Re: [PATCH v5 0/3] mm: fix workingset refaults in the zswap writeback path

From: Yosry Ahmed

Date: Wed Dec 02 2026 - 20:14:14 EST


> > > > > Yep. We rely on swap cache as the synchronization point, so
> > > > > unfortunately it will be a problem for all form of backend transfer
> > > > > down the line.
> > > > >
> > > > > >
> > > > > > Seems like both problems can be fixed if we can teach the swap cache
> > > > > > about a folio being added for paths other than swapin? Patch 1 reads
> > > > > > like it does this, but seems like we still need patch 3 to keep the
> > > > > > shadow alive inside zswap on writeback. I think patch 1 only moved the
> > > > > > refault out of the swap cache but kept allocating a new shadow?
>
> If you prefer, I can come up with a new variant of patch 1 that
> teaches swapcache about swapin and other paths so it does not wrongly
> count the refault during writeback.
>
> But patch 3 is still needed because otherwise a new shadow would be
> minted when the buffer is freed.

My beef is actually with patch 3, because I don't think carrying over
the shadow belongs in zswap. How much improvement does patch 3 give us
on top of 1+2?

> > > > > >
> > > > > > I wonder if both problems can be tackled at once if we handle this
> > > > > > within the swap cache, and if the implementation would be simpler.
> > > > >
> > > > > Porting this solution to vswap kind of gives you the generic solution
> > > > > that you're interested in.
> > > > >
> > > > > In vswap world, we add a per-swap-cluster array for the backend. So
> > > > > instead of moving the shadow to the zswap tree during writeback, we
> > > > > will move the shadow to that array instead (and everything else in
> > > > > this patch series stay the same). That is plenty generic - it will
> > > > > work for all form of backend transfer mechanisms that rely on swap
> > > > > cache as the synchronization point.
> > > > >
> > > > > (I'm not sure if we'll have enough tags in 32 bit systems though -
> > > > > might have to add a type field for that setup).
> > > > >
> > > > > So basically, this is another reason that you kind of need vswap for
> > > > > efficient and sound backend transfer :)
> > > >
> > > > I agree that vswap provides a better place for this, but I honestly
> > > > don't like shoving the shadow into the zswap entry in the meantime.
> > > > Would this be cleaner / more generic if it's done within the
> > > > swapcache? We can always move it to vswap later as needed.
> > >
> > > What do you mean by "within the swap cache"? The swap table slot that
> > > used to hold the shadow now carries the swap cache folio, so we can't
> > > really store it there. I guess we can tinker with the folio's fields?
> > > Not sure if that's cleaner though...
> >
> > Hmm yeah.. I honestly wonder if we should table this (patch 3
> > specifically) until vswap lands. More motivation for landing vswap :P
> >
>
> Yes the virtual_table of vswap would be "prettier" (even though my llm
> and I did not find an easy way to use it during writeback @Nhat).
>
> But as Nhat said (and unless someone has a better idea), this is the
> only thing that would change with vswap, so it won't make it easier to
> review.
>
> In addition, this fix then becomes totally un-backportable to stable
> releases (this bug has been present since 5.9).

I am not sure if this is stable-worthy to be honest. It's a
performance thing and it has been a while, so I don't think that's an
issue. Perhaps it doesn't look much better on top of vswap, but I
think maintaining the shadow when moving a page between swap backends
at least fits better there conceptually.