From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 309DFC4321E for ; Wed, 30 Nov 2022 18:20:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A64E66B0072; Wed, 30 Nov 2022 13:20:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A14546B0073; Wed, 30 Nov 2022 13:20:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92A506B0074; Wed, 30 Nov 2022 13:20:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 843E96B0072 for ; Wed, 30 Nov 2022 13:20:07 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4CF6A1C6A45 for ; Wed, 30 Nov 2022 18:20:07 +0000 (UTC) X-FDA: 80190922854.14.0A1646F Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) by imf02.hostedemail.com (Postfix) with ESMTP id D87198001B for ; Wed, 30 Nov 2022 18:20:06 +0000 (UTC) Received: by mail-oi1-f178.google.com with SMTP id b126so5136195oif.5 for ; Wed, 30 Nov 2022 10:20:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Vdp4j6kiy4UQZim4jGenqW5cdZeKNZUSFB293OPsKw4=; b=mAMq4T/gP9VcyGraToL3Nre1HYLcFBZ4FbRuIAZX2RXsBbLAfM+rzDZNmEB1G040Id cxtni1Wm7EGLVeYc1deX2HHYf0AFBvKl8C0SyW23CdBuu5uZao/XoeyG4dG0ncsIcvzD HZ4xcobLS8wW1jOBMQ9Q5FrlsXaGAR3IFpZ1w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=Vdp4j6kiy4UQZim4jGenqW5cdZeKNZUSFB293OPsKw4=; b=1Cq71EMcyAU3ncYXO5Aq7tSKdjst5e5f26kb5md0cRwGeQE7i3mhVm+xkiSi5w0E+d XQx3YFzaZGbk6rqGxec7yOhsPcXC9M7bWmeHDjAA18+Eat5nzTk1nmbcUlrpNqn0OmKY chDR3/uS+Aw1lfSxr84ISmme0pWFpwwudRGPtoBuPrsGLPaaCkMdKeWVZUAiLKAYYoIt JIgRJrpaRYOKTa9Uw84Z3T/467EjrdOeCCT6yAfIEEeWwCAjC6OEuDWCcIo7GfIQn7Kt 1kO9H1SHNvFQgEIZLzkAHFO+vHbH9Sqr+dlhajDESty1eIvZFAgHgONpBycvXh45ev/h jOPQ== X-Gm-Message-State: ANoB5pl5HA1zTi9YX4HkMObhnBaJfG6Wcs01mBD0cJV+U4mMRlIeBoFd XXksKwoemMdVuy3Gy6Itui3fR3vkt0Km11ykW8LnHw== X-Google-Smtp-Source: AA0mqf5sSvtaWTm2pchCNoKTpXWdWxaMgcb6sK6DTCzJV41ofLpiVL6MLm8SxjiIxRU+GiI+YWEzkPB6FcPNwfijHl0= X-Received: by 2002:a05:6808:1a09:b0:354:4a36:aa32 with SMTP id bk9-20020a0568081a0900b003544a36aa32mr32442745oib.15.1669832405979; Wed, 30 Nov 2022 10:20:05 -0800 (PST) MIME-Version: 1.0 References: <20221130181316.GA1012431@paulmck-ThinkPad-P17-Gen-1> <20221130181325.1012760-12-paulmck@kernel.org> In-Reply-To: <20221130181325.1012760-12-paulmck@kernel.org> From: Joel Fernandes Date: Wed, 30 Nov 2022 18:19:55 +0000 Message-ID: Subject: Re: [PATCH rcu 12/16] percpu-refcount: Use call_rcu_hurry() for atomic switch To: "Paul E. McKenney" Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Dennis Zhou , Tejun Heo , Christoph Lameter , linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=joelfernandes.org header.s=google header.b="mAMq4T/g"; spf=pass (imf02.hostedemail.com: domain of joel@joelfernandes.org designates 209.85.167.178 as permitted sender) smtp.mailfrom=joel@joelfernandes.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669832406; a=rsa-sha256; cv=none; b=EDKPZE6YFXpvrcaaGVX4QwYBD1yHWEkRBeO57Sk9y4i1GYa8whHlrH5PMSJh2tSGBMQ8k7 +EcG3GRepmHCUOzYV+G5rUaSRWQ3Gj9/INc+CdiJIFewxzxr28RdPqjSrhhuptKeHr6RAa 9kT+eqT1O6HwAkjuqMHEYUA0jplaxXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669832406; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Vdp4j6kiy4UQZim4jGenqW5cdZeKNZUSFB293OPsKw4=; b=GrFKZiLnxBamSjekFMAqWaSPvw96gbJoPu1JsXWLEeoZd/5Cu23o0bh0Fg36XXV+mUClAj blfcnYTRuJ7eV+pVustaKjgNpYqGjteg4a+c+n5PMzEi1fZR1rNpiUjTTo0Amqaxdld/o9 HnoE37j8KyBY5a9YMpoRABAxpQwSZrw= X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D87198001B Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=joelfernandes.org header.s=google header.b="mAMq4T/g"; spf=pass (imf02.hostedemail.com: domain of joel@joelfernandes.org designates 209.85.167.178 as permitted sender) smtp.mailfrom=joel@joelfernandes.org; dmarc=none X-Stat-Signature: hkdtrhhszkgkfcqjgxy39xda7edpbx8w X-HE-Tag: 1669832406-430971 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Tejun, Could you give your ACK for this patch, for percpu refcount? The API is renamed like in the workqueue one, as well. Thanks a lot, - Joel On Wed, Nov 30, 2022 at 6:13 PM Paul E. McKenney wrote: > > From: "Joel Fernandes (Google)" > > Earlier commits in this series allow battery-powered systems to build > their kernels with the default-disabled CONFIG_RCU_LAZY=y Kconfig option. > This Kconfig option causes call_rcu() to delay its callbacks in order to > batch callbacks. This means that a given RCU grace period covers more > callbacks, thus reducing the number of grace periods, in turn reducing > the amount of energy consumed, which increases battery lifetime which > can be a very good thing. This is not a subtle effect: In some important > use cases, the battery lifetime is increased by more than 10%. > > This CONFIG_RCU_LAZY=y option is available only for CPUs that offload > callbacks, for example, CPUs mentioned in the rcu_nocbs kernel boot > parameter passed to kernels built with CONFIG_RCU_NOCB_CPU=y. > > Delaying callbacks is normally not a problem because most callbacks do > nothing but free memory. If the system is short on memory, a shrinker > will kick all currently queued lazy callbacks out of their laziness, > thus freeing their memory in short order. Similarly, the rcu_barrier() > function, which blocks until all currently queued callbacks are invoked, > will also kick lazy callbacks, thus enabling rcu_barrier() to complete > in a timely manner. > > However, there are some cases where laziness is not a good option. > For example, synchronize_rcu() invokes call_rcu(), and blocks until > the newly queued callback is invoked. It would not be a good for > synchronize_rcu() to block for ten seconds, even on an idle system. > Therefore, synchronize_rcu() invokes call_rcu_hurry() instead of > call_rcu(). The arrival of a non-lazy call_rcu_hurry() callback on a > given CPU kicks any lazy callbacks that might be already queued on that > CPU. After all, if there is going to be a grace period, all callbacks > might as well get full benefit from it. > > Yes, this could be done the other way around by creating a > call_rcu_lazy(), but earlier experience with this approach and > feedback at the 2022 Linux Plumbers Conference shifted the approach > to call_rcu() being lazy with call_rcu_hurry() for the few places > where laziness is inappropriate. > > And another call_rcu() instance that cannot be lazy is the one on the > percpu refcounter's "per-CPU to atomic switch" code path, which > uses RCU when switching to atomic mode. The enqueued callback > wakes up waiters waiting in the percpu_ref_switch_waitq. Allowing > this callback to be lazy would result in unacceptable slowdowns for > users of per-CPU refcounts, such as blk_pre_runtime_suspend(). > > Therefore, make __percpu_ref_switch_to_atomic() use call_rcu_hurry() > in order to revert to the old behavior. > > [ paulmck: Apply s/call_rcu_flush/call_rcu_hurry/ feedback from Tejun Heo. ] > > Signed-off-by: Joel Fernandes (Google) > Signed-off-by: Paul E. McKenney > Cc: Dennis Zhou > Cc: Tejun Heo > Cc: Christoph Lameter > Cc: > --- > lib/percpu-refcount.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c > index e5c5315da2741..668f6aa6a75de 100644 > --- a/lib/percpu-refcount.c > +++ b/lib/percpu-refcount.c > @@ -230,7 +230,8 @@ static void __percpu_ref_switch_to_atomic(struct percpu_ref *ref, > percpu_ref_noop_confirm_switch; > > percpu_ref_get(ref); /* put after confirmation */ > - call_rcu(&ref->data->rcu, percpu_ref_switch_to_atomic_rcu); > + call_rcu_hurry(&ref->data->rcu, > + percpu_ref_switch_to_atomic_rcu); > } > > static void __percpu_ref_switch_to_percpu(struct percpu_ref *ref) > -- > 2.31.1.189.g2e36527f23 >