From: Yosry Ahmed <yosryahmed@google.com>
To: Chris Li <chrisl@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Nhat Pham <nphamcs@gmail.com>,
Johannes Weiner <hannes@cmpxchg.org>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Chengming Zhou <zhouchengming@bytedance.com>,
Barry Song <v-songbaohua@oppo.com>
Subject: Re: [PATCH v9] zswap: replace RB tree with xarray
Date: Tue, 26 Mar 2024 11:48:57 -0700 [thread overview]
Message-ID: <CAJD7tkajaRoZOmHV2HhkWk+j9rV6SBDMiZQYvAEw_Y-mH0CPtg@mail.gmail.com> (raw)
In-Reply-To: <CANeU7Q=8p4whMu+H9GXqQc4Ehjt0_kCtNdg34TiW4bWFw03dbw@mail.gmail.com>
On Tue, Mar 26, 2024 at 11:42 AM Chris Li <chrisl@kernel.org> wrote:
>
> On Tue, Mar 26, 2024 at 11:35 AM Chris Li <chrisl@kernel.org> wrote:
> >
> > Very deep RB tree requires rebalance at times. That contributes to the
> > zswap fault latencies. Xarray does not need to perform tree rebalance.
> > Replacing RB tree to xarray can have some small performance gain.
> >
> > One small difference is that xarray insert might fail with ENOMEM, while
> > RB tree insert does not allocate additional memory.
> >
> > The zswap_entry size will reduce a bit due to removing the RB node, which
> > has two pointers and a color field. Xarray store the pointer in the
> > xarray tree rather than the zswap_entry. Every entry has one pointer from
> > the xarray tree. Overall, switching to xarray should save some memory, if
> > the swap entries are densely packed.
> >
> > Notice the zswap_rb_search and zswap_rb_insert often followed by
> > zswap_rb_erase. Use xa_erase and xa_store directly. That saves one tree
> > lookup as well.
> >
> > Remove zswap_invalidate_entry due to no need to call zswap_rb_erase any
> > more. Use zswap_free_entry instead.
> >
> > The "struct zswap_tree" has been replaced by "struct xarray". The tree
> > spin lock has transferred to the xarray lock.
> >
> > Run the kernel build testing 5 times for each version, averages:
> > (memory.max=2GB, zswap shrinker and writeback enabled, one 50GB swapfile,
> > 24 HT core, 32 jobs)
> >
> > mm-unstable-4aaccadb5c04 xarray v9
> > user 3548.902 3534.375
> > sys 522.232 520.976
> > real 202.796 200.864
> >
> > Signed-off-by: Chris Li <chrisl@kernel.org>
>
> I remove the previous review tags because I like to get some review of
> the conflict resolution as well.
[..]
> > @@ -1624,20 +1562,14 @@ bool zswap_load(struct folio *folio)
> > pgoff_t offset = swp_offset(swp);
> > struct page *page = &folio->page;
> > bool swapcache = folio_test_swapcache(folio);
> > - struct zswap_tree *tree = swap_zswap_tree(swp);
> > + struct xarray *tree = swap_zswap_tree(swp);
> > struct zswap_entry *entry;
> > u8 *dst;
> >
> > VM_WARN_ON_ONCE(!folio_test_locked(folio));
> >
> > - spin_lock(&tree->lock);
> > - entry = zswap_rb_search(&tree->rbroot, offset);
> > - if (!entry) {
> > - spin_unlock(&tree->lock);
> > - return false;
> > - }
> > /*
> > - * When reading into the swapcache, invalidate our entry. The
> > + * When reading into the swapcache, erase our entry. The
> > * swapcache can be the authoritative owner of the page and
> > * its mappings, and the pressure that results from having two
> > * in-memory copies outweighs any benefits of caching the
> > @@ -1649,8 +1581,12 @@ bool zswap_load(struct folio *folio)
> > * the fault fails. We remain the primary owner of the entry.)
> > */
> > if (swapcache)
> > - zswap_rb_erase(&tree->rbroot, entry);
> > - spin_unlock(&tree->lock);
> > + entry = xa_erase(tree, offset);
> > + else
> > + entry = xa_load(tree, offset);
>
> This is the place I make the modification for the conflict resolution.
> It depends on the swapcache to execute xa_erase() or xa_load().
> Obviously, the xa_load() will not delete the entry from the tree.
The conflict resolution LGTM. If this is the only change from v8 then:
Acked-by: Yosry Ahmed <yosryahmed@google.com>
next prev parent reply other threads:[~2024-03-26 18:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 18:35 Chris Li
2024-03-26 18:42 ` Chris Li
2024-03-26 18:48 ` Yosry Ahmed [this message]
2024-03-26 21:04 ` Nhat Pham
2024-03-26 21:20 ` Chris Li
2024-03-26 20:48 ` Johannes Weiner
2024-03-26 21:03 ` Chris Li
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=CAJD7tkajaRoZOmHV2HhkWk+j9rV6SBDMiZQYvAEw_Y-mH0CPtg@mail.gmail.com \
--to=yosryahmed@google.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.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=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