Skip to content

How to set up swap space on Linux

Linux

FAQ · Linux · Help & Support

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 --show
free -h

2. Create a swap file (e.g. 2 GB):
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo 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

Still have questions?

Our support team is happy to help - via ticket, email, or phone.