Re: [PATCH v7] zswap: replace RB tree with xarray

Yosry Ahmed
2024-03-20T07:24:31Z

[..]
> > > - /* map */
> > > - spin_lock(&tree->lock);
> > > /*
> > > - * The folio may have been dirtied again, invalidate the
> > > - * possibly stale entry before inserting the new entry.
> > > + * We finish initializing the entry while it's already in xarray.
> > > + * This is safe because:
> > > + *
> > > + * 1. Concurrent stores and invalidations are excluded by folio lock.
> > > + *
> > > + * 2. Writeback is excluded by the entry not being on the LRU yet.
> > > + * The publishing order matters to prevent writeback from seeing
> > > + * an incoherent entry.
> >
> > As I mentioned before, writeback is also protected by the folio lock.
> > Concurrent writeback will find the folio in the swapcache and abort. The
> > fact that the entry is not on the LRU yet is just additional protection,
> > so I don't think the publishing order actually matters here. Right?
>
> Right. This comment is explaining why this publishing order does not
> matter. I think we are talking about the same thing here?

The comment literally says "the publishing order matters.." :)

I believe Johannes meant that we should only publish the entry to the
LRU once it is fully initialized, to prevent writeback from using a
partially initialized entry.

What I am saying is that, even if we add a partially initialized entry
to the zswap LRU, writeback will skip it anyway because the folio is
locked in the swapcache.

So basically I think the comment should say:

/*
* We finish initializing the entry while it's already in the
* xarray. This is safe because the folio is locked in the swap
* cache, which should protect against concurrent stores,
* invalidations, and writeback.
*/

Johannes, what do you think?