Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp838821rwl; Wed, 29 Mar 2023 09:06:14 -0700 (PDT) X-Google-Smtp-Source: AKy350bkuhFwf9Q5eaoZ3b7nmIlxi/CIuU59A7DTAxnlFf74EMh2hl7CwMnQIpQt4kosFojZ98nM X-Received: by 2002:a17:903:2844:b0:19e:73a9:c21b with SMTP id kq4-20020a170903284400b0019e73a9c21bmr17015299plb.45.1680105973904; Wed, 29 Mar 2023 09:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680105973; cv=none; d=google.com; s=arc-20160816; b=zdjy0ScdCtWzm1h8usTPnqW+agvSFlgSXG63btnx6+BEirKBCW0VXIyAO4yeg7JcIP DZjleMDBN2tgVFcdp4uwQa12YbJhpOUFOg8jkXazAbpgD/uGpCq7U2NWbx8sRl769wDw gNt0U6kp17bFVq7J2Ee9q2UG7ookkF+LRdhiLSkxn7q6f/PQPiY0T1711CnMRMqa6xQJ hKcRhGREa5dH+wkK6qJU9VtwLCSYpF5jMYWlPwhIgIOkFTxBqgz9wsD9tyceQPaog5Ct +NgZAj+l6HRdo0brGnmDIb1oA74l8dU21y0I6GXYBa8ZUHENLXJbZsA5NCdBxrxcomVw XzBA== 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=pxRhWFyb27BvogwhMK7gi/x5UwosXX92hs5VIGhZfD0=; b=FK+7Ddt/8+lPBCxqF/JcD8YOz/tpf2Ft8cLiDsHfJUcHipMHK3by/QLcW65yg14wlb iXaHM26n9SIHxmw+LaMtX1b6Vu8Z/n7X1xn0KC2AP8kheJTt4xCJEvBdbS/i8q5VESZP FCoFAftEZtM/euoL9kzhX7zsikphNmrFQ3WZZ0CeqaRI9FlMgs6LQCDS1j/g8pMARxmg C0KqP8dt2ygvjAsljdkCXTjAv0kwAIPjlGKYO6SEKXAlYgYifgDmDm8vubv1/BSBhXVM RjcrW5+1NnO8TyP5L4gGWiAZOH8xPusn3yvo4CiCSiBOEsFY+qmXYlSNUVQV+wPsg4x9 J7zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=We6Sppzs; 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 u13-20020a17090341cd00b0019cb3c948d5si21887805ple.540.2023.03.29.09.05.58; Wed, 29 Mar 2023 09:06:13 -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=We6Sppzs; 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 S230074AbjC2QEy (ORCPT + 99 others); Wed, 29 Mar 2023 12:04:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231582AbjC2QEU (ORCPT ); Wed, 29 Mar 2023 12:04:20 -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 AF252558E; Wed, 29 Mar 2023 09:03:10 -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 3F88461DAA; Wed, 29 Mar 2023 16:02:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFC75C4339C; Wed, 29 Mar 2023 16:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680105735; bh=+h4XK6+UI6FKKHszmm1wj9jmGuHr+bG0mxcM6PK0eo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=We6SppzsOzlK2//1daxu59Df7ANxDJyMznwP+OkNrFmQmFcLdYSH8atr1ezJd2MQj WGhWJt5bkH3VrhROVfbJh02EKGkS4HvFe7yGH7qz1L3O1hPSNGdLY0xegZuyYPbhO4 HFJ39S8in9KjgKsomrNfCm6kkGsr3ndqR6XGOtnZzBDu5NF8SysXHICJOoLTeTUZlf t8uQZIL7RyPCnaGpbfjU1TLNYO2Hj0+jgz4c93W2sJu3rtVZTMLioZzU+iPZjGmRfC D6tzE56MJESRUNbCdPEERhTIsa0krSKTMJRV4SDPnbDJ+cY+nwa+73GhrVeGcZadG2 6mVRYA++CYdug== From: Frederic Weisbecker To: "Paul E . McKenney" Cc: LKML , Frederic Weisbecker , rcu , Uladzislau Rezki , Neeraj Upadhyay , Boqun Feng , Joel Fernandes Subject: [PATCH 3/4] rcu/nocb: Recheck lazy callbacks under the ->nocb_lock from shrinker Date: Wed, 29 Mar 2023 18:02:02 +0200 Message-Id: <20230329160203.191380-4-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230329160203.191380-1-frederic@kernel.org> References: <20230329160203.191380-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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; + + 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