linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chengming Zhou <chengming.zhou@linux.dev>
To: Kairui Song <ryncsn@gmail.com>, Johannes Weiner <hannes@cmpxchg.org>
Cc: Yosry Ahmed <yosryahmed@google.com>,
	linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	Nhat Pham <nphamcs@gmail.com>, Chris Li <chrisl@kernel.org>,
	Barry Song <v-songbaohua@oppo.com>,
	"Huang, Ying" <ying.huang@intel.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mm/zswap: avoid touching XArray for unnecessary invalidation
Date: Sat, 12 Oct 2024 11:33:14 +0800	[thread overview]
Message-ID: <5fa01666-51d4-4ccb-bcd4-3b3620dd2e2b@linux.dev> (raw)
In-Reply-To: <CAMgjq7Ajen_XQHGznNp3hFWOes+K=fn6HssW3-SUL8i4xDebhQ@mail.gmail.com>

On 2024/10/12 11:04, Kairui Song wrote:
> Johannes Weiner <hannes@cmpxchg.org> 于 2024年10月12日周六 02:28写道:
>>
>> 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.
> 
> Hi Yosry and Johannes,
> 
> This is a good idea. But xa_empty is just much lighweighter, it's just
> a inlined ( == NULL ) check, so unsurprising it has better performance
> than xas_load.
> 
> And surprisingly it's faster than zswap_never_enabled. So I think it

Do you have CONFIG_ZSWAP_DEFAULT_ON enabled? In your case, CPU will go 
to the unlikely branch of static_key every time, which maybe the cause.

> could be doable to introduce something like zswap_may_have_swpentry as
> Yosry suggested.
> 
> So how about a combined version with xas_load and xa_empty? Check
> xa_empty first as a faster path, then xas_load, then xas_store.

Yeah, I also think this combined version is better.

Thanks.

> 
> Here is the benchmark result (time of swapin 2G zero pages in us):
> 
> Before:   1908944 1905870 1905322 1905627 1901667
> xa_empty: 1835343 1827367 1828402 1831841 1832719
> z.._enabled: 1838428 1831162 1838205 1837287 1840980
> xas_load: 1874606 1878971 1870182 1875852 1873403
> combined: 1845309 1832919 1831904 1836455 1842570
> 
> `combined` is xa_empty + xas_load.


  parent reply	other threads:[~2024-10-12  3:33 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
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 [this message]
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=5fa01666-51d4-4ccb-bcd4-3b3620dd2e2b@linux.dev \
    --to=chengming.zhou@linux.dev \
    --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=ryncsn@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