Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp358697lqp; Tue, 11 Jun 2024 06:48:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2WfXrSuj1zllCYOx8Z5Q46+LXkHJ7dHH06O8KDPHXe/jT0dMv2I84UWuA9dDtSDictvMHYqFVOfEbp8Ul38Keqpiavpg8FLWrxM+QXw== X-Google-Smtp-Source: AGHT+IHkNCQdhGCayrR1nTJ879u+gGARfC1NDhIos/WO31YHFkw9e2tEg9CFZ/3g0YzvbRfcvOAV X-Received: by 2002:a05:6358:78c:b0:19f:54a8:db62 with SMTP id e5c5f4694b2df-19f54a8de84mr581886655d.20.1718113682799; Tue, 11 Jun 2024 06:48:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718113682; cv=pass; d=google.com; s=arc-20160816; b=0FP3XT/MZqsaT+z0fOZrruhwEnJhJt9DAdi9fqQTHctwAY0HbhcmAjtf7V8YYHaPur qds4cYmUhlKKjqZ/JwZxXBDdhASSXUeN6ivw2nouLY9NPStUowUasAFOtWfzOJCwZFdo P3tpzsYuGSqOrWHbu3LBoxfHm91lkyl+MpaJxdaju92LvaKnN2q69mOY/yi6KWKVu5Ay NuUgLShvoyOttr3/BOpUOi3fNu28ne0h9WhWV17OK/8TK4tR8O+1qFkJEc55uipClpLB hh9Rc2Kui8sXkmD7SzoZG8zmZplAfyvcUIcUi06Y4kEspkeIax4A/xeZbiU+ZRVoMYkj l9Hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=tuBdErgY6EqIvR6Zc36TKGGAfL2xSbBTx8rRNPmSZ6U=; fh=Qx/tPHK2BgsIkMGy52fH8vWFpJkIIlthTZBCXMbFxNU=; b=lRYBY4h+5p1EpOIm1ZraPeo4bul9gFm8kgzs1BR9hzsuPo1NB4hUUKze2b2teL2u1H fzDiwnaDRc7l2DEUKyOu6AQZS9df/8Uy0fx3fcTjAQFHQqGgLv/IBPFXpFQx9+2p83Yc /stWHIfWB+w/Z7HXGYOxM9cA+CPPfbysGX0/9enG9ZrI5s9P4gL7sc6MfAfLhWhLcTLm dwPT2THeUBGV+rdXctM0iyhiCbxCow2jCGh/ThkAoe6owXdx64HA/mpV6SDqRZcYSoF+ J/UTvUd3JtPGzmA+53NSuOdG0H/Dl2MM2HauXAZV5bvo+rYoR4bKi8ESUWvukF2B3FGI i6wg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H+iSwK5C; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-209997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e787075a51si6147727a12.461.2024.06.11.06.48.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 06:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=H+iSwK5C; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-209997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209997-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EF50F284E8D for ; Tue, 11 Jun 2024 13:47:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A580117D36E; Tue, 11 Jun 2024 13:46:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H+iSwK5C" Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F10E917CA1F; Tue, 11 Jun 2024 13:46:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718113614; cv=none; b=iZxspcjC69TbrGi2sTCpy6i6+s7cQknGydvdu/G82+L9bY478XsagfZ+7HnFTdKWvWouR2rv1yGoiTEbCZ6/XaZhVLvb1ZhILF6D7uq4Mm4hQK7p2LwQxQMeTHEGLOTxt/GpjGCCjbBfzeB6hcJEoVg7MgCj5lX11JMnF/2c9Fk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718113614; c=relaxed/simple; bh=cNanDInxZk7FiGVbiLa/XAwCsdIBmKmI7LvvmzDUm30=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rqVxZHilsMV3/JC+wNpePZtFS5hkeGUxEhQ1ZnuA7CAf2atTSLEU5TKFqsi4WDUhJ5xx32bWeVqnV/1Tvvh81vEF+woKAfJa8fQQxgSPTKPnf+zj3dhi+BJWj2cjO9fQuZw9ANgoy2Em5Mhg9m3bSqU4kZCVixLZnMcNjAE7aiY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H+iSwK5C; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-57a1fe63a96so7446789a12.0; Tue, 11 Jun 2024 06:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718113611; x=1718718411; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=tuBdErgY6EqIvR6Zc36TKGGAfL2xSbBTx8rRNPmSZ6U=; b=H+iSwK5Cy8K3Jkf86bTsfBYDr9Thxy4GCQycPT8etsIoCkLQiLXfAgGhfRMkOjYWsc 39JyP48UtvBrg7fWk2B2Te1/iiR2jobyG6U83wWa+igZot3pvywb/NzfVrIdGVyjfoFP 2sDtAEV5pfI2vYcilnHnkQx/823bQ53BGm8M7cc/az7USVwWYsl0tYM5u9w/+KCOE1an m36N9iEWNaBCi5D2TsVqVB5oiqD5vNaiM+x7/AxXbPwFB8LBMhEEnax3E0Ux2B7Jw5E+ 3T8N4/JgmGWyS3XpMRZso3PRdVyKp2NTYyRzASxWmYDgmIuIAC2q1dUJK2BsDwKOBzvj IJ3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718113611; x=1718718411; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tuBdErgY6EqIvR6Zc36TKGGAfL2xSbBTx8rRNPmSZ6U=; b=iydXJaxWs3mfaeWZhMFkYLOJpDbNhmlb28BdPT+zq7IraacWDGHp1VM/mNag2MrvpQ cEihZF5b3Wp4ecTIqhXVIqJFgu12gpGmZ7r+E7kDGRgX13a/4IjX0XIcomOoc5vqofWK l5li2QQYjAkZgr4SUrfCP3xmMzGJzZkXAmXwxO5drntUT10WCLJ76dLgBUdeOgppnGwY nmV3ikGZaVpFnei4zKqIcfFwaoc78iw/ZkmmGW4aockSozgfStjuyPxSmiBcUnTW6Rgi XPqEutjOo7s+YeHJHi8J3txIyg7SVQuA5P8bYs90TIFW51oZ+gaUKndpaj57AoN2q+6x UfMQ== X-Forwarded-Encrypted: i=1; AJvYcCWKWdeAEosrvQ8x5Ve7XkoIsJCTJdhYzDF2JMxYqPGy2XPHDgwSOZIf0XwiFsK3l9wSwl4lcckUk3g8bBwgekws5R1hP1gUIhoWfqJgZLSJmr/cTSPndWyrj3Ou7atPjMOA X-Gm-Message-State: AOJu0YyFvKjcZJvncXuqJawvhQf/YtllpVHB/3nnqf1eTXv8GWao+6W1 juRkqkSohXWQclw8FUZtnDa4tDBtBMvjhQKvyBw1F9ABRc4aqq+vTFhlQ5hMIhQ64UjCRptx5dq 8o3U2CI9rODhUkWrGkoYOd3rJ+gg= X-Received: by 2002:a50:8e17:0:b0:57c:6955:41ea with SMTP id 4fb4d7f45d1cf-57c6955422cmr5411049a12.38.1718113611021; Tue, 11 Jun 2024 06:46:51 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <657595c8-e86c-4594-a5b1-3c64a8275607@paulmck-laptop> <20240604222355.2370768-3-paulmck@kernel.org> <3900dfd9-f2e7-4206-930b-2247186a37db@paulmck-laptop> In-Reply-To: <3900dfd9-f2e7-4206-930b-2247186a37db@paulmck-laptop> From: Neeraj upadhyay Date: Tue, 11 Jun 2024 19:16:37 +0530 Message-ID: Subject: Re: [PATCH rcu 3/9] rcu/tree: Reduce wake up for synchronize_rcu() common case To: paulmck@kernel.org Cc: Frederic Weisbecker , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Joel Fernandes (Google)" , Uladzislau Rezki Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jun 10, 2024 at 8:42=E2=80=AFPM Paul E. McKenney wrote: > > On Fri, Jun 07, 2024 at 07:21:55AM +0530, Neeraj upadhyay wrote: > > On Thu, Jun 6, 2024 at 11:42=E2=80=AFPM Paul E. McKenney wrote: > > > > > > On Thu, Jun 06, 2024 at 11:28:07AM +0530, Neeraj upadhyay wrote: > > > > On Wed, Jun 5, 2024 at 10:05=E2=80=AFPM Frederic Weisbecker wrote: > > > > > > > > > > Le Tue, Jun 04, 2024 at 03:23:49PM -0700, Paul E. McKenney a =C3= =A9crit : > > > > > > 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 =3D { > > > > > > .ofl_lock =3D __ARCH_SPIN_LOCK_UNLOCKED, > > > > > > .srs_cleanup_work =3D __WORK_INITIALIZER(rcu_state.srs_cl= eanup_work, > > > > > > rcu_sr_normal_gp_cleanup_work), > > > > > > + .srs_cleanups_pending =3D ATOMIC_INIT(0), > > > > > > }; > > > > > > > > > > > > /* Dump rcu_node combining tree at boot to verify correct setu= p. */ > > > > > > @@ -1633,8 +1634,11 @@ static void rcu_sr_normal_gp_cleanup_wor= k(struct work_struct *work) > > > > > > * the done tail list manipulations are protected here. > > > > > > */ > > > > > > done =3D 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 schedule= d, > > > > > there has to be a wait_queue in rcu_state.srs_done_tail. And decr= ementing > > > > > may make things worse. > > > > > > > > > > > > > I also don't see a scenario where this can happen. However, if we a= re > > > > 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 co= unts. > > > > > > > > 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 happen= s > > > means that attempts to clean up will usually just make matters worse. > > > And all too often, the clean-up code makes debugging more difficult. > > > > > > > Ok. Thanks for sharing this info! > > > > > 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 real= ly > > > 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? > > > > Maybe nothing. As kworker context does not modify srs_done_tail and > > invalid values > > of srs_done_tail can only be caused by the GP kthread manipulations > > of srs_done_tail , my thought here was, we can keep the pending > > rcu_sr_normal_gp_cleanup_work count consistent with the number of > > queue_work() and kworker executions, even when we see unexpected > > srs_done_tail values like these. However, as you described the general = rule > > is to not attempt any clean up for such scenarios. > > So "if (WARN_ON_ONCE(!done) return;"? > Looks good, nit: one more closing parenthesis "if (WARN_ON_ONCE(!done)) ret= urn;" > Or is there a better way? > I think, above check suffices . Thanks Neeraj > Thanx, Paul