Swap size calculator and swap file setup
Enter your RAM and disk to see how much swap makes sense, the right swappiness for your workload, and the commands that create a swap file and keep it after a reboot.
Why a server wants some swap
Without swap, a memory spike makes the kernel kill a process, often your database. A little swap absorbs the spike and moves idle memory out of the way, so the RAM serves what is busy.
What swappiness means
- It is how eager the kernel is to swap: 0 to 100, with 60 as the default.
- 10 suits servers: swap is used, but only when memory is really short.
- 1 suits databases, which slow down badly when their pages are swapped out.
The rule behind the number
Small machines get twice their RAM, up to 2 GB. Above that the size grows with the square root of the RAM: 2 GB for 4 GB, 3 GB for 8 GB, 4 GB for 16 GB. Servers do not hibernate, so there is no need to match the RAM.
More tools
- VPS ping test
- VPS cost calculator
- chmod calculator
- Cron generator
- Subnet calculator
- SSH key generator
- Bandwidth calculator
- What is my IP
- Cloud-init generator
- SSH hardening generator
- UFW firewall generator
- Fail2ban config generator
- WireGuard config generator
- Nginx reverse proxy generator
- Docker Compose generator
- Systemd service generator
- DNS lookup