Guide
Add a swap file to a small VPS
Last updated: 15 November 2026
Swap is disk space the system uses when RAM runs out. On a small VPS it can stop the kernel from killing your app during a short memory peak. It is a safety net, not a replacement for RAM: if the server swaps all the time, it is too small. If you are logged in as root, leave out sudo.
Fast VPS from $7.99 a month
- Sign up with an email address, a password and any nickname: no ID, no phone number.
- Pay with Monero, Bitcoin, Litecoin, USDT, USDC, SOL or TRX, or by card through MoonPay. Monero is the most private way to pay; USDT or USDC on Solana confirm in seconds, and we add no transfer fee on them.
- Orders are processed automatically: most are ready within minutes, occasionally it takes up to a few hours.
- New VPS orders have a 24-hour guarantee (see the terms for what is covered).
See Fast VPS plansHow ordering works
Check first
free -h
swapon --show
If swapon --show prints nothing, there is no swap yet. If it lists a swap already, stop here.
Create a 2 GB swap file
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/fstab
If fallocate fails on your file system, create the file with sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 instead, then continue from chmod. Check with free -h.
Tune it
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swap.conf
sudo sysctl --system
A low swappiness makes the system prefer RAM and use swap only under pressure.
When swap is not the answer
- If
free -h shows swap in constant use and the server is slow, add RAM: see the Fast VPS plans (upgrades are possible; downgrades are not).
- Find what uses the memory with
ps aux --sort=-%mem | head.
- Databases and Java apps need their memory limits set properly (for example MariaDB buffers, Java
-Xmx).
Questions and answers
What is swap?
Disk space the system uses as extra memory when RAM runs out.
How big should the swap file be?
On a small VPS 1 to 2 GB is a common start; it is a safety net, not extra RAM.
How do I make swap permanent?
Add a line for the swap file to /etc/fstab.
When should I add RAM instead?
When the server uses swap constantly and is slow.
Ready to try it? Fast VPS from $7.99 a month
- Pick a plan: Fast 1-2, $7.99 a month or all Fast VPS plans.
- Sign up with an email address, a password and any nickname: no ID, no phone number.
- Pay with Monero, Bitcoin, Litecoin, USDT, USDC, SOL or TRX, or by card through MoonPay. Monero is the most private way to pay; USDT or USDC on Solana confirm in seconds, and we add no transfer fee on them.
- Orders are processed automatically: most are ready within minutes, occasionally it takes up to a few hours.
- New VPS orders have a 24-hour guarantee (see the terms for what is covered).
- Before you pay you can ping our test IPs and read the live status page.
- Support is available 24/7 via email and our client ticket portal.
See Fast VPS plansHow ordering works