In defence of swap: common misconceptions
7 hours ago
- #Linux
- #Memory Management
- #Performance Tuning
- Swap is essential for efficient memory management, not just emergency memory.
- Disabling swap shifts disk I/O thrashing from anonymous to file pages, potentially worsening performance.
- Kernels before 4.0 had aggressive swap behavior, but newer versions handle swap more effectively.
- On SSDs, swapping anonymous pages and reclaiming file pages have similar performance; on HDDs, swap reads are slower.
- Swap allows for equality in memory reclamation, improving system performance under normal and peak loads.
- The OOM killer is a last resort; swap can delay its invocation but doesn't prevent system instability.
- cgroup v2's memory.low provides better control over swap behavior for individual applications.
- vm.swappiness biases memory reclamation between anonymous and file pages; default is 60, but tuning is workload-dependent.
- Recent kernels (4.20+) include memory pressure metrics (CONFIG_PSI=y) for better swap tuning.