Skip to content
IJK

Node Swap in Kubernetes: Why It Was Discouraged and What Changed

By IJK ·

The two reasons the Kubernetes post gives for why swap was discouraged and what it says removes each of them.

The first reason: one combined limit

Historically, swap was discouraged in Kubernetes for two reasons. [1]

Under cgroup v1, the controls treated memory and swap as a single combined limit rather than letting operators set an independent limit for disk swap. [2]

Without independent tracking, a process could page large amounts of anonymous memory out to disk, which made a container's real memory usage unpredictable and hard to isolate. [3]

Combined memory and swap limitunder cgroup v1; addressed by separate swap accou...Latency of slow spinning diskslargely eliminated by fast NVMe Local SSDs
What were the two reasons, and what does the post say addresses each?

The second reason: slow disks

The second reason was the latency penalty of paging to slow spinning disks, which fast NVMe Local SSDs largely eliminate. [4]

What the post says this makes practical

Together, these make it practical to increase pod density and buffer against memory spikes without sacrificing cluster stability. [5]

By enabling the Linux kernel to page out anonymous memory to disk, node swap acts as a shock absorber during traffic spikes or periods of heavy memory oversubscription. [6]

Sources

  1. The Kubernetes project source says: Historically, swap was discouraged in Kubernetes for two reasons. Scaling Kubernetes Workloads with Node Swap
  2. The Kubernetes project source says: Under cgroup v1, the controls treated memory and swap as a single combined limit rather than letting operators set an independent limit for disk swap. Scaling Kubernetes Workloads with Node Swap
  3. The Kubernetes project source says: Without independent tracking, a process could page large amounts of anonymous memory out to disk, which made a container's real memory usage unpredictable and hard to isolate. Scaling Kubernetes Workloads with Node Swap
  4. The Kubernetes project source says: The second reason was the latency penalty of paging to slow spinning disks, which fast NVMe Local SSDs largely eliminate. Scaling Kubernetes Workloads with Node Swap
  5. The Kubernetes project source says: Together, these make it practical to increase pod density and buffer against memory spikes without sacrificing cluster stability. Scaling Kubernetes Workloads with Node Swap
  6. The Kubernetes project source says: By enabling the Linux kernel to page out anonymous memory to disk, node swap acts as a shock absorber during traffic spikes or periods of heavy memory oversubscription. Scaling Kubernetes Workloads with Node Swap

Editorial (AI-assisted; automatically checked, not human-reviewed). Each statement is linked to its source; check the source before relying on a detail.

  • kubernetes
  • swap
  • memory
  • operations