Re: [PATCH v5 0/3] mm: fix workingset refaults in the zswap writeback path
From: Yosry Ahmed
Date: Tue Dec 01 2026 - 13:17:32 EST
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.
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.