D Darkless Help
Open the portal

Help Running your server Care and troubleshooting

Add a swap file

Give the server a cushion of disk-backed memory, so a short spike slows it down instead of stopping a program.

2 min Updated 7 Nov 2026 Ubuntu, Debian, AlmaLinux

Swap is disk space the server uses when memory is full. It's far slower than memory, so it's a cushion, not more memory: a short spike slows the server instead of the kernel stopping your database.

Check what you have#

swapon --show
free -h

If swapon prints nothing, and the Swap: line in free says 0B, there's no swap.

Make a swap file#

1 or 2 GB is plenty for most servers. Check there's room with df -h /, then make a 2 GB file:

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

Only root may read it, as it can hold anything that was in memory:

sudo chmod 600 /swapfile

Format it as swap, and turn it on:

sudo mkswap /swapfile && sudo swapon /swapfile

Turn it on at every boot too:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Check it worked:

swapon --show

Use it only when needed#

Swappiness is how keen the server is to use swap. The default, 60, starts early; 10 keeps programs in memory until it really runs short:

echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf
sudo sysctl --system

Is swap being used a lot?#

A little swap used is normal. Watch it for a few seconds:

vmstat 2 5

si and so are memory moving in from and out to swap. Above zero all the time means the server is short of memory, which swap can't fix: find what's using it or upgrade your plan.

Remove it#

sudo swapoff /swapfile && sudo rm /swapfile

Then delete the /swapfile line from /etc/fstab (sudo nano /etc/fstab).

Still stuck? Open a ticket and say which guide you followed.