Ramblings of an aging IT geek
← Ramblings of an aging IT geek
linux

yes, i still give my servers swap

Why, after years of arguing about it, I keep a small amount of swap on every homelab box and tune swappiness low rather than running with none at all.

A terminal showing free -h and a low swappiness value

The swap debate is one of those arguments that never quite dies, like tabs versus spaces but with more confidence on both sides. "You have 64GB of RAM, why would you ever swap?" The answer I have settled on for my own machines: because swap is not really about running out of memory, it is about giving the kernel somewhere to put pages it does not want.

A long-lived process accumulates pages that are touched once and then never again. With zero swap, those pages sit in RAM forever, taking space that the page cache could use for things you actually read often. Give the kernel a few gigabytes of swap and a low vm.swappiness, and it will quietly evict the dead weight without ever touching anything hot.

vm.swappiness = 10

So my rule is small swap, low swappiness, everywhere. Enough to let the kernel breathe, not so much that a runaway process limps along thrashing for an hour before the OOM killer does the merciful thing. If a box is genuinely under memory pressure I want it to fail loudly and quickly, not crawl.

The one place I make an exception is anything with a strict latency budget, where a swapped-in page at the wrong moment is worse than an honest OOM. Those run swapoff. Everything else gets its little safety valve, and I stop thinking about it.