Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1175728rwl; Wed, 29 Mar 2023 13:56:18 -0700 (PDT) X-Google-Smtp-Source: AKy350ZKUyHQS6QhB9X2KQWBhOKi61xpwIbJr/EGTRWX+KrczjNbsVNScA75g9do5GXtYyit2sVH X-Received: by 2002:a17:906:4b51:b0:92f:3e2b:fbb7 with SMTP id j17-20020a1709064b5100b0092f3e2bfbb7mr20402067ejv.14.1680123378262; Wed, 29 Mar 2023 13:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680123378; cv=none; d=google.com; s=arc-20160816; b=1C5Ih6G3gQ4Ttprcnc0faFurQWRCzc0pYWN11XzAOjOmbceY7Mb98flFsbMQvkNgcE 0IBv9X4UOibWBUhyPV8NFelzfNNrVK+sq7pwpKHaQ4lDAxT1wfR4YjA59PIPpbNCDXlb KEKW/p9mymMREOJ4yM8wjvP08AmWHDxQy9yCIuYgXquZpdzNWkXZFcVEd23625KR15dq NCV+ZqFa4BRw8MnpbQ1TiQQOypvUsQeWbRvuoBCm3k+b5+DkwtCpD9dqU4f6qbk3F880 XrCD74xw5+1oNoukE6mDP0uGRX3+lIb/nM5PXppO2Dd7g4P3FehPSBZIsV9qg7tgs6vW ej6w== 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=RZKcgbgzEbfYanBfOMg0QURS1FNRFGm7NtltdULoVck=; b=BBuEhrecCRDnxhzrvvTLwUjnYCVagoaGgIOd0xH6FAKTUKcEwbOE8SrG6vqFGRihmj UpNKoXgy/DMUS4vZpof+jSfR3KoAeR3w6qSKI5BBlyuz4TQ3bnx5z4JEtUBQKJMxlJdS AUMCKPrhxbwi3MlO61wG5lU+pXwrlh+jcU/PuvFHX0amVnPQHdf6DTGVxQuxKDjxds3f 5J0j06re+8Qp3SagqcqWRMcX8YGaBbWyknDtf9huLg4upUfcGSmWyJnDC4X/aEl5kUwt 3d6OImgOTOLV7DqEPaAKGIN69J1/hCxOcGZef16bTTXoyhM2eEHzpST0rzPgte+vJU+6 785A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="M/MwojbQ"; 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 d18-20020a1709063ed200b00945552edf1fsi184043ejj.783.2023.03.29.13.55.53; Wed, 29 Mar 2023 13:56:18 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b="M/MwojbQ"; 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 S229567AbjC2Uy0 (ORCPT + 99 others); Wed, 29 Mar 2023 16:54:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjC2UyX (ORCPT ); Wed, 29 Mar 2023 16:54:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08CD710FB; Wed, 29 Mar 2023 13:54:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9653F61E27; Wed, 29 Mar 2023 20:54:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB292C433D2; Wed, 29 Mar 2023 20:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680123261; bh=AbVWsfd24flX0NPK7NPatY9+8fT6TeXiEaIfWJAqTIM=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=M/MwojbQOjIFYA215EwwrbyaIYUfgtTlJvfup4puyu0OpeSoE84RHFBW4HmnMEI0t lFUexgCWABLMPBoMerI0L163fWcVNtSSkr0UJCv3OYVS0z3FPK3qeHbIwuxH616Yxs M7imhua9aINkFUuh9Nzwemsp2ELRtBrpohR+DWto+mHzJfBBh0Nr1+IZvTG91OPLuq gbG56QSj7i8lTGtLQ3k+j8djUIrN3GXhOGbIvMq2QKoDNjeVeomQgQKM8p7YsPPpBc D7RFRQAwvyNK+wC5JCAojVDqhRqsZzLZOCn0QiMJgclaKds/zGXufDwgfRBsoARlvH 7WGflIt3350JA== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 7C9FA154047D; Wed, 29 Mar 2023 13:54:20 -0700 (PDT) Date: Wed, 29 Mar 2023 13:54:20 -0700 From: "Paul E. McKenney" To: Frederic Weisbecker Cc: LKML , rcu , Uladzislau Rezki , Neeraj Upadhyay , Boqun Feng , Joel Fernandes Subject: Re: [PATCH 3/4] rcu/nocb: Recheck lazy callbacks under the ->nocb_lock from shrinker Message-ID: <8df51703-1ee4-4b7b-9e05-90b3650e8ee7@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20230329160203.191380-1-frederic@kernel.org> <20230329160203.191380-4-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230329160203.191380-4-frederic@kernel.org> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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, Mar 29, 2023 at 06:02:02PM +0200, Frederic Weisbecker wrote: > The ->lazy_len is only checked locklessly. Recheck again under the > ->nocb_lock to avoid spending more time on flushing/waking if not > necessary. The ->lazy_len can still increment concurrently (from 1 to > infinity) but under the ->nocb_lock we at least know for sure if there > are lazy callbacks at all (->lazy_len > 0). > > Signed-off-by: Frederic Weisbecker > --- > kernel/rcu/tree_nocb.h | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) > > diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h > index c321fce2af8e..dfa9c10d6727 100644 > --- a/kernel/rcu/tree_nocb.h > +++ b/kernel/rcu/tree_nocb.h > @@ -1358,12 +1358,20 @@ lazy_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) > if (!rcu_rdp_is_offloaded(rdp)) > continue; > > + if (!READ_ONCE(rdp->lazy_len)) > + continue; Do you depend on the ordering of the above read of ->lazy_len against anything in the following, aside from the re-read of ->lazy_len? (Same variable, both READ_ONCE() or stronger, so you do get that ordering.) If you do need that ordering, the above READ_ONCE() needs to instead be smp_load_acquire() or similar. If you don't need that ordering, what you have is good. > + rcu_nocb_lock_irqsave(rdp, flags); > + /* > + * Recheck under the nocb lock. Since we are not holding the bypass > + * lock we may still race with increments from the enqueuer but still > + * we know for sure if there is at least one lazy callback. > + */ > _count = READ_ONCE(rdp->lazy_len); > - > - if (_count == 0) > + if (!_count) { > + rcu_nocb_unlock_irqrestore(rdp, flags); > continue; > - > - rcu_nocb_lock_irqsave(rdp, flags); > + } > WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, jiffies, false)); > rcu_nocb_unlock_irqrestore(rdp, flags); > wake_nocb_gp(rdp, false); > -- > 2.34.1 >