Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2864408rwb; Wed, 30 Nov 2022 11:59:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf6brIc/bwBInCB81z6XQjYaUpAMIsJMz+I/TBYjb9JNl6zVC6EjKv8jDDZL+/WN5/t7pl65 X-Received: by 2002:a17:90a:1c96:b0:219:4ae8:1d9b with SMTP id t22-20020a17090a1c9600b002194ae81d9bmr11948369pjt.147.1669838340336; Wed, 30 Nov 2022 11:59:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669838340; cv=none; d=google.com; s=arc-20160816; b=LKeLsg7Hrmj3FgFz8FEl0QeSyNsYwsSgmz8OrOWDTIo277fbuu1Ceko1tToSobaMq9 ZlbXWtwHtabvbMPNWh7ZLabxkVInwhO539/+OmWf3cLqr0y46bzmGnKDWaoU89XHtzua zueJeMpzIOYV9r9IpW9JR4CPlmXNLWtDZCLWOB2f03UB+fSKA8a0MyYMny5FBoAvBruB KXxajkNi7MUrgqhPPJ/PJZqOnl4cfUi4CIUnAYcIArA/Fyhxd+B2rUWxwGGVwqpfLj9M XRWDPkl2L2vdXZ1VjqEMc/tqdfFSnaMevxpLpwnkYKAexuOn9FGu6OG+FydelrDg3Pdh hgrQ== 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:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=4l2DcvUQCzeMiHwNRaOIRYz18pb8Nk29Wkn+R8wEW5k=; b=TQkCKxrLZTtpxv1V1I+SBDN7EBDgDinWoyZNIdYQHXHTxbf2beHE4MSLmsoSGh9Xd6 4hmrS0NlI7pGbjqcRTBJek8x2PG5HctpcDzHaz//OKSeo21O1RlBkMT8TkotVi3EcFPg WREJ9Ac2ZUvTgIDPbdGhDQUmKZBGuSjK0HY1T0x+WBRJ7Zr3vasGN6il1b469Qhp9rno 9m45M9Rs53xJq0TtkY7Nag336p1YzNaoO0ih9DJ8Jg0i/51iVp+zf9zh7N8bA6ZgNglY zqIU5jHvSmT8MoXe2WssapusDXrvp1shXBicZCXrX10JSuhkQ9DXV2LAQCp0U1eqTrsC T+og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="i/i/jt8i"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a056a00089600b00572d3b2ed93si2712586pfj.139.2022.11.30.11.58.49; Wed, 30 Nov 2022 11:59:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="i/i/jt8i"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbiK3ToX (ORCPT + 84 others); Wed, 30 Nov 2022 14:44:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiK3Tn6 (ORCPT ); Wed, 30 Nov 2022 14:43:58 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AACF497036; Wed, 30 Nov 2022 11:43:46 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id jl24so231308plb.8; Wed, 30 Nov 2022 11:43:46 -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=ik/NEhV2ha4OPFOr9TI2Y+bPuJgbUQFYtuQK8NlPH5JENanbY5DF9nPpgwunwQN5iV B+R/AgOE0Tv/QNBevY5ldOXk4Vb6V/nfdM0grewTlNVSH4FB7815SORI199iPT+gCWak HWW30D+ZoZFUxmdGuaXEfqIH0D3vm4HtITTpQoCr6r94QhuMKkAzFWVpy1GIfd9dcQfB Qa4vV9wJETJtiv+a2+Lf5RjZpwSfbKhOvfmag1JXM7qlH+65GIEsm9EnU4cbEiIztODt +8JyBXSEKSzdEMcZbs9vu9QrygCFXRauXhXrG77vN6+nz1A5Dmqb7lsH/wvT2BsSZiRN ykrw== X-Gm-Message-State: ANoB5pnGrHaEF3clWKStt45pI2KT3aREgS0vna1ZdLZ10pk0xbaGyehU eVuVn2GutkzTWkkvKsE1hak= 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) Sender: Tejun Heo 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> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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