[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240320100803.GB294822@cmpxchg.org>
Date: Wed, 20 Mar 2024 06:08:03 -0400
From: Johannes Weiner <hannes@...xchg.org>
To: Yosry Ahmed <yosryahmed@...gle.com>
Cc: Chris Li <chrisl@...nel.org>, Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
Nhat Pham <nphamcs@...il.com>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
Chengming Zhou <zhouchengming@...edance.com>,
Barry Song <v-songbaohua@...o.com>
Subject: Re: [PATCH v7] zswap: replace RB tree with xarray
On Wed, Mar 20, 2024 at 07:24:27AM +0000, Yosry Ahmed wrote:
> [..]
> > > > - /* 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?
I don't think that's quite right.
Writeback will bail on swapcache insert, yes, but it will access the
entry before attempting it. If LRU publishing happened before setting
entry->swpentry e.g., we'd have a problem, while your comment suggets
it would be safe to rearrange the code like this.
So LRU publishing order does matter.
Powered by blists - more mailing lists