Skip to content

Knowledge Base

Creating and managing a swap file

Swap can provide a small safety margin during short memory spikes, but it is slower than RAM and does not fix a sustained undersized workload.

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon --show

To keep it after reboot, add exactly one line to /etc/fstab:

/swapfile none swap sw 0 0

Confirm free disk space first. If fallocate is unsuitable for the filesystem, create the file with dd. To remove swap, run swapoff /swapfile only when sufficient memory is available, remove its fstab entry, then delete the file.

Please rate this article to help us improve our Knowledge Base.

0 0