[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMgjq7AjBMJAE-rj2MmB53FrQKcsARK5tZ3sKB4+uhWhkQ=EGA@mail.gmail.com>
Date: Sat, 19 Oct 2024 04:01:18 +0800
From: Kairui Song <ryncsn@...il.com>
To: Matthew Wilcox <willy@...radead.org>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
Johannes Weiner <hannes@...xchg.org>, Yosry Ahmed <yosryahmed@...gle.com>,
Nhat Pham <nphamcs@...il.com>, Chengming Zhou <chengming.zhou@...ux.dev>,
Chris Li <chrisl@...nel.org>, Barry Song <v-songbaohua@...o.com>,
"Huang, Ying" <ying.huang@...el.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm, zswap: don't touch the XArray lock if there is no
entry to free
On Sat, Oct 19, 2024 at 3:46 AM Matthew Wilcox <willy@...radead.org> wrote:
>
> On Sat, Oct 19, 2024 at 03:25:25AM +0800, Kairui Song wrote:
> > if (xa_empty(tree))
> > return;
> >
> > - entry = xa_erase(tree, offset);
> > - if (entry)
> > + rcu_read_lock();
> > + entry = xas_load(&xas);
> > + if (entry) {
>
> You should call xas_reset() here. And I'm not sure it's a great idea to
> spin waiting for the xa lock while holding the RCU read lock? Probably
> not awful but I could easily be wrong.
Thanks for the review. I thought about it, that could cancel this optimization.
Oh, and there is a thing I forgot to mention (maybe I should add some
comments about it?). If xas_load found an entry, that entry must be
pinned by HAS_CACHE or swap slot count right now, and one entry can
only be freed once.
So it should be safe here?
This might be a little fragile though, maybe this optimization can
better be done after some zswap invalidation path cleanup.
>
> > + xas_lock(&xas);
> > + WARN_ON_ONCE(xas_reload(&xas) != entry);
> > + xas_store(&xas, NULL);
> > + xas_unlock(&xas);
> > zswap_entry_free(entry);
> > + }
> > + rcu_read_unlock();
> > }
> >
> > int zswap_swapon(int type, unsigned long nr_pages)
> > --
> > 2.47.0
> >
> >
>
Powered by blists - more mailing lists