memory.swap.max
memory.swap.max is the cgroup v2 control that limits charged swap usage separately from resident-memory usage.
In Linux 6.12, the default is max; numeric limits are expressed in bytes. memory.swap.high is a separate throttling threshold, not the normal hard limit. memory.zswap.max instead caps memory used by the compressed pool. These counters describe different resources. [1]
Writing a smaller swap limit does not synchronously empty existing swap entries. swap_max_write changes the limit and returns; later swap charging checks the swap counter. Setting it to zero prevents new swap charges, including those needed for new zswap-backed entries, but is not a command to cancel already-submitted device I/O. [2]
With zswap enabled, memory.zswap.writeback=0 still permits zswap stores but disallows backing-device fallback after a failed store and zswap writeback. An ancestor's disabled setting also applies. This differs from denying new swap charges altogether; recurring compression failures can make reclaim inefficient. [1]
The disabled-backend exception is decisive: mem_cgroup_zswap_writeback_enabled returns true when zswap is disabled, before examining the cgroup hierarchy. Therefore memory.zswap.writeback=0 alone does not prohibit ordinary swap-device writes in that configuration. [2]
Zero-filled pages are a separate case. After swap-slot allocation and preparation, swap_writepage can record a zero-filled folio in a bitmap and return before calling zswap_store or checking writeback permission. No device write on that path is not evidence that zswap compressed the page. This does not bypass the earlier swap charge. [3]
Relations
Limitations
- These version-scoped controls do not guarantee application latency, recovery durability or absence of all host I/O. [1, 3]
Citations
- Linux 6.12 cgroup v2: swap and zswap controls
- Linux v6.12 memcontrol.c: swap_max_write, swap charging and mem_cgroup_zswap_writeback_enabled
- Linux v6.12 page_io.c: swap_writepage zeromap, zswap and writeback ordering
Sources & caveats
- Source review of Linux v6.12; no memory-pressure experiment, kernel reconfiguration or swap activation was performed.