Re: [PATCH v7 00/20] mm: mandatory virtual swap

From: Nhat Pham

Date: Thu Dec 03 2026 - 18:00:42 EST


On Thu, Dec 3, 2026 at 3:14 PM Yosry Ahmed <yosry@xxxxxxxxxx> wrote:
>
> On Thu, Dec 3, 2026 at 2:00 PM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
> >
> > Changelog
> >
> > * v6 [v6] -> v7
> > * Append five patches that make vswap mandatory after the optional
> > implementation. Keep all swap counts, cache entries and ordinary
> > cgroup ownership at the virtual slot.
> > * The mandatory conversion removes 437 lines net across 19 files.
> > Calls to swap_is_vswap() or is_vswap_entry() fall from 61 to 25,
> > excluding definitions and assertions. Physical cluster metadata
> > shrinks by 16 bytes on x86-64 with CONFIG_MEMCG.
> > * Rebase onto mm-unstable. Keep the cluster XArray in this series;
> > the v7-compatible VM_SPARSE variant is evaluated separately.
> > * Restructure the patches for review. Keep I/O preparation ahead
> > of virtual-entry storage and allocation, and split allocation
> > from the zswap/zero backends.
> > * Split physical backing into allocator, backing-lookup, swapoff
> > preparation and final wiring patches. Register the physical
> > backend with the virtual layer.
> > * Walk PTEs and shmem for physical swapoff. Extend cache-only
> > backing reclaim to allocation-range scans.
> > * Fix cgroup v1 accounting and failed zswap writeback rollback.
> > Register the vswap statistic only in swap builds.
> > * Enable 32-bit with a one-word vtable.
> > * Expand the zswap shrinker benchmarks and add MariaDB read/write
> > results.
>
> Not sure what others prefer, but I usually put the changelog at the
> end, and only the most recent one with a link to the previous version.
> This avoids the cover letter getting too large.

Acked. Will move this to the bottom from now on.

>
> [..]
>
> > II. Design
> > ==========
> >
> > Patches 1-15 build the optional vswap implementation, roughly equivalent
> > to v6 in functionality. Patches 16-20 then make it the common layer for
> > ordinary swapping.
>
> I assume that if we decide to go this route we will fold these patches
> into the series (i.e. start with always-on vswap to begin with)?


Let me try that one first. If it's easier to review then I certainly
can give it a shot.


>
> [..]
>
> > III. Mandatory vswap
> > ====================
> >
> > In the v6 version, vswap keeps separate virtual and direct physical swap
> > paths.
> >
> > At the last vswap sync, we discussed making vswap mandatory to simplify
> > the implementation. Patches 16-20 apply this conversion after the
> > optional vswap implementation.
> > Anonymous and shmem swapping use virtual entries throughout, with swap
> > counts, swapcache and cgroup ownership held at the virtual slot.
> >
> > Physical swap supplies disk backing and raw hibernation slots. Its swap
> > table records reverse mappings to virtual slots, so backing reclaim can
> > find the owner directly. Compressed zswap entries live in the vtable,
> > removing per-device zswap trees. Initialize vswap automatically when
> > CONFIG_SWAP is enabled, and move virtual-only fields out of physical
> > clusters.
>
> This section should call out the extra memory overhead when zswap is
> not used. More generally, I think the cover letter should call out the
> memory overhead for zswap and non-zswap cases (I believe the former is
> 0?).

Yeah the former is 0.

For non-zswap backend, it's 16 bytes per entry! For the forward and
reverse map. We can get rid of the reverse map, if we can get rid of
cluster readahead, and implement a different scheme to do
swap-cache-only freeing. We can do it as a follow-up.

>
> >
> > IV. Benchmarks
> > ==============
> >
> > Highlights
> > ----------
> >
> > The largest gain is with zswap and its shrinker. Host usemem throughput
> > rises about 47% and wall time falls about 32%; kernel build wall time
> > falls 3.6%. With zswap, usemem free time falls about 10-11%. MariaDB TPS
> > rises 11.7% with the shrinker and 6.8% without it. Mean p95 latency
> > falls 12.0% and 6.2%, respectively.
> >
> > Overall wall-time and throughput regressions are mostly a few percent in
> > tight-memory microbenchmarks. Some separate costs are larger: cgrouped
> > SSD usemem free time rises 3.8% and host-zram free time rises 7.0%.
> > These overheads are a tradeoff for simplification: ordinary swapping
> > shares the virtual layer, removing separate direct physical paths.
>
> Do we know what the specific cause of regression is? Is it something
> that can be optimized later while keeping vswap always-on?

There's a couple more places where I can optimize. For e.g, on the
free path right now I'm separating the reference dropping and
uncharging options, but those can be merged to save memcg lookup work.
I think I might also be clearing the zeromap bits twice - a simple
check might be able to shave that one off too.

I can perf around a bit to see how much we can reduce it even further,
but FWIW though it feels like I will just be overindexing on some
microbenchmarks :)