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

From: Yosry Ahmed

Date: Thu Dec 03 2026 - 11:23:53 EST


On Wed, Dec 2, 2026 at 5:51 PM Chris Li <chrisl@xxxxxxxxxx> wrote:
>
> On Wed, Dec 2, 2026 at 5:12 PM Yosry Ahmed <yosry@xxxxxxxxxx> wrote:
> >
> > On Wed, Dec 2, 2026 at 10:55 AM Chris Li <chrisl@xxxxxxxxxx> wrote:
> > I think we still need to go through the swapcache to synchronize
> > incoming page faults on the writeback page, otherwise we could end up
> > with 2 copies of the page, right?
>
> The incoming page fault is still using the current swap cache part. So
> two page faults are fine there. The write back is using a different
> folio not insert into the swap cache. However the folio being written
> back is not visible to the process so that is fine. The page fault
> data will load from the zswap entry into the swap cache.

What happens if they race?

- Zswap starts writeback, allocates a folio *not* in the swap cache
and swaps in into it. Assuming writeback won't delete the entry from
the xarray or free it as it does today.
- A page fault happens on the same page, now the page fault allocates
a new folio in the swap cache, and decompresses the compressed page
again into it.

Now we have two copies of the page in memory at the same time.
Userspace mappings point at one and zswap writeback is swapping out
another. You can't have two folios pointing at the same swap slot, at
least not without a lot of special casing, or having the writeback
folio just written out directly to the swapfile without getting the
slot first. The data can also get out of sync if the mapped folio is
written to before the writeback folio is written out.

Overall, I think it opens a large can of worms if we do not go through
the swap cache. A lot of things can break.