From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 353C12376E6; Wed, 23 Jul 2025 20:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753302485; cv=none; b=HgQ88ihMzpZNVW6IAn7xzGM0aRSIDPqslxLnF7hLC6GAkEJsjrec1kKAjoC6aUjOMWGrvXENr3W8PL4EJ7w9hIj6U/xTtRRfU9dc9nHxtg2nDz4IG2YzbML3Tdt7MY6qvTORK7w/ok6PjiiGgYM71gL35eQuNRsBwQzQmWqAV0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753302485; c=relaxed/simple; bh=4SSkEhAPaR3rmWNDWHon6TEQT0/S26eD/pqJzTj6tKY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VuF+DTXzsqjEw+mYKicDIXt4kAMSbyRLccpm/sT7a5wOsPj0yC1OSYJQiZ3Lx0gvhkkB77vvUXj33Eb6195uWoP7ZeS8nPAaHl8oKa5epcDoJlNrQEB4Su5+7OocJdfSAwvUlw83QFtJD6OQSko5gD1DggSJ8uiKF5lyOS6LfUw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ULy0KYa/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ULy0KYa/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC959C4CEFD; Wed, 23 Jul 2025 20:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753302484; bh=4SSkEhAPaR3rmWNDWHon6TEQT0/S26eD/pqJzTj6tKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ULy0KYa/FimCMc+aEg4Xwoo6O80VGJfim2xYMZdinFvpInetq1E2+AhMUVE3wd1u6 aIfYo+7B+pzrgyaCyTONE6y9GMreTgO54rzFRPmeseKJB5Vn/tRUPYPPFJEWokioNL vtXp4eyCGxVKQKj8GuRAviUaKL0gjYqK2FUXgS+jxNN71XRr1k51yspLV2Fd7nRnrQ 4+GAr9cAq8Q+4m8WGgcvxU/M+yrkpp/aEOR/3dgbW6GYlmKFsmk3hw3MBARSbLE98N hZk5/7qjUh+SlPWC6BTJ99WB4k3d1qcm9xLOUD2TD59IxX5dFc09n5gW5wDCGN//SH f6ZkVxZe1iAtw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 13651CE0F52; Wed, 23 Jul 2025 13:28:04 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Mathieu Desnoyers , Sebastian Andrzej Siewior , bpf@vger.kernel.org Subject: [PATCH v4 6/6] srcu: Document srcu_flip() memory-barrier D relation to SRCU-fast Date: Wed, 23 Jul 2025 13:28:00 -0700 Message-Id: <20250723202800.2094614-6-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> References: <45397494-544e-41c0-bf48-c66d213fce05@paulmck-laptop> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The smp_mb() memory barrier at the end of srcu_flip() has a comment, but that comment does not make it clear that this memory barrier is an optimization, as opposed to being needed for correctness. This commit therefore adds this information and points out that it is omitted for SRCU-fast, where a much heavier weight synchronize_srcu() would be required. Signed-off-by: Paul E. McKenney Cc: Mathieu Desnoyers Cc: Steven Rostedt Cc: Sebastian Andrzej Siewior Cc: --- kernel/rcu/srcutree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index c5e8ebc493d5e..1ff94b76d91f1 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -1168,6 +1168,16 @@ static void srcu_flip(struct srcu_struct *ssp) * counter update. Note that both this memory barrier and the * one in srcu_readers_active_idx_check() provide the guarantee * for __srcu_read_lock(). + * + * Note that this is a performance optimization, in which we spend + * an otherwise unnecessary smp_mb() in order to reduce the number + * of full per-CPU-variable scans in srcu_readers_lock_idx() and + * srcu_readers_unlock_idx(). But this performance optimization + * is not so optimal for SRCU-fast, where we would be spending + * not smp_mb(), but rather synchronize_rcu(). At the same time, + * the overhead of the smp_mb() is in the noise, so there is no + * point in omitting it in the SRCU-fast case. So the same code + * is executed either way. */ smp_mb(); /* D */ /* Pairs with C. */ } -- 2.40.1