Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp424512lqp; Mon, 10 Jun 2024 08:11:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZrFxsqjNcyzkx3RTw4Ccx0T+xZfOfs++4cq82XXxCKekOd7Knnuu1JVnhXVVbercwQfXX/Hv48x3SuagXSpmTAJ/FGB5KMyhvKGUJwQ== X-Google-Smtp-Source: AGHT+IHM1wVGIrd6/aL2vg61NNEPUZM8hi6xHAogj3NQCRcFR//Hvrfy5PGrKXba+qhinVx11ICK X-Received: by 2002:a50:d71a:0:b0:57c:7ee5:baeb with SMTP id 4fb4d7f45d1cf-57c7ee5baf4mr2423096a12.37.1718032263227; Mon, 10 Jun 2024 08:11:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718032263; cv=pass; d=google.com; s=arc-20160816; b=h5+OY9x6W68aXRyU+4uWbPYMVOj/A0ogItK38JeYA/NqNvkPHdnCiyXZFnlC6oyl/l jt+MGf/Z0VEG8LCQS3v+ho7SqK6ObdeBdxBFj9lFoJdb9MH24m3+aPp8icZfemlCZtfF lu+yRj7JFyK1fLhkw4dX1iqegKSMxhMfKM+XU9c4BHQVESyHY+FKle3zMVeuL5/Eticq NMATgOQW8n+pJSXKjuAjZq90T3i9vzCv4iKwSh9yWaw6FrfeJZmfiTNQkuacl4F8tZ7a NNR3+c4lDkqNicccvSfnnX9UEWsa3DoI5ot2lym9f/hdNpo/Ed1oFxO6P6CC02GS4Utj FhHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=H6BguNh1FhrEQspBFq6w1adelDyMULw6oHmc3IxATUs=; fh=Qh7xOoC4/Cjmz0Jg05XEFFKSFK7on99YM4bWrbOtqlE=; b=bojSJ/ege0o26neUYGtCQUifkB0ClB6auQCW6mCGWnwdiLBTtQ2K7fJ3KA9L68EaDG TqA9vd+R8ot6T4qr8P06HVI19wBadd7rQbuW7/WXSsJVaN1EPqLI8johFdi6vKMIC10l +PFIIOdqQPEvfqR6hxG6BsB3ilvbczPtDohL6dNb1N2vACt75MA1njm54uMm2Ypd0wrc c7jWhhrk8GtNn6w59mXlsavUauH2WsFhpZTU7lTVNqcTB9jqrwAp+zC1n/G4Ncd69Oek nwfPd6x9zK2MPJfo2zagAii+DGMdrFL4/ZK1tMAkkhy1QbyOf57xzeA8i4LrdIwslA83 8EUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CyZT3uH6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208426-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae289b70si4887283a12.616.2024.06.10.08.11.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 08:11:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CyZT3uH6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208426-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C24E51F2371F for ; Mon, 10 Jun 2024 15:11:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86A05139580; Mon, 10 Jun 2024 15:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CyZT3uH6" 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 7E75A13212B; Mon, 10 Jun 2024 15:10:55 +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=1718032255; cv=none; b=ioU6qdjt8+mVN4tUs/PskSH3CIANqmRXEJPAAjN4qCXqlcWnCb11X/gRXck56377uFLglQyBqM9b0kVTQQHEGr7Z51oF29Ovs+6MzBoogF5Ki5t1JH3IUtXQFgc5A2c+sABgCt9jX8BKFGXW4ONvJBR2hzIqxh0ER52snQC8ZgI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032255; c=relaxed/simple; bh=6AlFxH4NIHxQy7Ir3kIGMAcdMCTeUeBcXMZVbDgDHQM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rZrz2QIQSCioHKJIq3yKBcUCxpZ54N5xDgOM/O6gF9S/6xyFDb0OevlvD1ZUZep9gkPWPMkNlBRSdc1fqi8xSbXdW1mR5diRGONE4KDCpTX9mt6ri0gfC1haizhopvnBOu6QPt6jTUKjSeCBpDsxSOkh9GUx+maEYrWa2Q8HCnY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CyZT3uH6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D064C2BBFC; Mon, 10 Jun 2024 15:10:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718032255; bh=6AlFxH4NIHxQy7Ir3kIGMAcdMCTeUeBcXMZVbDgDHQM=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=CyZT3uH68inUrPXz5GzpHEUS53QFtQ/YVgvPnJcBMKRNMXs+hiVUeG69JiYo+utc9 +w/NwxXiZUXO+J56yN8IMSU3RgjB8GuhxtDjccvt/iep4H0q8YU6L8eaYsrBryMs+b TXfN4looZ5DRppmaPFj+gpRC0l35C/86Cs2qi31sa3Tjp2V+ctyRsMnsdxvHYXWe2D l64DWtjjBAk9qW7X0735xhPrMxSIcY1PwqmtdrYaEpFb7IckG89drxPfEvSbLlKkPp t+RE/fUFoX5EbmN1Nl3+iPZKca1ckc9mqvN5qytR1M1Mp8WATM2wehrQeODZCHdyWu ZFgjF06ZgxDjQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B00B6CE2373; Mon, 10 Jun 2024 08:10:54 -0700 (PDT) Date: Mon, 10 Jun 2024 08:10:54 -0700 From: "Paul E. McKenney" To: Leonardo Bras Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Sean Christopherson Subject: Re: [PATCH rcu 6/9] rcu: Add rcutree.nocb_patience_delay to reduce nohz_full OS jitter Message-ID: <50efb4a3-578a-4df9-9bb2-550eb8c17d43@paulmck-laptop> Reply-To: paulmck@kernel.org References: <657595c8-e86c-4594-a5b1-3c64a8275607@paulmck-laptop> <20240604222355.2370768-6-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=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jun 10, 2024 at 02:05:30AM -0300, Leonardo Bras wrote: > On Tue, Jun 04, 2024 at 03:23:52PM -0700, Paul E. McKenney wrote: > > If a CPU is running either a userspace application or a guest OS in > > nohz_full mode, it is possible for a system call to occur just as an > > RCU grace period is starting. If that CPU also has the scheduling-clock > > tick enabled for any reason (such as a second runnable task), and if the > > system was booted with rcutree.use_softirq=0, then RCU can add insult to > > injury by awakening that CPU's rcuc kthread, resulting in yet another > > task and yet more OS jitter due to switching to that task, running it, > > and switching back. > > > > In addition, in the common case where that system call is not of > > excessively long duration, awakening the rcuc task is pointless. > > This pointlessness is due to the fact that the CPU will enter an extended > > quiescent state upon returning to the userspace application or guest OS. > > In this case, the rcuc kthread cannot do anything that the main RCU > > grace-period kthread cannot do on its behalf, at least if it is given > > a few additional milliseconds (for example, given the time duration > > specified by rcutexperiementationree.jiffies_till_first_fqs, give or take > > scheduling > > delays). > > > > This commit therefore adds a rcutree.nocb_patience_delay kernel boot > > parameter that specifies the grace period age (in milliseconds) > > before which RCU will refrain from awakening the rcuc kthread. > > Preliminary experiementation suggests a value of 1000, that is, > > Just a nit I found when cherry-picking here > s/experiementation/experimentation/ Good eyes! I will fix this on my next rebase, thank you! Thanx, Paul > Thanks! > Leo > > > one second. Increasing rcutree.nocb_patience_delay will increase > > grace-period latency and in turn increase memory footprint, so systems > > with constrained memory might choose a smaller value. Systems with > > less-aggressive OS-jitter requirements might choose the default value > > of zero, which keeps the traditional immediate-wakeup behavior, thus > > avoiding increases in grace-period latency. > > > > [ paulmck: Apply Leonardo Bras feedback. ] > > > > Link: https://lore.kernel.org/all/20240328171949.743211-1-leobras@redhat.com/ > > > > Reported-by: Leonardo Bras > > Suggested-by: Leonardo Bras > > Suggested-by: Sean Christopherson > > Signed-off-by: Paul E. McKenney > > Reviewed-by: Leonardo Bras > > --- > > Documentation/admin-guide/kernel-parameters.txt | 8 ++++++++ > > kernel/rcu/tree.c | 10 ++++++++-- > > kernel/rcu/tree_plugin.h | 10 ++++++++++ > > 3 files changed, 26 insertions(+), 2 deletions(-) > > > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > > index 500cfa7762257..2d4a512cf1fc6 100644 > > --- a/Documentation/admin-guide/kernel-parameters.txt > > +++ b/Documentation/admin-guide/kernel-parameters.txt > > @@ -5018,6 +5018,14 @@ > > the ->nocb_bypass queue. The definition of "too > > many" is supplied by this kernel boot parameter. > > > > + rcutree.nocb_patience_delay= [KNL] > > + On callback-offloaded (rcu_nocbs) CPUs, avoid > > + disturbing RCU unless the grace period has > > + reached the specified age in milliseconds. > > + Defaults to zero. Large values will be capped > > + at five seconds. All values will be rounded down > > + to the nearest value representable by jiffies. > > + > > rcutree.qhimark= [KNL] > > Set threshold of queued RCU callbacks beyond which > > batch limiting is disabled. > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > index 35bf4a3736765..408b020c9501f 100644 > > --- a/kernel/rcu/tree.c > > +++ b/kernel/rcu/tree.c > > @@ -176,6 +176,9 @@ static int gp_init_delay; > > module_param(gp_init_delay, int, 0444); > > static int gp_cleanup_delay; > > module_param(gp_cleanup_delay, int, 0444); > > +static int nocb_patience_delay; > > +module_param(nocb_patience_delay, int, 0444); > > +static int nocb_patience_delay_jiffies; > > > > // Add delay to rcu_read_unlock() for strict grace periods. > > static int rcu_unlock_delay; > > @@ -4344,11 +4347,14 @@ static int rcu_pending(int user) > > return 1; > > > > /* Is this a nohz_full CPU in userspace or idle? (Ignore RCU if so.) */ > > - if ((user || rcu_is_cpu_rrupt_from_idle()) && rcu_nohz_full_cpu()) > > + gp_in_progress = rcu_gp_in_progress(); > > + if ((user || rcu_is_cpu_rrupt_from_idle() || > > + (gp_in_progress && > > + time_before(jiffies, READ_ONCE(rcu_state.gp_start) + nocb_patience_delay_jiffies))) && > > + rcu_nohz_full_cpu()) > > return 0; > > > > /* Is the RCU core waiting for a quiescent state from this CPU? */ > > - gp_in_progress = rcu_gp_in_progress(); > > if (rdp->core_needs_qs && !rdp->cpu_no_qs.b.norm && gp_in_progress) > > return 1; > > > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h > > index 340bbefe5f652..31c539f09c150 100644 > > --- a/kernel/rcu/tree_plugin.h > > +++ b/kernel/rcu/tree_plugin.h > > @@ -93,6 +93,16 @@ static void __init rcu_bootup_announce_oddness(void) > > pr_info("\tRCU debug GP init slowdown %d jiffies.\n", gp_init_delay); > > if (gp_cleanup_delay) > > pr_info("\tRCU debug GP cleanup slowdown %d jiffies.\n", gp_cleanup_delay); > > + if (nocb_patience_delay < 0) { > > + pr_info("\tRCU NOCB CPU patience negative (%d), resetting to zero.\n", nocb_patience_delay); > > + nocb_patience_delay = 0; > > + } else if (nocb_patience_delay > 5 * MSEC_PER_SEC) { > > + pr_info("\tRCU NOCB CPU patience too large (%d), resetting to %ld.\n", nocb_patience_delay, 5 * MSEC_PER_SEC); > > + nocb_patience_delay = 5 * MSEC_PER_SEC; > > + } else if (nocb_patience_delay) { > > + pr_info("\tRCU NOCB CPU patience set to %d milliseconds.\n", nocb_patience_delay); > > + } > > + nocb_patience_delay_jiffies = msecs_to_jiffies(nocb_patience_delay); > > if (!use_softirq) > > pr_info("\tRCU_SOFTIRQ processing moved to rcuc kthreads.\n"); > > if (IS_ENABLED(CONFIG_RCU_EQS_DEBUG)) > > -- > > 2.40.1 > > >