Why Kubernetes Hates Linux Swap?

Bhargav Bhikkaji
Tailwinds-MajorDomo
2 min readApr 27, 2020
Kubernetes No Love For Linux Swap.

A typical computer system has two types of memory. A volatile memory called RAM (Random Access Memory) that is actively used by programs while the second type is non-volatile memory called HD (Hard Disk) that is typically used for long term storage.

Kernel’s Memory Managed Unit(MMU) carves out a part of memory from the HD and loans it to RAM for unusual spikes. For example, if a system already has 4GB of RAM, the MMU can carve out additional 2GB from the HD and fake it as 6GB in total. This 6GB memory is also referred virtual memory. MMU has inbuilt heuristics to determine what contents be part of actual RAM, what should be part swap space and refresh it on continuous basis. It should be observed that accessing RAM is faster while the HD is slow. So, accessing contents on swap space has undeterminstic performance.

Kubernetes has three types of QoS that Pod could be part of. They are

  • Guaranteed: When a pod has Guaranteed configured, request & limits will be the same and system should provide guaranteed resources to the pod.
  • Burstable: When a pod has Burstable configured, requests must be guaranteed while limits are based on availability.
  • BestEffort: When a pod has no request and limits configured, the pod’s QoS is considered as BestEffort. The resources are allocated on subject to availability.

The scheduler in Kubernetes called as kube-scheduler decides placement of pods on to worker nodes based on resources availability and QoS configuration for simple cases. As of today, the scheduler does not dig deep into swap configuration and usage to provide smarts for swap support. Enabling swap would have an effect on performance of the applications. Keeping all these in mind, the kubernetes community decided to defer this feature until there are solid gains realized due to this feature. Guess, a good decision made by the community.

Here is the link to this discussion on the community.

--

--