Swap
A swap space is an area of a disk under the control of the Linux kernel memory management subsystem. The kernel uses swap space to supplement the system RAM by holding inactive pages of memory. The combined system RAM plus swap space is called virtual memory.
RAM | Swap Space | Swap Space if Allowing for Hibernation |
---|---|---|
2 GiB or less | Twice the RAM | Three times the RAM |
Between 2 GiB and 8 GiB | Same as RAM | Twice the RAM |
Between 8 GiB and 64 GiB | At least 4 GiB | 1.5 times the RAM |
More than 64 GiB | At least 4 GiB | Hibernation is not recommended |
To create a swap space, you need to perform the following:
- Create a partition with a file system type of
linux-swap
. - Place a swap signature on the device.
Use parted
or fdisk
to create a partition on a device with the file system type linux-swap
.
The udevadm settle
command waits for the system to detect the new partition and to create the associated device file.
Format the device with mkswap /dev/sdb1
.
The swapon
command is used to activate a formatted swap space but to make it persistent, add it to /etc/fstab
.
Use the pri
option to set the priority in /etc/fstab
. The kernel uses the swap space with the highest priority first. The default priority is -2
.
Summary
Swap spaces are initialized using the mkswap
command.
Command References:
mkswap
, swapon
, swapoff
, mount
, parted
and fdisk
.