Swap is a type of virtual memory that allows the system to use a portion of the hard disk as if it were RAM. Speed would depend on the disk, but in any case, it'll be way slower than RAM. Swap can be used as an additional buffer of RAM for servers. It’s completely optional.
Most of the time swap will be disabled by default. Type docker info
to confirm if that's the case by looking for the output of WARNING: No swap limit support
at the bottom. If you don't see such warnings, then swap is enabled and there's nothing else required for you to do.
To enable swap, open etc/default/grub
as root user and find a line starting with GRUB_CMDLINE_LINUX_DEFAULT
. Add swapaccount=1
somewhere inside the double quotes.
It'll most likely contain other parameters inside of it, such as GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
. Do NOT delete any existing parameters if there are any and only append swapaccount=1
next to them. For example:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash swapaccount=1"
<aside>
📢 Some Linux distributions do not contain GRUB_CMDLINE_LINUX_DEFAULT
and instead would use GRUB_CMDLINE_LINUX
</aside>
Finally, run the command update-grub
and restart the server with reboot
to apply the new changes.
To disable swap, open etc/default/grub
as root user and find a line starting with GRUB_CMDLINE_LINUX_DEFAULT
.
Locate swapaccount=1
and remove it from inside the double quotes. Do not remove the double quotes “ “ or any other parameters.
After that, run the command update-grub
and restart the server with reboot
to apply the new changes.