Back to tools

RAM & Swap Size Calculator

Tell it your RAM and workload and get a swap size recommendation with the exact commands — plus a reverse check for a server you’ve already set up. The game-server case is handled honestly: it usually wants little or no swap.

Your server

RAM and workload

This is a starting-point heuristic, not a guarantee — real workloads vary. Watch actual memory pressure and adjust.

Recommendation

Swap size
2 GB
vm.swappiness
60 (default)
Heuristic, not gospel. Heuristic used: swap = RAM up to 2 GB, then roughly half of RAM, adjusted for web server (nginx/php/node, moderate traffic) and capped so it does not balloon on very large instances. Treat this as a starting point — watch actual swap usage (free -h, vmstat) and adjust rather than trusting it blindly.

Commands

Create and enable the swap file

Run as root or with sudo. Creates the file, locks it to owner-only, formats it, activates it, and makes it survive a reboot.

1 — allocate the file (fallocate, fast path)

fallocate -l 2G /swapfile

Some filesystems (notably ZFS, and older Btrfs setups) do not support fallocate for swap files. If that happens, fall back to dd — slower, but works everywhere:

1b — fallback (dd)

dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress

2 — lock permissions

chmod 600 /swapfile

A swap file readable by other users is a real exposure — anything the kernel ever pages out, including secrets that were briefly in RAM, can end up sitting in that file.

3 — format and activate

mkswap /swapfile
swapon /swapfile

4 — persist across reboots (/etc/fstab)

/swapfile none swap sw 0 0

Append that line to /etc/fstab — do not overwrite the file.

5 — set vm.swappiness (persistent)

sudo sysctl vm.swappiness=60
echo 'vm.swappiness=60' | sudo tee -a /etc/sysctl.conf

Background

What vm.swappiness actually does, and when swap helps

A single kernel knob from 0–100 that decides how eagerly it swaps out memory pages before they are strictly needed.

  • What the number means: vm.swappiness (0–100) tells the kernel how eagerly to move memory pages to swap before it strictly has to. Low values mean "only swap when RAM is nearly exhausted"; high values mean "swap out cold pages more readily, keep more RAM free for cache."
  • When swap genuinely helps: Bursty workloads (a web server’s traffic spikes) and as a backstop against the OOM killer — a process getting slowed down by swap is almost always recoverable, a process getting killed is not.
  • When it is masking a shortage: If swap is in constant, heavy use rather than occasional use during a spike, that is a workload that no longer fits in RAM, quietly running slower every day instead of failing loudly once.
  • How to tell the difference: Check swap usage over time (free -h, vmstat 1, or swapon --show). Occasional spikes that drain back down are healthy. Swap usage that stays high or keeps climbing means it is time to add RAM, not swap.

Running your own game server?

Wespner game servers with DDoS protection, NVMe drives and activation within minutes.

Browse hosting