Linux

Creating swap memory on Linux (and when it does not help)

A cushion so the system does not kill processes outright when RAM fills up. How to create it in two minutes and why it is no substitute for more RAM.

1 min readUpdated on 6 October 2026

Swap is a part of the disk the system uses as reserve memory when RAM fills up. Without it, if you run out of memory, Linux kills the biggest process, which is usually exactly your game server or your database.

Do you already have it?

swapon --show
free -h

If swapon --show prints nothing, you have no swap.

Create a 2 GB swap file

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab

The last line keeps it active after a reboot. 1-2 GB is usually enough; it takes that much disk space.

Only use it when really needed

By default Linux starts moving things to swap fairly early. On a server it is better to wait until it is needed:

sysctl vm.swappiness=10
echo 'vm.swappiness=10' > /etc/sysctl.d/99-swappiness.conf

What swap does not do

Disk is far slower than RAM. If your game server lives in swap, it will stutter anyway. Use it as a safety net for occasional peaks; if free -h shows it in constant use, what you need is more RAM: upgrade the plan, with no migration needed.

Related articles

Back to the help centre

Can’t find what you need?

Open a ticket from your panel and we will answer in under 5 minutes.