From: Johannes Weiner <hannes@cmpxchg.org>
To: Yosry Ahmed <yosryahmed@google.com>
Cc: Kairui Song <kasong@tencent.com>,
linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Nhat Pham <nphamcs@gmail.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Chris Li <chrisl@kernel.org>, Barry Song <v-songbaohua@oppo.com>,
"Huang, Ying" <ying.huang@intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/zswap: avoid touching XArray for unnecessary invalidation
Date: Fri, 11 Oct 2024 14:28:31 -0400 [thread overview]
Message-ID: <20241011182831.GC351101@cmpxchg.org> (raw)
In-Reply-To: <CAJD7tkaZgEHUNce5c8LWpWXKnTZ7geOuBym41t+UoZax_nky7Q@mail.gmail.com>
On Fri, Oct 11, 2024 at 10:53:31AM -0700, Yosry Ahmed wrote:
> On Fri, Oct 11, 2024 at 10:20 AM Kairui Song <ryncsn@gmail.com> wrote:
> >
> > From: Kairui Song <kasong@tencent.com>
> >
> > zswap_invalidation simply calls xa_erase, which acquires the Xarray
> > lock first, then does a look up. This has a higher overhead even if
> > zswap is not used or the tree is empty.
> >
> > So instead, do a very lightweight xa_empty check first, if there is
> > nothing to erase, don't touch the lock or the tree.
Great idea!
> XA_STATE(xas, ..);
>
> rcu_read_lock();
> entry = xas_load(&xas);
> if (entry) {
> xas_lock(&xas);
> WARN_ON_ONCE(xas_reload(&xas) != entry);
> xas_store(&xas, NULL);
> xas_unlock(&xas);
> }
> rcu_read_unlock();
This does the optimization more reliably, and I think we should go
with this version.
First, swapcache is size-targeted to 50% of total swap capacity (see
vm_swap_full()), and swap is rarely full. Second, entries in swapcache
don't hold on to zswap copies. In combination, this means that after
pressure spikes we routinely end up with many swapcache entries and
only a few zswap entries. Those few zswapped entries would defeat the
optimization when invalidating the many swapcached entries.
So checking on a per-entry basis makes a lot of sense.
next prev parent reply other threads:[~2024-10-11 18:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-11 17:19 Kairui Song
2024-10-11 17:53 ` Yosry Ahmed
2024-10-11 18:28 ` Johannes Weiner [this message]
2024-10-12 3:04 ` Kairui Song
2024-10-12 3:26 ` Yosry Ahmed
2024-10-12 5:08 ` Kairui Song
2024-10-12 3:33 ` Chengming Zhou
2024-10-12 4:48 ` Kairui Song
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=20241011182831.GC351101@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=v-songbaohua@oppo.com \
--cc=ying.huang@intel.com \
--cc=yosryahmed@google.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