From: Andrew Morton <akpm@linux-foundation.org>
To: Egor Shalashnov <shalasheg@gmail.com>
Cc: linux-mm@kvack.org, dennis@kernel.org, tj@kernel.org,
cl@gentwo.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] percpu_ref: replace the global switch lock with hashed locks
Date: Sun, 29 Nov 2026 17:28:21 -0800 [thread overview]
Message-ID: <20261129172821.ff27377465a4a3c939155ece@linux-foundation.org> (raw)
In-Reply-To: <0100d9e7-140c-41f7-be26-f1148b101fe6@gmail.com>
On Mon, 30 Nov 2026 02:43:26 +0300 Egor Shalashnov <shalasheg@gmail.com> wrote:
> Currently, percpu_ref uses the global percpu_ref_switch_lock to
> protect the mode switching operation. When multiple percpu_ref
> perform mode switching at the same time, the lock may become a
> performance bottleneck.
>
> This patch introduces a hashed array of 64 cacheline-separated
> spinlocks to fix this issue without introducing a separate
> spinlock for each percpu_ref.
>
> The contention was observed during full-volume discard in a
> thin-provisioning implementation in an out-of-tree module.
> Logical regions are processed concurrently, each requiring its
> reference to be killed, drained, and reinitialized after processing
> discard. Reinitialization also clears the per-CPU counters while
> holding the switch lock.
>
> In module-local fio discard benchmarks with 128 jobs, one pinned
> to each logical CPU, the 64-lock implementation gave the following
> completion times in seconds:
>
> Volume (TB) Global Hash64 Speedup
> 1 3.393 0.722 4.70x
> 2 5.039 1.399 3.60x
> 4 8.705 1.471 5.92x
> 8 16.955 2.834 5.98x
> 16 34.056 4.997 6.82x
> 32 67.177 9.467 7.10x
> 64 134.081 20.311 6.60x
> 128 263.881 40.135 6.57x
> 256 543.297 83.590 6.50x
Thanks, lgtm.
> --- a/lib/percpu-refcount.c
> +++ b/lib/percpu-refcount.c
> @@ -1,12 +1,15 @@
> // SPDX-License-Identifier: GPL-2.0-only
> #define pr_fmt(fmt) "%s: " fmt, __func__
>
> +#include <linux/cache.h>
> +#include <linux/hash.h>
> #include <linux/kernel.h>
> #include <linux/sched.h>
> #include <linux/wait.h>
> #include <linux/slab.h>
> #include <linux/mm.h>
> #include <linux/percpu-refcount.h>
> +#include <linux/spinlock.h>
I'll slip a #include <linux/log2.h> in here and I'll queue this for
test and more review.
prev parent reply other threads:[~2026-11-30 1:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 23:43 Egor Shalashnov
2026-11-30 1:28 ` Andrew Morton [this message]
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=20261129172821.ff27377465a4a3c939155ece@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=dennis@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shalasheg@gmail.com \
--cc=tj@kernel.org \
/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
all inboxes | Powered by JetHome®