Frequently Asked Question

What is swappiness and should I change it?

vm.swappiness is a kernel knob (0–200 since 5.8, 0–100 before that) that biases the page reclaimer between two choices: evict file-backed pages (drop bits of the page cache, which can be re-read from disk later) or evict anonymous pages (swap process memory out to the swap device). A high swappiness leans toward swapping anonymous memory; a low one leans toward shrinking the cache. The default is 60, which means under memory pressure the kernel is fairly willing to swap.

Despite the folklore, swappiness has nothing to do with how full RAM is when swapping starts, it is a balance, not a threshold. On a server with plenty of RAM and SSD-backed swap, the defaults are fine. On a desktop where any swap activity feels painfully slow, vm.swappiness=10 is a common tweak. On a database server you usually want to keep the hot pages of the buffer pool from being swapped out, which argues for a low value. Set it in /etc/sysctl.d/99-swap.conf with vm.swappiness=10 and apply with sudo sysctl --system.

Further reading and video