linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chris Li <chrisl@kernel.org>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Yosry Ahmed <yosryahmed@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	 Nhat Pham <nphamcs@gmail.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	 Chengming Zhou <zhouchengming@bytedance.com>,
	Barry Song <v-songbaohua@oppo.com>
Subject: Re: [PATCH v7] zswap: replace RB tree with xarray
Date: Wed, 20 Mar 2024 11:34:32 -0700	[thread overview]
Message-ID: <CANeU7Q=w-vgx3wD9xR6_A-cCe+FFOKfbaoKdYUccOG4B1ir1oA@mail.gmail.com> (raw)
In-Reply-To: <20240320100803.GB294822@cmpxchg.org>

On Wed, Mar 20, 2024 at 3:08 AM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> 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.

Yes, I agree with Johannes on this one. The publish order does matter,
it is not always safe recording the publish order. I will keep the V7
comments here.

Chris


  reply	other threads:[~2024-03-20 18:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-20  5:52 Chris Li
2024-03-20  6:13 ` Yosry Ahmed
2024-03-20  6:34   ` Chris Li
2024-03-20  7:24     ` Yosry Ahmed
2024-03-20 10:08       ` Johannes Weiner
2024-03-20 18:34         ` Chris Li [this message]
2024-03-20 19:11         ` Yosry Ahmed
2024-03-20 19:25           ` Johannes Weiner
2024-03-20 19:34             ` Yosry Ahmed
2024-03-20 19:41               ` Chris Li
2024-03-20 19:46                 ` Yosry Ahmed
2024-03-20 20:03               ` Johannes Weiner
2024-03-20 20:12                 ` Yosry Ahmed
2024-03-20 10:14 ` Johannes Weiner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANeU7Q=w-vgx3wD9xR6_A-cCe+FFOKfbaoKdYUccOG4B1ir1oA@mail.gmail.com' \
    --to=chrisl@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=v-songbaohua@oppo.com \
    --cc=willy@infradead.org \
    --cc=yosryahmed@google.com \
    --cc=zhouchengming@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox