Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp220163rdd; Wed, 22 Nov 2023 14:01:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtz1+BTcEAAleDxTTtpzNrFOhKvAucJMHciOHTvnyxPNbtj6OrquHvcz2LvY3Jpum1yC4E X-Received: by 2002:a17:90b:4f4c:b0:268:ca76:64a with SMTP id pj12-20020a17090b4f4c00b00268ca76064amr3724268pjb.49.1700690494015; Wed, 22 Nov 2023 14:01:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700690493; cv=none; d=google.com; s=arc-20160816; b=lfM04dHIeumbBsZlj+V5dj+BzHcWBuUJXBd2bLJriyGMXsoFJs88l9cYATihYGrNc7 +dWM2TXNNXDMbiSX3za6pQrur20ijINGvVXOYXZjpGnzKUjgTRV3wRK1K6sHUlbj6w9T skPhryxqsF9KcD9jmTWFu2haQP/OfWOymxYzfzROob2ihwtE+eHPnW5MruUcErGmkWcr Cu/iVCmqc8fC1uO8YzZkmmFOyZK+TnTWxDRXY0Wd9gOZhf8Pb5NCa0scTCQz/mHcewqS dsmmU//vJBZXy035/XXvfxy5dlu+onmltL9DcViPInV02ZQ4g5AkJ2odNqUCSYV2qJ4o fFhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=JlO7RtP1vf369l/gQ7T1/93TqpYwXLEMEE+SpdrGYB4=; fh=qaEbbkOEfHKM9WHIbUbfGUBKMwkF7MDUyulGrSePYRU=; b=Z/HSAhUckCZK0j+bVZlUbea+J6n5h2bw15wed7M2cWZm/Zil3UsmTw40JeCKQNYOpH RvHfBOvlEEt0K/dcCr7M3u+ur9h2xdGoJz2d/9iexuzdvlW5HWdWqK7aRFhPFGSct/9y y9lGNyJq8675vtz3iNyhwgu8hTQmsIB8vOI2kJChNuzSGayfmhUjQ+9ZbRx4yuOGoCsQ lcd7XLqfvsJgWVMMR9q/tRo62vshR/Jb+yYQMWeVbBTpJMwcYkEXRW0/ZzQOfNKZsAYO InPqd5bB8xUqngMk5j9dbOVgrAY8ImC6bdOgNOSaO77cmx2J8esLCHnlXDhZljWB4Fwx K1dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R4ZpUYg3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d22-20020a17090ad3d600b002683f507990si462357pjw.109.2023.11.22.14.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 14:01:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R4ZpUYg3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 06AD8806B82A; Wed, 22 Nov 2023 14:00:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232064AbjKVWAR (ORCPT + 99 others); Wed, 22 Nov 2023 17:00:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbjKVWAP (ORCPT ); Wed, 22 Nov 2023 17:00:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC6310C; Wed, 22 Nov 2023 14:00:12 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1E49C433C7; Wed, 22 Nov 2023 22:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700690412; bh=ZiMYxOQFb+TDdnQ6v43qXplIgnPy8bym53lENqByhY4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=R4ZpUYg3J2Dwk6dweZsS3DYZOUwu7ZkMQdvOcpOWaEezJCOmZ67x7a+WxlGtJYlmt 5UjLKjuN2tnbwFMYDjS6VQHoMYeyA3qWDu2v6CnVzhiWjhlmQuM4H2zUu9EEOaU+2K 4ObHXiIFwQde9PWu3pJSBDc54vkXfdg/fFgpkHgm5T1YtPZCTkncEkEtkC3CKbvs1k mgnqQK1peWldufOVhoMgePwKnBWzAuCd4+dcFWpspYXpxJUFc9N8ubVe7xhIg7JSGx O0pCENp/qWoYXN48AIIBhUarhBDFe2jW9/p6Yj7ggBPByuYw2UR6n8SDjUCDEWCqbC ammX87lqC2UqQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 84245CE1B87; Wed, 22 Nov 2023 14:00:11 -0800 (PST) Date: Wed, 22 Nov 2023 14:00:11 -0800 From: "Paul E. McKenney" To: Qais Yousef Cc: Joel Fernandes , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Andrea Righi , John Stultz , linux-kernel@vger.kernel.org, rcu@vger.kernel.org Subject: Re: [PATCH] rcu: Provide a boot time parameter to enable lazy RCU Message-ID: <811b2157-1009-4339-8ff2-0433512f3094@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20231121205304.315146-1-qyousef@layalina.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231121205304.315146-1-qyousef@layalina.io> X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 22 Nov 2023 14:00:24 -0800 (PST) On Tue, Nov 21, 2023 at 08:53:04PM +0000, Qais Yousef wrote: > To allow more flexible opt-in arrangements while still provide a single > kernel for distros, provide a boot time parameter to enable lazy RCU. > > Specify: > > rcutree.enable_rcu_lazy > > Which also requires > > rcu_nocbs=all > > at boot time to enable lazy RCU assuming CONFIG_RCU_LAZY=y. The > parameter will be ignored if CONFIG_RCU_LAZY is not set. > > With this change now lazy RCU is disabled by default if the boot > parameter is not set even when CONFIG_RCU_LAZY is enabled. > > Signed-off-by: Qais Yousef (Google) > --- > > Makes sense to remove the CONFIG_RCU_LAZY now we have a boot time param? > > We can make it a static key too if it *really* matters. > > Thanks to Joel for helping initially in reviewing this patch which was intended > originally for Android. > > I got some requests to make this a runtime modifiable for init scripts; but > Paul suggested there shall be dragons. So RO it is. I must defer to the people using this, but my experience is that kernel boot parameters work for some people but not others. For example, I tried making rcu_nocbs be the only way to say that all CPUs were going to be offloaded, but popular demand resulted in my adding a CONFIG_RCU_NOCB_CPU_DEFAULT_ALL. If we cannot be sure that we know everyone using CONFIG_RCU_LAZY=y and expecting full laziness, the safe approach is to make another Kconfig option that defaults to off, but with either setting allowing rcutree.enable_rcu_lazy to override at boot time. If you can be sure that you know everyone using CONFIG_RCU_LAZY=y is OK with this change, I must confess that I am curious as to how you found them all. Thoughts? Thanx, Paul > .../admin-guide/kernel-parameters.txt | 5 ++++ > kernel/rcu/tree.c | 26 ++++++++++++++++++- > 2 files changed, 30 insertions(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index 65731b060e3f..2f0386a12aa7 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -5021,6 +5021,11 @@ > this kernel boot parameter, forcibly setting it > to zero. > > + rcutree.enable_rcu_lazy= [KNL] > + To save power, batch RCU callbacks and flush after > + delay, memory pressure or callback list growing too > + big. > + > rcuscale.gp_async= [KNL] > Measure performance of asynchronous > grace-period primitives such as call_rcu(). > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index 3ac3c846105f..e0885905b3f6 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -2718,7 +2718,30 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in) > } > } > > +static bool enable_rcu_lazy; > #ifdef CONFIG_RCU_LAZY > +/* Enable lazy rcu at boot time */ > +static int param_set_rcu_lazy(const char *val, const struct kernel_param *kp) > +{ > + int ret; > + > + /* > + * Make sure a grace period has passed before and after flipping the > + * switch. > + */ > + rcu_barrier(); > + ret = param_set_bool(val, kp); > + rcu_barrier(); > + > + return ret; > +} > +static const struct kernel_param_ops rcu_lazy_ops = { > + .flags = KERNEL_PARAM_OPS_FL_NOARG, > + .set = param_set_rcu_lazy, > + .get = param_get_bool, > +}; > +module_param_cb(enable_rcu_lazy, &rcu_lazy_ops, &enable_rcu_lazy, 0444); OK, I will bite... Given that this is to be set only at boot time, why not replace everything from "#ifdef CONFIG_RCU_LAZY" to here with this? module_param(enable_rcu_lazy, bool, 0444); And then maybe also a __read_mostly on the definition of enable_rcu_lazy? > + > /** > * call_rcu_hurry() - Queue RCU callback for invocation after grace period, and > * flush all lazy callbacks (including the new one) to the main ->cblist while > @@ -2792,7 +2815,8 @@ EXPORT_SYMBOL_GPL(call_rcu_hurry); > */ > void call_rcu(struct rcu_head *head, rcu_callback_t func) > { > - __call_rcu_common(head, func, IS_ENABLED(CONFIG_RCU_LAZY)); > + __call_rcu_common(head, func, IS_ENABLED(CONFIG_RCU_LAZY) && > + READ_ONCE(enable_rcu_lazy)); > } > EXPORT_SYMBOL_GPL(call_rcu); > > -- > 2.34.1 >