Linux Swap Tuning for Kubernetes: Real-World Results

Evgeny Anikiev October 23, 2025 k8s
Linux Swap Tuning for Kubernetes: Real-World Results

Swap is coming to Kubernetes - but it's not plug-and-play.

The upcoming Kubernetes v1.34 will graduate NodeSwap to stable, allowing Linux nodes to spill memory to disk when RAM runs dry. Sounds great, right? More memory headroom, fewer OOM kills. But here's the catch: if you misconfigure the Linux kernel parameters that govern swap behavior, you'll get the opposite.

A Google engineer (Ajay Sundar Karuppasamy) ran extensive stress tests on GKE and found that default kernel settings lead to node restarts and cascading failures under memory pressure. The culprit? Three overlooked sysctl parameters:

vm.swappiness (0–200): Controls whether the kernel prefers swapping anonymous memory or dropping file cache. High values = aggressive swapping + I/O thrashing. Low values = preserve cache but risk OOM faster.

vm.min_free_kbytes (in KB): Sets a safety buffer. Too low, and kswapd doesn't have time to reclaim pages before the system hits critical. The tests showed that jumping from 68MB to 500MB prevented OOM kills entirely.

vm.watermark_scale_factor (multiplier): Widens the gap between memory watermarks, giving the kernel more room to swap gradually. Increasing it from 10 to 2000 doubled the swapping window.

The real insight? Swap and Kubelet eviction need to work together. If watermarks are too tight, the OOM killer fires before Kubelet can gracefully evict pods. If they're too loose, you're just masking memory leaks and trading latency for stability.

Recommended starting point for production:

vm.swappiness=60 (workload-dependent)
vm.min_free_kbytes=500000
vm.watermark_scale_factor=2000

benchmark with your own workloads first. Swap performance is sensitive to disk type (SSD vs HDD), CPU load, and I/O patterns. One cluster's sweet spot is another's bottleneck.

Tags:

☁️ AWS Cloud That Saves and Scales

Helping SaaS teams cut costs, speed up releases, and scale securely with DevOps done right

Uncover Bottlenecks & Savings - Free 30-Min Review