Skip to main content
A free VPS gives you a modest amount of RAM, and it does not take much to hit the ceiling. When memory runs out, the Linux kernel starts killing processes, usually the one you cared about most. A swap file gives the kernel breathing room by letting it move inactive memory to disk.
Swap uses disk space and is much slower than RAM. Use it as a safety net for occasional spikes, not as a substitute for enough memory. Check your resource limits before adding a large swap file.

Add a swap file

1

Check current swap

2

Create a 1 GB swap file

3

Make it persistent across reboots

4

Verify

Tune swappiness

Swappiness controls how eagerly the kernel moves memory to swap. On a server, a lower value keeps active data in RAM longer.

Diagnose slow performance

Check memory and CPU

Find the biggest memory hogs

Find the biggest CPU hogs

Check disk usage

Check disk I/O

Remove a swap file