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 CC096C4708C for ; Wed, 30 Nov 2022 19:43:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25EFA6B0074; Wed, 30 Nov 2022 14:43:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 20F696B0075; Wed, 30 Nov 2022 14:43:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D7526B0078; Wed, 30 Nov 2022 14:43:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F1CBC6B0074 for ; Wed, 30 Nov 2022 14:43:47 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CB5DC1A0745 for ; Wed, 30 Nov 2022 19:43:47 +0000 (UTC) X-FDA: 80191133694.04.C7641A7 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf24.hostedemail.com (Postfix) with ESMTP id 6C63418000D for ; Wed, 30 Nov 2022 19:43:47 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id w15-20020a17090a380f00b0021873113cb4so3377507pjb.0 for ; Wed, 30 Nov 2022 11:43:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=4l2DcvUQCzeMiHwNRaOIRYz18pb8Nk29Wkn+R8wEW5k=; b=i/i/jt8iAGXMRriP8xCj6maFrHzwSpMBsKZVf6rgU3SYA00gIaZX/ele+xaG/FZuIl gIxD3fI1T68WBPelwtCcgIgZ4Kf+c+6iyAYUxiDi2+M9D1p59C/ywPsLIpuWJU7eMQxf 4kWn0pWGD+gKCHHCXCqA79dMiPaftl20sgR1hJoCjZ8QZx/Pk8dpcnwgfgBOvv0OktBb i7u4ZBFEfhk7YxRk+KIAFO/2QiclwERjFQbLq2QzZ/b20Bqwv1M352GuCodE5U9QvToW okrhRWttNEHN6FM95IKfSt8lh9WFVKKeCJ3ZGA/CRUnMNG+PqihEvSS2gV9obmbHZlcC PE9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4l2DcvUQCzeMiHwNRaOIRYz18pb8Nk29Wkn+R8wEW5k=; b=mLseMtuvko6z8PNJwP8wJ1ww0DwMFB4cLD0NVjChYHRao7Ocq4ko7QNh3NTlicERP6 jFnxHuyfF/bCo8OE/CKUEJVK8wprlk9BuEp7V1dmUz99So6yEqhyg9IxOhOsCaXdnYkQ 1llIJIPJskXBrS8zNPwHejFz1aTGqDLWEYZ58thqwfUp2p+nK53IChW35NsBPmiFosLk oMU0Jp45wjdGAeP3/hcTOwV72yIK/kv2OtaH6WaB3vjXBwKwzpJbOIVgx6Y99Usjj1aJ ykP77OLOisGqC57WpmXIxBghslNWEmbteYZ0tZ3jwf96X3blCNAld7N49rm42Ne5b8gf /WCg== X-Gm-Message-State: ANoB5pmj7ZaE7E6+Kp4f/ERYm6LVT7tU7kuqjzaaHRRyx7yOY7o3j/m+ IG/YQKY7cSVZp5KRBjG4MT3KDyhF2VANMA== X-Google-Smtp-Source: AA0mqf7EmnKIHMkE2Ak7r9WcCipVMPY60uFMXYLh/Imw2ExO2xUH6i6GYyyvHEKFisYKhpXnDOq2EA== X-Received: by 2002:a17:90a:1d5:b0:219:55d5:f30e with SMTP id 21-20020a17090a01d500b0021955d5f30emr8474826pjd.107.1669837426215; Wed, 30 Nov 2022 11:43:46 -0800 (PST) Received: from localhost (2603-800c-1a02-1bae-a7fa-157f-969a-4cde.res6.spectrum.com. [2603:800c:1a02:1bae:a7fa:157f:969a:4cde]) by smtp.gmail.com with ESMTPSA id k1-20020a170902c40100b001869ba04c83sm1862427plk.245.2022.11.30.11.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 11:43:45 -0800 (PST) Date: Wed, 30 Nov 2022 09:43:44 -1000 From: Tejun Heo To: "Paul E. McKenney" Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Joel Fernandes (Google)" , Dennis Zhou , Christoph Lameter , linux-mm@kvack.org Subject: Re: [PATCH rcu 12/16] percpu-refcount: Use call_rcu_hurry() for atomic switch Message-ID: References: <20221130181316.GA1012431@paulmck-ThinkPad-P17-Gen-1> <20221130181325.1012760-12-paulmck@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221130181325.1012760-12-paulmck@kernel.org> ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="i/i/jt8i"; spf=pass (imf24.hostedemail.com: domain of htejun@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=htejun@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669837427; a=rsa-sha256; cv=none; b=HRfzj94o1qjW2kpfw//gO+hrbtvR2kKr0Rd1ffDFIcfyyVitZaQaBFH9okBD/J9ZvVBK7X +n3EM6YURxrxo7o/lPYqdkXFo9z8jizXkIKQXwP1xCQLK0xncUjMRzVlR0kVjMgefyLmhZ WFLPDw7akhcRVMPuIOMD05ASIIf8C3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669837427; h=from:from:sender: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=4l2DcvUQCzeMiHwNRaOIRYz18pb8Nk29Wkn+R8wEW5k=; b=NqFtkruorWsqnH+qqhcxqhta4o9X8cDnAgp/miDVeRgXfgfMFGqr2y/m0EbpznrfTniBFV OpLEkxMIUz0RlmeFtCcSitvImTun02ie14/QOn5N8R2hhNZUbyOKwZ5QaslU3fX3ZW9lkU R3dUWPqc/9apr54n5NtOddhVb5AdZFA= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="i/i/jt8i"; spf=pass (imf24.hostedemail.com: domain of htejun@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=htejun@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-Rspamd-Server: rspam01 X-Stat-Signature: hwsyahrwjqa5ymdbf7zxm1pimsdqiojx X-Rspamd-Queue-Id: 6C63418000D X-Rspam-User: X-HE-Tag: 1669837427-292959 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: On Wed, Nov 30, 2022 at 10:13:21AM -0800, 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: Acked-by: Tejun Heo Thanks. -- tejun