From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796002103; b=NziMuXs59gSrizPWuXG8QYh+tjsgA3u5qpS9Bd73M1+a0vxWgifB0WyWQkYdrFJn8aoD eLK4r2FjOH1fGCpqWRFMmV6pAwuDC+5vaUd2ZeipjFP/HmBsSgnzubsmYXhqyc4l99JNi wGomaE/TIYiR/jtHNnYki6fgo8uz8SQUSJuhwYJlRFVsXpJ/F5dokznZcYTYKxnI6SDqJ 4a6PZCZ9iyyOGA9qrZzymLMRSCtxsDclD/SWGUyZQlYpZgzeyAtgVHMuYDKW620xm9oRK uLmNCl8q7S36CxKi9NtXFly8UZ58hezFt+jkTDsL12oxcoYeQWF7MdpoVr83HvWKBsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796002103; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-Id: In-Reply-To:References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=I7eWPJzXWAJ1OiptHyT5SHee3R9WaxnUHtTaJRbMphE=; b=nYyH5TOXD8yreaC/ZcH9ERcfKwu71oAiVXcYRR00jjTeXc/622ZWqXeEKr8Qf/YnP2Pd VPhJs9ZWOQxhbQrOc8l4OihkimmIRMPsVqv/7la27mthoNI+QFSc/8cfh1amW5zcaKiOW FF1plxMx9hylFuw4XZ7N1h+RNmBxGkhbC9Onjy7dRC6eG9xoR2TkHeZtjFGxw4Q52/97V UOaxfXUzOVj7S5sFNXasvn//CKfGcJPaqneZDjZe5inqglpGdJAfDG6fVZ0XiYLiMhNc1 wYP3NUroOa/dmUMGauhCVRwnKUrQdtABD9lgvJDUwFaq+kdmlDewfIxg/4HCwSe6kGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=L5ec0nIq; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19253606A31C for ; Mon, 30 Nov 2026 01:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=L5ec0nIq Received: by smtp.kernel.org (Postfix) with ESMTPSA id B69C51F000C1; Mon, 30 Nov 2026 01:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796002101; bh=I7eWPJzXWAJ1OiptHyT5SHee3R9WaxnUHtTaJRbMphE=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=L5ec0nIqqbHfgY6sZxOH2B/omtzqLLBWFqElESvivMjvNtsF8K5K7MObU0q5tE9Bs zo0PYmjJ+vvVH2TyUSSMV4I5Zjy8l0Y2DZKjbgoefqLnCVqE1NT3Bl8FfCWz4Ixn3+ FnH+rIjIZfHRqRwpBvBOwGlwN10TN0WPqLWctLG4= Date: Sun, 29 Nov 2026 17:28:21 -0800 From: Andrew Morton To: Egor Shalashnov 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 Message-Id: <20261129172821.ff27377465a4a3c939155ece@linux-foundation.org> In-Reply-To: <0100d9e7-140c-41f7-be26-f1148b101fe6@gmail.com> References: <0100d9e7-140c-41f7-be26-f1148b101fe6@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 30 Nov 2026 02:43:26 +0300 Egor Shalashnov 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 > +#include > #include > #include > #include > #include > #include > #include > +#include I'll slip a #include in here and I'll queue this for test and more review.