Tuning Linux Swap for Kubernet... Note

Tuning Linux Swap for Kubernetes: A Deep Dive

The Kubernetes NodeSwap feature, set to become stable, allows Linux nodes to utilize swap space for additional virtual memory. This aims to improve resource utilization and reduce out-of-memory (OOM) kills when physical RAM is exhausted. However, its effectiveness hinges on tuning specific Linux kernel parameters like vm.swappiness, vm.min_free_kbytes, and vm.watermark_scale_factor. The vm.swappiness parameter controls the kernel's preference between swapping anonymous memory and reclaiming file-backed memory. vm.min_free_kbytes acts as a safety buffer, influencing when aggressive page reclamation begins. vm.watermark_scale_factor adjusts the gap between memory free watermarks, affecting the swapping window. Tests revealed that default kernel parameters can lead to OOM kills and node restarts under memory pressure. Increasing vm.min_free_kbytes and vm.watermark_scale_factor proved crucial in preventing premature evictions and OOM kills by providing the kernel more time to swap. A higher swappiness can lead to significant I/O wait, while lower swappiness prioritizes dropping file cache. Properly tuning these parameters, alongside Kubelet's eviction thresholds, creates a balanced memory pressure management strategy. Risks include performance degradation due to slow swap access and masking memory leaks.
CdXz5zHNQW_LEZYliBqbk.png