Scaling Kubernetes Workloads with Node Swap
Kubernetes node swap, GA since v1.34 and backed by fast NVMe Local SSDs, lets nodes page out dormant anonymous memory and pack far more pods. Benchmarks show a Linux kernel build running at half the memory limit (300 MB vs 600 MB) with no slowdown, gVisor headless Chrome doubling from 80 to 160 pods, Kata rising from 40 to 50, and gVisor Python sandboxes tripling from 80 to 240. At peak density, latency rises mainly from CPU contention rather than swap I/O, but squeezing limits into the active working set (200 MB for the build) cost over 40% runtime, so swap is burst insurance, not a RAM replacement. To use it, enable LimitedSwap in the kubelet config on cgroup v2 and run workloads as Burstable QoS.
Related posts
- Incident Report: May 4th, 2024
Railway mediumAdeptA single self-service customer workload deployed multiple memory-hungry replicas into Railway's smallest region, Asia-Southeast, and exhausted its memory. The kernel OOM reaper then killed the Dataplane instance manager on every compute node, and a later redeploy packed all replicas onto one node, locking up the hypervisor. The root cause was overcommitment: the sum of per-container limits exceeded physical RAM, so system memory pressure hit 99% without any container breaching its own limit and triggering eviction. Fixes include reprioritizing the OOM killer to evict user workloads before system daemons, evicting or migrating workloads on node-level memory pressure, scheduling on historical usage, adding capacity, and committing to status updates at least every 30 minutes.
- Transparent memory offloading: more memory at a fraction of the cost and power
Meta Engineering hardMasterTMO offloads cold memory to compressed RAM (zswap) or NVMe SSD swap. It uses the kernel's Pressure Stall Information (PSI), which measures time lost to CPU, memory and I/O shortage, and a userspace agent, Senpai, that applies mild proactive reclaim through a new stateless cgroup2 memory.reclaim knob. A reworked Linux swap algorithm engages swap in proportion to file-cache refaults, so cold anonymous pages get evicted at low pressure instead of only near OOM. In production across millions of servers, TMO saves 20–32% of memory per server, and SSD backends suit poorly compressible data like quantized ads models.
- Scaling to 1 million concurrent sandboxes in seconds
Modal mediumAdept
Modal rebuilt its sandbox control plane to run 1 million concurrent sandboxes, creating all of them in under a minute, by removing central coordination and durable stores from the creation path. A horizontally scaled fleet of scheduling servers picks workers using in-memory state that workers publish to a Redis stream, then calls the worker directly over RPC; workers act as their own source of truth and reject requests when full. Kubernetes and Modal's old Postgres-backed design hit limits from O(pods) and O(nodes) etcd and Postgres writes and serialized scheduling. The new path takes two network hops, scheduling takes tens of milliseconds, and median start time is under 0.5s, with tail latency driven by kernel rtnl lock contention during container networking setup.
- 1 Year of Autoscaling Postgres: How it’s going, and what’s next
Neon hardMaster
Neon autoscales Postgres by running each instance as a VM in Kubernetes (NeonVM), with a per-node autoscaler-agent, a modified scheduler, and an in-VM vm-monitor that resizes the Local File Cache. Over the past year the team replaced cgroup memory.high event triggers with 100ms polling of memory usage for stability, and traced a 0-TPS stall to a kernel bug in ACPI memory hotplug that was fixed by upgrading the kernel. Next steps include sizing compute with a HyperLogLog estimate of working set from LFC page accesses, since a slightly larger cache can yield 10x gains. They are also adding swap, set up via mkswap/swapon on pre-created VMs, and disabling overcommit so up-front allocations like pgvector 0.6's parallel HNSW builds don't OOM.
- The Shift to cgroup v2 in Kubernetes: What You Need to Know
Kubernetes Blog mediumAdeptKubernetes has deprecated cgroup v1: from v1.35 the kubelet refuses to start on cgroup v1 nodes by default (`failCgroupV1: true`), kubeadm preflight errors on it, and the fallback is slated for removal in v1.38. cgroup v2 enables Memory QoS with `memory.high` throttling and tiered `memory.min`/`memory.low` reservations, container-wide OOM kills via `memory.oom.group`, safe rootless delegation, eBPF-based device control, PSI metrics, and accurate Pod-level in-place resizing. Migration requires kernel 5.8+ (5.9+ for Memory QoS), a cgroup v2-capable runtime, and matching cgroup drivers, ideally systemd with CRI auto-detection. A step-by-step procedure traces Pod resource limits from the API through CRI, OCI spec, and systemd scope down to the actual cgroup files.