freenode
Kernel & Low-Level

Linux gains virtual swap so zswap works without a swapfile

Nhat Pham’s vswap layer decouples swap slots from disk, with on-demand physical fallback and cgroup accounting that only charges real backing.

Linux memory management is poised to let zswap compress anonymous pages without a physical swapfile, removing a constraint that has forced operators either to provision disk swap they did not want or to forgo compressed reclaim entirely.

Nhat Pham posted the sixth round of the virtual swap (vswap) work to the Linux kernel mailing list. The design creates a kernel-lifetime virtual swap device, capped just under 8 TiB on 64-bit systems, that never appears in swapon or swapoff. A boot parameter (vswap=) turns it on; when enabled, swap-out can park pages in zswap or as zero-filled entries without consuming a real swap slot. If zswap declines a page, typically because its pool is full, the path can allocate a physical slot on demand when conventional swap exists, and later write compressed vswap entries back to disk the same way.

That split forced reclaim and overcommit fixes. Free physical slots no longer decide whether anonymous memory is reclaimable: a cgroup can still push anon through zswap within its swap headroom even when no disk slot is free. The OVERCOMMIT_GUESS heuristic, which once collapsed to RAM alone on swapfile-less hosts, adds a 3x RAM ceiling when vswap and zswap are both active, on top of any real swap. Cgroup swap charging moves with the model: memory.swap tracks physical backing only, so a group with memory.swap.max at zero can still reclaim via zswap, and charge failure can surface at writeback rather than at slot allocation. Idle physical slots left behind by cache-only vswap entries are reclaimed once swap is more than half used.

Usage shows up in /proc/vmstat and cgroup memory.stat; debugfs reports allocated virtual slots and allocation rejects. Kairui Song and Johannes Weiner steered major design choices; Baoquan He contributed the sparse cluster array that replaced an earlier xarray layout. For fleets that want compressed reclaim without swap disks, capacity planning, or the extra failure domain, vswap makes that configuration a first-class kernel path rather than a workaround.