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

From: Nhat Pham

Date: Tue Dec 01 2026 - 22:33:22 EST


On Tue, Dec 1, 2026 at 11:17 AM Yosry Ahmed <yosry@xxxxxxxxxx> wrote:
>
> On Tue, Dec 1, 2026 at 9:57 AM Alexandre Ghiti <alex@xxxxxxxx> wrote:
> >
> > When an anonymous folio is reclaimed, workingset_eviction() stores a
> > "shadow" (the eviction cookie) in the swap slot so that a later swap-in
> > can be recognised as a refault and, if the refault distance is short
> > enough, the page can be re-activated. This is how anon workingset/refault
> > detection has worked since commit aae466b0052e ("mm/swap: implement
> > workingset detection for anonymous LRU").
> >
> > zswap writeback breaks this in two independent ways:
> >
> > - Over-count at writeback: the shrinker allocates a buffer folio in the
> > swap cache, and the allocation path counts that folio as a refault.
> >
> > - Lost eviction cookie at reclaim: adding the buffer to the swap cache
> > overwrites the slot's shadow, so the original cookie is lost; when the
> > buffer folio is finally reclaimed a fresh, inaccurate cookie is minted
> > in its place.
> >
> > This series preserves the shadow within zswap itself, without any new
> > swap-table or swap-slot state. At writeback, instead of erasing the freed
> > zswap entry, the captured shadow is parked in the zswap tree in its place,
> > so it outlives the writeback buffer folio.
> >
> > Finally, the refault evaluation is moved out of the swap-cache allocator
> > into the swap-in callers, so allocating the writeback buffer is no longer
> > miscounted as a refault.
>
> I admittedly did not look at the individual patches yet, but this
> seems to be too invasive. I also wonder how this would interact with
> incoming vswap and swap tiering work. Seems like it would become a
> generic problem whenever we need to move a page between swap tiers, we
> have to allocate a folio in the swap cache, but we want to keep the
> shadow intact and avoid reactivation.

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