Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1025621lqt; Tue, 19 Mar 2024 10:30:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXAeMJ1LfCHrhkoGK+XMRmNkZsSvTkZOQaU4A8Mmw6T+kMvbuob8KNbyl3eAusKXF+s0NjlbpWm6wBtExnXO/8MQ89O7U9U5L9tqm8HtA== X-Google-Smtp-Source: AGHT+IFeCx1pMzmhYeB90zKOfr7DHqVw6rMqd5ip8hJElH5NjV4gYkclVgU3/MWifne7x+Xq5bca X-Received: by 2002:a17:906:eece:b0:a46:c11d:dd01 with SMTP id wu14-20020a170906eece00b00a46c11ddd01mr5569284ejb.50.1710869403198; Tue, 19 Mar 2024 10:30:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710869403; cv=pass; d=google.com; s=arc-20160816; b=ZaG3n9CbYvPEkLcOHXjlVu8DVagGsjspk1407UBvANss2+LFwg6uLh7WPZ0AAn1MOB ZvXo8hUfgq5L7cSA/juyacrokF7eUMLQXOpCABjWQh0yUINIIJyi8xMNPSjfD0MnOfPr C/ycYwbc7r8d0hFbLSgDqB4KDYG2UJ3ualjtUtMYbdsQBj0Hkj75P5IHBFu7gdeOXWNw 1jygh7TK72pmKqUGJHaATKPYwA+CjobERFyxZsev4XYhcDR47I9S6kjxsyg1Vj2nqW2c yCDg1U1Fi4zhCbBxQKKm1v7CSsbbPdamoUYs5lNHkxtWaJLEGbJmkprmG1x5U7+XHSBC Jzeg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=DRSOwVQmD/LUS31oTkPPiVrE1LXL9Wggo9W1oa7Xqec=; fh=K+qKo3yB4iiVal72lPKNlPnl/NQVQ5dRN//ZwJWBUwg=; b=kwYskSmOCF11DqrMA6cXY8c0BYzqUkdagOqgum+qwewK0N8U3dU75ZgzdaVGOgyfMt oSx8nIUq+Cz6Gi8LyaZsa6sNVfZ5/gHzqcZUAWsoIepjwsyYWr5gDWcC18PR4UKvzWyA qyWOlnaC3uiSe0+NUW2Y0/UW6vX3Q2Wpvracm0k1/aC0mhSeDik6Gt+JIrNqA8j9NWUB wOUiR51WjD7FJNfDtLk9edaebFYYsxVmuFylQZzACiHKh8tRaBFydlL8eE3jExWb4DdT jKYgz2HAg8wEVP3UY9HGUFKQaNcugHSLf1xRqE9yZssPd548c0CjGjUy4/Gu7ClKxIq2 XKlw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=HN4uQQil; arc=pass (i=1 spf=pass spfdomain=joelfernandes.org dkim=pass dkdomain=joelfernandes.org); spf=pass (google.com: domain of linux-kernel+bounces-107916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107916-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dt3-20020a170906b78300b00a45bfa91e83si5386049ejb.465.2024.03.19.10.30.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 10:30:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=HN4uQQil; arc=pass (i=1 spf=pass spfdomain=joelfernandes.org dkim=pass dkdomain=joelfernandes.org); spf=pass (google.com: domain of linux-kernel+bounces-107916-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107916-linux.lists.archive=gmail.com@vger.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9CD691F23381 for ; Tue, 19 Mar 2024 17:30:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 287D21BF53; Tue, 19 Mar 2024 17:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="HN4uQQil" Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (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 63283179A6 for ; Tue, 19 Mar 2024 17:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710869395; cv=none; b=ttFffI8qRnlZvF0qLJIiT6eRDFKWrmqnRMOqmfr5uwiMWjp+RPpzVOzPeduoyBxPseacGefs9wySv4uoZIlZyksbUeXx8MpwZRX56PWuuV1owuCSumbP+0OhmYCX/KpXSRMw9FBm6jjzh8dJ8g71uDH0Y7echd84n77Ddq+kNp8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710869395; c=relaxed/simple; bh=p5DlegjkqXmaO2leoq8/zMuptH6ZXgU5GSZvgXNBGzI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LXpmlFjjuI1wZlcpRGXLKTrO1eYJA3e+DhMoLRgAE5lxDEDIkChAa8EAgo60v9U3UqcJQHiYFFQFzbBT55IRml5SsTgyPILUojxzgHLc0Or3yFN3hs1jXYElXTrD8BiVLmFURH7D/SRpCLK/6ZjyiBaRWptv87Zj/W8Kd5ZrD40= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org; spf=pass smtp.mailfrom=joelfernandes.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b=HN4uQQil; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=joelfernandes.org Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6963c0c507eso855466d6.1 for ; Tue, 19 Mar 2024 10:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1710869392; x=1711474192; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=DRSOwVQmD/LUS31oTkPPiVrE1LXL9Wggo9W1oa7Xqec=; b=HN4uQQiliF8H+21+jOszD1upgzY2VB1TseCOGPVfoHtWrxXuVSFQ3bYs0AzCwReVeL xKuolTuzKLDs6ncwFjsbCJe6cR1upOkfgwHuQNpWs/t608uEiSLv/wxvwGFlh8E8UPM7 aTdYy+QgJR0Pov0xdKJ0hjX3ZqeULfthW1UOM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710869392; x=1711474192; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DRSOwVQmD/LUS31oTkPPiVrE1LXL9Wggo9W1oa7Xqec=; b=EVsOyASFAr6pLaTNGnqcwkh92d2HI8YNMqFhyC7e+Zxn5pOmod1YXOgyH/CiGVlnkX dIRJoN+0le5sgkCCmXij784Ek9Cso8mumDOUrazft1duQ3Hmrpepn4sex5/rNgMf5z46 YiLp7p8wuLzPvTMdEmDYyS4R8GP8fFM7i0aHMxbTxOTbBUVpOlDJTtUQkZADv9oz2o9E M0cDmXFYeHHvgPRZCsAnW7gGwIiDbO97LZWHa0M2yuQ06246obL3Hv7LMtukKOoj2ku3 8AcDpDIbZ7k49P8MNyF9z8/ujE6yyiirGmXXmMSym7HQgydHDAhdM+C55cMxX1D6tfm2 J+Zw== X-Gm-Message-State: AOJu0YxY6rPcVjYAtUnzUyPIvRCtiDZ/v9+rBDvKRKGkkEkZv9pG8J45 KvVi8FeI3kZSbts2P3reEjzRthPDXlwFhcqKmmz82VT/N+4bgE984OYHNKQaEiE= X-Received: by 2002:ad4:4eab:0:b0:68f:a954:bba1 with SMTP id ed11-20020ad44eab000000b0068fa954bba1mr5302484qvb.26.1710869392049; Tue, 19 Mar 2024 10:29:52 -0700 (PDT) Received: from [10.5.0.2] ([185.195.59.198]) by smtp.gmail.com with ESMTPSA id 15-20020ad45b8f000000b00690dbc390dcsm6681062qvp.89.2024.03.19.10.29.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Mar 2024 10:29:51 -0700 (PDT) Message-ID: <8f221ab6-6d34-4c3b-a6a7-6c1de405000a@joelfernandes.org> Date: Tue, 19 Mar 2024 13:29:49 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 rcu/dev 1/2] rcu/tree: Reduce wake up for synchronize_rcu() common case Content-Language: en-US To: Uladzislau Rezki Cc: linux-kernel@vger.kernel.org, frederic@kernel.org, boqun.feng@gmail.com, neeraj.iitr10@gmail.com, rcu@vger.kernel.org, rostedt@goodmis.org, "Paul E. McKenney" , Neeraj Upadhyay , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Zqiang References: <0B372386-9546-492E-930E-DC6C883F3B2B@joelfernandes.org> <20240319160252.GA186534@joelbox2> From: Joel Fernandes In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 3/19/2024 1:26 PM, Uladzislau Rezki wrote: > On Tue, Mar 19, 2024 at 12:11:28PM -0400, Joel Fernandes wrote: >> On Tue, Mar 19, 2024 at 12:02 PM Joel Fernandes wrote: >>> >>> On Tue, Mar 19, 2024 at 03:48:46PM +0100, Uladzislau Rezki wrote: >>>> On Tue, Mar 19, 2024 at 10:29:59AM -0400, Joel Fernandes wrote: >>>>> >>>>> >>>>>> On Mar 19, 2024, at 5:53 AM, Uladzislau Rezki wrote: >>>>>> >>>>>> On Mon, Mar 18, 2024 at 05:05:31PM -0400, Joel Fernandes wrote: >>>>>>> >>>>>>> >>>>>>>>> On Mar 18, 2024, at 2:58 PM, Uladzislau Rezki wrote: >>>>>>>> >>>>>>>> Hello, Joel! >>>>>>>> >>>>>>>> Sorry for late checking, see below few comments: >>>>>>>> >>>>>>>>> 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) >>>>>>>>> --- >>>>>>>>> Rebased on paul/dev of today. >>>>>>>>> >>>>>>>>> kernel/rcu/tree.c | 36 +++++++++++++++++++++++++++++++----- >>>>>>>>> kernel/rcu/tree.h | 1 + >>>>>>>>> 2 files changed, 32 insertions(+), 5 deletions(-) >>>>>>>>> >>>>>>>>> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c >>>>>>>>> index 9fbb5ab57c84..bd29fe3c76bf 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. */ >>>>>>>>> @@ -1642,8 +1643,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); >>>>>>>>> return; >>>>>>>>> + } >>>>>>>>> >>>>>>>>> WARN_ON_ONCE(!rcu_sr_is_wait_head(done)); >>>>>>>>> head = done->next; >>>>>>>>> @@ -1666,6 +1670,9 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) >>>>>>>>> >>>>>>>>> rcu_sr_put_wait_head(rcu); >>>>>>>>> } >>>>>>>>> + >>>>>>>>> + /* Order list manipulations with atomic access. */ >>>>>>>>> + atomic_dec_return_release(&rcu_state.srs_cleanups_pending); >>>>>>>>> } >>>>>>>>> >>>>>>>>> /* >>>>>>>>> @@ -1673,7 +1680,7 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) >>>>>>>>> */ >>>>>>>>> static void rcu_sr_normal_gp_cleanup(void) >>>>>>>>> { >>>>>>>>> - struct llist_node *wait_tail, *next, *rcu; >>>>>>>>> + struct llist_node *wait_tail, *next = NULL, *rcu = NULL; >>>>>>>>> int done = 0; >>>>>>>>> >>>>>>>>> wait_tail = rcu_state.srs_wait_tail; >>>>>>>>> @@ -1699,16 +1706,35 @@ static void rcu_sr_normal_gp_cleanup(void) >>>>>>>>> break; >>>>>>>>> } >>>>>>>>> >>>>>>>>> - // concurrent sr_normal_gp_cleanup work might observe this update. >>>>>>>>> - smp_store_release(&rcu_state.srs_done_tail, wait_tail); >>>>>>>>> + /* >>>>>>>>> + * Fast path, no more users to process. Remove the last wait head >>>>>>>>> + * if no inflight-workers. If there are in-flight workers, let them >>>>>>>>> + * remove the last wait head. >>>>>>>>> + */ >>>>>>>>> + WARN_ON_ONCE(!rcu); >>>>>>>>> >>>>>>>> This assumption is not correct. An "rcu" can be NULL in fact. >>>>>>> >>>>>>> Hmm I could never trigger that. Are you saying that is true after Neeraj recent patch or something else? >>>>>>> Note, after Neeraj patch to handle the lack of heads availability, it could be true so I requested >>>>>>> him to rebase his patch on top of this one. >>>>>>> >>>>>>> However I will revisit my patch and look for if it could occur but please let me know if you knew of a sequence of events to make it NULL. >>>>>>>> >>>>>> I think we should agree on your patch first otherwise it becomes a bit >>>>>> messy or go with a Neeraj as first step and then work on youth. So, i >>>>>> reviewed this patch based on latest Paul's dev branch. I see that Neeraj >>>>>> needs further work. >>>>> >>>>> You are right. So the only change is to drop the warning and those braces. Agreed? >>>>> >>>> Let me check a bit. Looks like correct but just in case. >>>> >>> >>> Thanks. I was also considering improving it for the rcu == NULL case, as >>> below. I will test it more before re-sending. >>> >>> On top of my patch: >>> >>> ---8<----------------------- >>> >>> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c >>> index 0df659a878ee..a5ef844835d4 100644 >>> --- a/kernel/rcu/tree.c >>> +++ b/kernel/rcu/tree.c >>> @@ -1706,15 +1706,18 @@ static void rcu_sr_normal_gp_cleanup(void) >>> break; >>> } >>> >>> + >>> + /* Last head stays. No more processing to do. */ >>> + if (!rcu) >>> + return; >>> + >> >> Ugh, should be "if (!wait_head->next)" instead of "if (!rcu)". But >> in any case, the original patch except the warning should hold. >> Still, I am testing the above diff now. >> >> - Joel >> > Just in case, it is based on your patch: > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index bd29fe3c76bf..98546afe7c21 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -1711,29 +1711,25 @@ static void rcu_sr_normal_gp_cleanup(void) > * if no inflight-workers. If there are in-flight workers, let them > * remove the last wait head. > */ > - WARN_ON_ONCE(!rcu); > - ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_done_tail); > - > - if (rcu && rcu_sr_is_wait_head(rcu) && rcu->next == NULL && > - /* Order atomic access with list manipulation. */ > - !atomic_read_acquire(&rcu_state.srs_cleanups_pending)) { > + if (wait_tail->next && rcu_sr_is_wait_head(wait_tail->next) && !wait_tail->next->next && > + !atomic_read_acquire(&rcu_state.srs_cleanups_pending)) { Yes this also works. But also if wait_tail->next == NULL, then you do not need to queue worker for that case as well. I sent this as v3. If you want to add that and resend my patch with the above diff, that would also be fine. Or I can do that, let me know. Thanks! - Joel