21. Feb 2026
1 min
Swap space extends your server's available memory by using disk space as virtual RAM. This is especially useful on servers with little RAM.
1. Check the current swap:sudo swapon --showfree -h
2. Create a swap file (e.g. 2 GB):sudo fallocate -l 2G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfile
3. Make it permanent:
Add the following line to /etc/fstab:/swapfile none swap sw 0 0
4. Adjust swappiness (optional):
The default value is 60. For servers, we recommend a lower value:sudo sysctl vm.swappiness=10
To make it permanent, add to /etc/sysctl.conf:vm.swappiness=10