Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7636110rwr; Wed, 10 May 2023 10:32:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71L3FKKPKxXG4Xof0WD4sUM7NlgCBXJoWGI5G8wLVht8BS6azzaSOXnujSvLcWF4CZeQ6v X-Received: by 2002:a05:6a21:3399:b0:ff:8d85:9f24 with SMTP id yy25-20020a056a21339900b000ff8d859f24mr19238911pzb.50.1683739924797; Wed, 10 May 2023 10:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683739924; cv=none; d=google.com; s=arc-20160816; b=CZH2kHGw0zOrrlWuLT1AQD+8IPeX6gHcuuQkuKw3oHjTiAKzvjQKMpOo6Ni0ZJnFz+ aXVghiffkSYvzJKZMHGYlkOiFxgpO+lyWhN2UGY0qOGiuyDNzi1D5T5RSyTJHVep1Hk+ Roy2Bhx88qFVfbUYOU20on33xXjfsMznnbgGs32DRo6bZ9lAztsx89ZXH7ogq7Y3rxMA EAdHftevVERTXzORVuLYzh3MtEMPXE8B4QBZqF8BD/VfHBUUc1IB6kmu0t8PqfiSaC96 hhaPeH7UMtMX+icNM4WZiN7nWHJ8FbsRvk9kG4HtZJC4ddgEw7OttpxV/rCCqArIX66g FlRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MU2530c1n+erBl2mX1Ca/bGSXIDN9C4I3A5IBwZtZeo=; b=0a+IV9wkvDVGip++enHqDzYn8e3SAjFBpUt90a5oXtQ7oNt0DL6w2cRcTeKnWwEuZA XXDYqAskDxQIvXBGVKcITsuIfUZOlACPwhm5kCDwAJhYpPNOU5abJZ8SSPFpirG0yDWQ vFDKqjftBmCIv3oICq5pFQfwr5Qb5Wm7Awu/FyZAWP2h+fr5zBQinSmOEEwhKcbMTdZ0 PDBlpyJg93oHev66VA5Fs7bZLFzQZV12gUWBJcyQ+xn6NVu3CWWY1TMPrK1w+RIxDJDa 3hsIh7s9MH3cy+h7jdBke3MD/I7I4OPx5eNbWD5/U8c/TUpWZS3+uZTlP5uLVShE45XE a2Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Zb5FyCgF; 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 h187-20020a6253c4000000b006489d6fa83fsi1222898pfb.142.2023.05.10.10.31.44; Wed, 10 May 2023 10:32:04 -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=Zb5FyCgF; 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 S236402AbjEJRGf (ORCPT + 99 others); Wed, 10 May 2023 13:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236114AbjEJRGX (ORCPT ); Wed, 10 May 2023 13:06:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF96840DC; Wed, 10 May 2023 10:06:11 -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 3B1D963F38; Wed, 10 May 2023 17:06:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9803CC4339C; Wed, 10 May 2023 17:06:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683738370; bh=H90atByaaZG57Ja5si+08MrZWAJclHUD/Fm7cc4BBy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zb5FyCgFyVq9kEZcciczkbQBiJssX9KxpfXgBdP7Op/QoO5qstS/dC0UqXuOLZHB5 Q2cmdAtVzBAV29p+W15urN4LldqNFusI3zwWFg2ZSsuRkrqjIpn4K5nMUpobeldqQ+ hsTmP1GiQKHjCWnmgHSXuTm5ikzekrNyBtDvlo8FlfmdpUQZh+fMS8kaw+GZ3ccx5C QDmGfsJvStbf8ONS6KNNdOmMbhqsfMBvvJRjT6oU2d7v/+Fv0qlZbiyR2WgneJRrPf PMxcff/79aG4EXbUpvTbIra9xrpDZFKhQGbhYl6oPh7eGiHmHmKT+sOL9sdUwq8qHm c3sHKU5324qZQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 32131CE127F; Wed, 10 May 2023 10:06:10 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Frederic Weisbecker , "Paul E . McKenney" Subject: [PATCH rcu 3/4] rcu/nocb: Recheck lazy callbacks under the ->nocb_lock from shrinker Date: Wed, 10 May 2023 10:06:06 -0700 Message-Id: <20230510170607.2187978-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <9c5fae22-e25e-4548-b6e9-117495b29e62@paulmck-laptop> References: <9c5fae22-e25e-4548-b6e9-117495b29e62@paulmck-laptop> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Frederic Weisbecker 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 Signed-off-by: Paul E. McKenney --- kernel/rcu/tree_nocb.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 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; - _count = READ_ONCE(rdp->lazy_len); - - if (_count == 0) + if (!READ_ONCE(rdp->lazy_len)) continue; 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) { + rcu_nocb_unlock_irqrestore(rdp, flags); + continue; + } WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, jiffies, false)); rcu_nocb_unlock_irqrestore(rdp, flags); wake_nocb_gp(rdp, false); -- 2.40.1