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

From: Yosry Ahmed

Date: Thu Dec 03 2026 - 12:00:19 EST


On Thu, Dec 3, 2026 at 8:54 AM Chris Li <chrisl@xxxxxxxxxx> wrote:
>
> On Thu, Dec 3, 2026 at 8:23 AM Yosry Ahmed <yosry@xxxxxxxxxx> wrote:
> >
> > 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.
> Ack.
>
> > - 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.
> Ack.
>
> >
> > Now we have two copies of the page in memory at the same time.
>
> Ack.
>
> > 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
>
> The folio being written back can be considered a bounce buffer
> belonging to the block device side, it has nothing to do with the
> upper part of swap, PTE etc.
>
> > 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.
>
> That is the one byte refcount in the zswap entry we are discussing in
> the other email. We can use some exploration to see exactly how bad
> the change is; now, with LLMs doing most of the heavy lifting of
> validation.

I don't see how the refcount can help with having out of sync copies
of the folio in memory. Also, I don't think the complexity is
warranted here to be honest.

> > 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.
>
> Think about writing the compressed data to drive case. It is the same
> set of complexity you need to deal with any way.

Writing compressed data is a different use case that may warrant
additional complexity. But I do imagine that if we do so, we still
won't have multiple competing writes to the same swap slots. We'd
probably carve out an area on disk to write compressed memory, or
multiplex them onto swap slots? Not sure, I didn't think it through.