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

From: Yosry Ahmed

Date: Thu Dec 03 2026 - 18:05:47 EST


> > > 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.

I would expect/hope so. Thanks!

> > > 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.

This is per used swapped out entry, not for the entire swapfile size, right?

> > > 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 :)

Yeah I am not saying we need to do this, just wondering what the
options are if it becomes a real problem. Thanks!