User Tools

Site Tools


swap

If you want to send us your comments, please do so. Thanks
More on comments


Swap

Warning: You should not use swapon on a swapfile with holes. If there is a swapfile with holes can be found in /var/log/systemlog. Look for:

swapon: swapfile has holes.

Show swap status

cat /proc/swaps
swapon -s

Show memory usage

Commands:

cat /proc/meminfo 
free
top
htop

System speed up

You can make your system a bit faster by clearing the swapspace
Do, it can take a bit time before the swap is cleared, as root

swapoff /dev/sdax
swapon /dev/sdax

x is the number of the partition / drive
or set swap usage to 0 kilobytes by doing as root

swapoff --all && swapon --all

See also swapoff --help for details about the --all option (differs from the man page)
See also man swappon for details about the --all option

Swap partition and a swap file

When you, temporarily, need more swap space you can add an extra swapfile (to the already existing swap partition)
The util-linux package has to be installed. It should be installed when Debian is installed. This package contains, among others, fallocate, mkswap, swapon and swapoff
As root do

  • fallocate -l 5G /mnt/5GExtraSWAP
  • mkswap /mnt/5GExtraSWAP . This results in something like
    • mkswap: /mnt/5GExtraSWAP: insecure permissions 0644, 0600 suggested.
    • Setting up swapspace version 1, size = 5 GiB (524283904000 bytes)
    • no label, UUID=00000000-0000-0000-0000-000000000000
  • chmod 600 /mnt/5GExtraSWAP
  • swapon /mnt/5GExtraSWAP . This turns the swap on
  • When you want to make it permanent then add to /etc/fstab : /mnt/5GExtraSWAP none swap sw defaults,pri=100 0 0 . pri stands for priority and can range from 0 to 32676. Give each swap partion or file the appropriate priority

swapon swapoff

swap off

swapoff -av
swapoff /mnt/5GExtraSWAP
swapoff /dev/sda4

swapon -av

swapon: /dev/sda4: found signature [pagesize=4096, signature=swap]
swapon: /dev/sda4: pagesize=4096, swapsize=2097152000, devsize=2097152000
swapon /dev/sda4

/mnt/5GExtraSWAP is not turned on. You need to do swapon -av /mnt/5GExtraSWAP. Then you get something like

swapon: /dev/sda4: found signature [pagesize=4096, signature=swap]
swapon: /dev/sda4: pagesize=4096, swapsize=2097152000, devsize=2097152000
swapon /dev/sda4
swapon: /mnt/5GExtraSWAP: found signature [pagesize=4096, signature=swap]
swapon: /mnt/5GExtraSWAP: pagesize=4096, swapsize=5474836480, devsize=5474836480
swapon /mnt/5GExtraSWAP

Useful commands

swapon -sShow the swap status
partprobeForce the kernel to re-read the partition table. No reboot needed
truncateshrink or extend the size of a file to the specified size

Errors

From

sgdisk --info=3 /dev/sda

Partition GUID code: 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F (Linux swap)
or the
Partition unique GUID: FD3B975F-8477-4C5A-AF57-E1D63FAB7845
tried in fstab

PARTUUID=FD3B975F-8477-4C5A-AF57-E1D63FAB7845  none    swap  sw      0 0                       
PARTUUID=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F  none    swap  sw      0 0

Running as root

swapon -a

results in

swapon: cannot find the device for PARTUUID=0657FD6D-A4DD-43A4-74E5-0933C84B4F4F

should work according to the fstab man page. It does not.

In fstab: PARTLABEL=swap

PARTLABEL=swap  none  swap  sw  0 0

Running as root

swapon -a

results in

swapon: /dev/sda3: read swap header failed

altough this should work according to the man page of fstab. It does not.

Running

swapoff

results in

swapoff failed: Cannot allocate memory

Solution: An application is still using swap space. Stop the application and try again

Swap intensity

On systems with a SSD, SDcard, CFcard or similar enough memory it is needed to avoid swapping
The swappiness can then better be set low or off
Do vi /etc/sysctl.conf and add or change

vm.swappiness = x

where x is a value in the range 0 or 100
0 means the swap is off
The higher x the more the computer might swap
To activate execute

sysctl -p (Load the settings from /etc/sysctl.conf)

To check the swap intensity

 sysctl vm.swappiness

Swap
Swappiness on Wikipedia
Swappiness
Reload sysctl.conf on linux using sysctl


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
swap.txt · Last modified: 13-02-2024 23:21 by wim