Modernizing Linux swapping: introducing the swap table
Interactive responsiveness & “swap storms”
- Several users describe systems becoming unusable under memory pressure: UI freezes, SSH impossible, terminals unresponsive, often requiring a hard power-off.
- Disabling swap does not fully avoid this: the kernel still reclaims file‑backed executable and library pages, causing repeated page faults and heavy I/O.
- Some report that Magic SysRq (including the OOM‑killer shortcut) often fails to break out of these situations in practice.
Protecting UI and critical processes
- Desired feature: mark certain processes/pages as “required for interactivity” so desktop, window manager, terminals, SSH, etc. never get paged out.
- Existing mechanisms:
mlock/mlockall, cgroupmemory.min, OOMScoreAdjust, and cgroups in general. SSH is cited as already protected via OOM score. - Problems: these require explicit app or admin configuration; no simple, distro‑standard policy that “system UI stays responsive, apps die first”.
- Concern: if apps can self‑declare interactivity (e.g., Electron), they might lock huge amounts of memory.
MGLRU and current reclaim behavior
- Some note MGLRU (multigen LRU), enabled in 6.1+, dramatically improves swap behavior (e.g., on Chromebooks).
- Others report regressions: aggressive compaction/defragmentation causing frequent multi‑second freezes instead of dropping caches or swapping.
Swap vs no swap: stability and sizing
- Strong disagreement on whether swap is “obsolete”:
- Pro‑swap: essential for unpredictable workloads, VM/container hosts, desktops with occasional spikes; small to moderate swap improves stability and allows more disk cache.
- Anti‑swap: fear of thrashing and total unresponsiveness; preference for OOM‑killing over prolonged stalls; some run large‑RAM systems with zero swap successfully.
- Old rules like “swap = 2× RAM” are widely considered outdated. Suggested heuristics range from a few hundred MB to several GB, “enough for inactive anonymous pages but not enough to thrash”.
Compression (zram vs zswap)
- Interest in OS‑level memory compression similar to macOS/Windows.
- Clarification: Linux already has zswap (compressed RAM cache in front of swap); zram remains useful and is still default on some distros.
- zswap can be used with or without backing disk, and can effectively delay or avoid disk swapping.
Cloud and server considerations
- Ubuntu cloud images are recommended to have swap even with ample RAM, to avoid hard OOM failures.
- Some argue Linux’s behavior under memory pressure is worse than macOS/Windows, making careful swap, cgroup limits, and OOM tuning more important.