sysctl.si › Parameters › vm.swappiness

vm.swappiness

How eagerly the kernel swaps memory pages out. Lower keeps data in RAM.

Default
60
Typical value
1–10 on servers, 10–30 on desktops

When to change it

Lower it on database and cache servers so hot data stays in RAM. A value of 0 does not disable swap, and very low values make the kernel reclaim page cache more aggressively.

How it works

Linux can free memory in two ways: drop file-backed page cache, or write rarely used application memory out to swap. vm.swappiness sets how much the kernel prefers the second option. Higher values make swapping more likely, and lower values make the kernel reclaim cache first.

The range is 0 to 100 on older kernels and up to 200 on kernel 5.8 and newer. A value of 0 does not turn swap off: the kernel can still swap when memory is nearly exhausted.

Signs you need to change it

Recommended values by workload

Database server
1 to 10
Redis or Memcached
1
General server
10 to 30
Desktop or laptop
10 to 60
Host with zram or zswap
Higher values are common; test them

Common mistakes

Check the current value

sysctl vm.swappiness

Change it until the next reboot

sudo sysctl -w vm.swappiness=1

Make it permanent

echo "vm.swappiness = 1" | sudo tee /etc/sysctl.d/99-custom.conf
sudo sysctl --system

Related parameters

vm.dirty_ratio · vm.dirty_background_ratio · vm.overcommit_memory · vm.max_map_count · vm.min_free_kbytes · vm.nr_hugepages

Generate a full sysctl config for your server

Values are starting points. Test on a staging machine and measure before and after.