📢 LordCloud support has moved to Ballastra — Join now →
Docs

Adding swap

Create a swap file to protect small VPS plans from out-of-memory crashes.

1 min read
On this page

Swap is disk space used as overflow memory. It's slower than RAM, but it can stop the out-of-memory killer from terminating your apps during short spikes.

Create a 2 GB swap file#

bash
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Make it permanent:

bash
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Check it#

bash
free -h
swapon --show

Tune swappiness#

Lower values make Linux prefer RAM:

bash
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf

Remove swap#

bash
sudo swapoff /swapfile
sudo rm /swapfile
# then delete the /swapfile line from /etc/fstab
Have a question? Chat with us👋