Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp578808lqt; Thu, 6 Jun 2024 11:43:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXEvz5uAhhH7SNSj3oAC9ZubuiXG1tyBRfnbREHSP6ijudowJ2HOetO2UzAUeGJ9Z88oQefxUAtXBRhL4YDlUX8TuwhzM/PKuUMrSYq4A== X-Google-Smtp-Source: AGHT+IEUKj22x5HEPeGu6FFWSipfrcCKtOuArP7rWtA0ZEDd/bxYXkoVqigX54PlfuaLfVoTchRW X-Received: by 2002:a05:6a20:7285:b0:1b2:b3ff:fb7b with SMTP id adf61e73a8af0-1b2f9ccabe0mr491788637.52.1717699429394; Thu, 06 Jun 2024 11:43:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717699429; cv=pass; d=google.com; s=arc-20160816; b=VhaebW6cdVDE/o1A2tE5bfDFnK+mMZiXXhUQzOIp+Gk14RjQ4pWyV94N3JdHz8noO4 bhZJz/mfLmh04hcxf3X4pUoQFeJ+mVGIpKtF65zKQx949zhBLw9HKupa4XPuFuVzIO1s BKPZynfRc7v3iioM9LWyO5C9+c9Oq4sxYQdk611G0ENPZXvo2ADwIJRsRncjVU1YsTFz pScv+FiYabiKINtuX2MMmjwbxSstELrnJa6Dlm0R7bjBw0L8Z4uhAqR7t+ReR0Jsykuq eQlG5yHYI01akdnTUuAYSWczfah4K3zQLC+NJExDFEIyHja5TRZ5as88Bk/uEK1mE2Ug YXqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=4OZmPHbNKqlxge6J87AXCUeCHmkEqps8P7jqh0GV9QM=; fh=2SS6GLfn0HipWFTrXtSoz76lIQwcg5qPVPeTt5mfTKs=; b=BoOEJPTJgsrfZiIrUMv0jnCMN4s6UzIlqMGBlbfM1kE/0+b95l8dX+GVEti4Wk6Vwl ngTPYNA0Iie2nKymv39ikvL3HdqSPo0Jvzp00qVvypFWPpqMEZQkD91adVBAJ2cpSDY7 V/mP22vzkr3b1/1U3gh/YmmWlgZesqHs1btECLHNdUC6SMEC9wcpNKjEhPmPVXJOFNIt UgeF2/WxgfGVsLI1KUuWwjVpRzaGak3YFrk02vJqyPR+r3RxH9emITI81vb086swZ2Qo pWnh8/KJP6JIthrbXF78B4hslu5W+CWXVCAuX/SQp+1fC0OwqFOEHFpaicHFXrvenT/8 Jc6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=octv4Whv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-204862-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204862-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de2760ace9si1559945a12.518.2024.06.06.11.43.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 11:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204862-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=octv4Whv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-204862-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204862-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 04137B2301C for ; Thu, 6 Jun 2024 18:12:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CBC5199391; Thu, 6 Jun 2024 18:12:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="octv4Whv" 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 404A3199389; Thu, 6 Jun 2024 18:12:02 +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=1717697523; cv=none; b=hUVBed2hGeFvxN1LQPJ8YwEIH4JMgtk4+p4RimIS3cdjSjgme/+8PZYOYTQ7zv/Rrf6R7ZiQ3QKoG/J9J0gvxm2Xb76hn4GcqOFd78nw3BXSxMnAvrqAxAQ9Og0ZqGHj13XXRLie8nrGR5uY6WbBxX5kdw8/N00kBUzCCbuUPSM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717697523; c=relaxed/simple; bh=rahIpKZsGpZl2GO/jcg+ZxtQQuJCfpWo2UtJ417xTUw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QMqMYLvd7MWssRBwVq3yLhXSws57WJWiVAANLXrpfFiJsJU557I01fnD+MqU54iQQd64bMyqo/byZg/99NCnLhtjox5y4gp4Wm7ChbRVNiki+RS2gFV0OCF0b9zANPGEpb/u7n+LN5ODOfirLxgZ9ujnxnSwuLeG/FHwvixNHM8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=octv4Whv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C271EC2BD10; Thu, 6 Jun 2024 18:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717697522; bh=rahIpKZsGpZl2GO/jcg+ZxtQQuJCfpWo2UtJ417xTUw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=octv4WhvBePeFZZ7velpQzLtev96q76IfX8815xAMcWB094Tr6JRjwZ7nR4LPR9Xs 53zumoRdLP7y38JHxw3o6f9GxytjeiC1is8PNEz1zhgkz+I7MAEIjH+cjkZui3gQpc TWom6+lJO94GhpTjiUI33wEbgothq1eDMFQOE5oS6zIkkLUpvSJfOVulwr1fcu86ju rEgU91FGQHRzyOiIHOr/2csuQQm4Y6XSvMxqoVLNw9jY8/7+PlPrKieWhyJ91PVovI EMfmq4Cp9bkzYypKi7UpyMdhu363uhDXrtpF4nNez52jO0l1S/3BAqKUdRRVHFEcQW Fms/kBSgmutGg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 47419CE3F34; Thu, 6 Jun 2024 11:12:02 -0700 (PDT) Date: Thu, 6 Jun 2024 11:12:02 -0700 From: "Paul E. McKenney" To: Neeraj upadhyay Cc: Frederic Weisbecker , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Joel Fernandes (Google)" , Uladzislau Rezki Subject: Re: [PATCH rcu 3/9] rcu/tree: Reduce wake up for synchronize_rcu() common case Message-ID: Reply-To: paulmck@kernel.org References: <657595c8-e86c-4594-a5b1-3c64a8275607@paulmck-laptop> <20240604222355.2370768-3-paulmck@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Jun 06, 2024 at 11:28:07AM +0530, Neeraj upadhyay wrote: > On Wed, Jun 5, 2024 at 10:05 PM Frederic Weisbecker wrote: > > > > Le Tue, Jun 04, 2024 at 03:23:49PM -0700, Paul E. McKenney a écrit : > > > From: "Joel Fernandes (Google)" > > > > > > In the synchronize_rcu() common case, we will have less than > > > SR_MAX_USERS_WAKE_FROM_GP number of users per GP. Waking up the kworker > > > is pointless just to free the last injected wait head since at that point, > > > all the users have already been awakened. > > > > > > Introduce a new counter to track this and prevent the wakeup in the > > > common case. > > > > > > Signed-off-by: Joel Fernandes (Google) > > > Reviewed-by: Uladzislau Rezki (Sony) > > > Signed-off-by: Paul E. McKenney > > > --- > > > kernel/rcu/tree.c | 35 ++++++++++++++++++++++++++++++----- > > > kernel/rcu/tree.h | 1 + > > > 2 files changed, 31 insertions(+), 5 deletions(-) > > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > index 6ba36d9c09bde..2fe08e6186b4d 100644 > > > --- a/kernel/rcu/tree.c > > > +++ b/kernel/rcu/tree.c > > > @@ -96,6 +96,7 @@ static struct rcu_state rcu_state = { > > > .ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED, > > > .srs_cleanup_work = __WORK_INITIALIZER(rcu_state.srs_cleanup_work, > > > rcu_sr_normal_gp_cleanup_work), > > > + .srs_cleanups_pending = ATOMIC_INIT(0), > > > }; > > > > > > /* Dump rcu_node combining tree at boot to verify correct setup. */ > > > @@ -1633,8 +1634,11 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) > > > * the done tail list manipulations are protected here. > > > */ > > > done = smp_load_acquire(&rcu_state.srs_done_tail); > > > - if (!done) > > > + if (!done) { > > > + /* See comments below. */ > > > + atomic_dec_return_release(&rcu_state.srs_cleanups_pending); > > > > This condition is not supposed to happen. If the work is scheduled, > > there has to be a wait_queue in rcu_state.srs_done_tail. And decrementing > > may make things worse. > > > > I also don't see a scenario where this can happen. However, if we are > returning from here, given that for every queued work we do an > increment of rcu_state.srs_cleanups_pending, I think it's safer to > decrement in this > case, as that counter tracks only the work queuing and execution counts. > > atomic_inc(&rcu_state.srs_cleanups_pending); > if (!queue_work(sync_wq, &rcu_state.srs_cleanup_work)) > atomic_dec(&rcu_state.srs_cleanups_pending); Linus Torvald's general rule is that if you cannot imagine how a bug can happen, don't attempt to clean up after it. His rationale (which is *almost* always a good one) is that not knowing how the bug happens means that attempts to clean up will usually just make matters worse. And all too often, the clean-up code makes debugging more difficult. One example exception to this rule is when debug-objects detects a duplicate call_rcu(). In that case, we ignore that second call_rcu(). But the reason is that experience has shown that the usual cause really is someone doing a duplicate call_rcu(), and also that ignoring the second call_rcu() makes debugging easier. So what is it that Frederic and I are missing here? Thanx, Paul > Thanks > Neeraj > > > So this should be: > > > > if (WARN_ON_ONCE(!done)) > > return; > > > > Thanks. > > >