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

how much swap, and why i stopped arguing about it

After years of fiddling, here is the swap policy I actually run on my homelab boxes and the reasoning behind it.

A terminal showing free and swap output

Every few months someone on a forum reignites the swap argument, and every few months I remember that I have already settled it for my own machines. So here is the policy, written down, so I stop relitigating it with myself.

For anything with plenty of RAM, I give it a small swap file anyway. Not because I expect to page heavily, but because the kernel reclaims cold anonymous pages into swap and frees real memory for the page cache. A box with 32GB and zero swap will happily sit on gigabytes of pages that nothing has touched since boot. 2GB of swap and vm.swappiness=10 lets it shuffle those out without ever feeling slow.

The exception is anything latency-sensitive that I would rather have OOM-kill cleanly than thrash. My one Postgres box runs with swap disabled and a sensible oom_score_adj, because a database that has started swapping is a database that is already having a bad day, and I would rather know.

zram on the small ARM nodes, a modest swap file everywhere else, swappiness turned down, and an alert if swap usage ever climbs past a few hundred megabytes. That last bit is the real win: swap is a shock absorber, not a place to live. The moment it becomes a place to live, the alert tells me, and I go and fix the actual problem.