freenode
Kernel & Low-Level

Virtual swap layer proposed to decouple Linux PTEs from backing

Nhat Pham's v5 series lets zswap and zero pages claim swap entries without pre-allocating physical slots, and retunes memcg swap charging to match.

Nhat Pham has posted a fifth revision of an eleven-part series that adds a virtual swap layer to the Linux kernel, so page-table swap entries no longer have to point straight at a physical slot or a zswap object.

Today a swapped-out anonymous page still consumes a slot on a swap device even when the real payload lives only in zswap or is known to be zero. That forces operators to provision disk (or accept tight overcommit limits) for memory that never touches storage. Virtual swap inserts an indirection: a large, always-on virtual device (capped just under 8 TiB for 4 KiB pages) hands out entries that can later be backed by zswap, a zero page, or, when needed, an on-demand physical slot.

The feature is gated by a vswap= command-line parameter rather than a runtime sysctl. When enabled it also widens the OVERCOMMIT_GUESS ceiling by another two times RAM, recognizing that compression-backed swap is still memory. Memcg accounting changes with it. memory.swap.current will count only pages that actually occupy disk; a cgroup allowed to use zswap can reclaim anonymous memory even with memory.swap.max set to zero. Charges that used to fail at allocation can now fail later, at writeback, if the cgroup hits its limit.

Physical writeback, THP swap-in for contiguous physical runs, reclaim of cache-only backing slots, and deferred memcg tables for clusters that only serve virtual entries are all included. Zswap writeback of virtual entries allocates the physical slot at shrink time instead of pinning one up front. An RFC final patch replaces the xarray cluster store with a sparse vmalloc array originally designed by Baoquan He, simplifying lookup and lifetime rules.

Johannes Weiner shaped several of the policy and memcg refactors; Kairui Song contributed earlier design input. The series targets mm-unstable and remains optional: with vswap off, ordinary swap behavior is unchanged.