Swap space is a critical but often overlooked part of VPS performance. When your VPS runs out of physical RAM, the kernel moves idle memory pages to swap preventing out-of-memory crashes. Proper swap configuration keeps your server stable without sacrificing performance.
You can compare VPS plans with enough RAM for your workload on our VPS comparison page.
How Much Swap Do You Need?
| RAM Size | Recommended Swap | With Hibernation |
|---|---|---|
| 512 MB | 1 GB | 1 GB |
| 1 GB | 1 GB | 2 GB |
| 2 GB | 1 GB | 3 GB |
| 4 GB | 2 GB | 5 GB |
| 8 GB+ | 2 GB | RAM x 1.5 |
Creating Swap on a Linux VPS
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabOptimization
Set swappiness to 10 so the kernel only swaps when RAM is over 90% full, ideal for VPS environments: sudo sysctl vm.swappiness=10. Check our VPS hosting comparison for plans with adequate RAM.




Leave a Reply
You must be logged in to post a comment.