Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1206894rwl; Wed, 29 Mar 2023 14:25:27 -0700 (PDT) X-Google-Smtp-Source: AKy350YQae4pP8+U8jk0NIRcmdkaxM+pykGfntpNzwinOwrXB5fN5hl77dn3FjsmI+Zlebok/WcT X-Received: by 2002:a17:902:fa0e:b0:19e:e39b:6d98 with SMTP id la14-20020a170902fa0e00b0019ee39b6d98mr18590285plb.35.1680125126846; Wed, 29 Mar 2023 14:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680125126; cv=none; d=google.com; s=arc-20160816; b=ARVt5hnHQ8n5/L5pddN2BlOTz8Ji2vU39PdYr3naeQ1Lml+3sBxRdetDmFjGVcs7Qo 3zLhWO1OXhq9Hr2kz77lvcdOzRaQ89cDh0adMALkFGbqX7OCphbRaEGTSpFtPi27ud5N 2vuFkeJWwgUjgZw6sKfmceI/Mb2nShlIdbD1KxFR4AESq+/vZr6ks2kZkhHuJEafzdBJ L5hEhtKje5G6ubFysz3ymPnwhX8fXR7EUIrZ8Ox4MPELXy3a2u4ZjJBS/DBQedOpQ7xG cG1oAUAh3Y2Ls+cC/KlPZUwa8nenCdBbMQqxk3S1Qr/n97MiZG+nDyGcl2fDT9H5MvJe R3BA== 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:dkim-signature; bh=VgIOX3ArTMvlHiPZJApC9/Fr8PWJbeQh/9jzjHsrFlk=; b=zKslDL4BITmHdc0ja5I7tldA0P7zv5OBdmgN9W96qf1cbSMinTTnGpggP8cEFJAIEu s3Y0uMseLMPNErBALI7YWEVyHS+j40NjwGDpX3c6IrmS0Qmyirn5+5K//+iAk4w1xNmH HaDWH1mYzLYJU6/30WjJ+KnDh2svuIYy+t4LLIDiKvfpeya3S89hWQq085Dyzfhlf4Ph 1v8ZbvoMjZKbx/vsT6EAI53U/HZfjimN2HyEl/9cE2farV8yxp7Fh6S4YjlRPbVU6xwR WSx6Oh6gRbQ2WGqcaGsyhZJ8pc3mysInFSLOHmkDzP69x3r4KZBTw7uEjZiya38vYo1W UOCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FAb5FXto; 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 h8-20020a170902f54800b0019f239f4966si18042355plf.568.2023.03.29.14.25.08; Wed, 29 Mar 2023 14:25:26 -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=FAb5FXto; 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 S229643AbjC2VYL (ORCPT + 99 others); Wed, 29 Mar 2023 17:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjC2VYC (ORCPT ); Wed, 29 Mar 2023 17:24:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B84E768A; Wed, 29 Mar 2023 14:23:30 -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 C7A5661E4C; Wed, 29 Mar 2023 21:22:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA47FC433EF; Wed, 29 Mar 2023 21:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680124968; bh=BQEBTl7sXemlMssTlUV/AZAbpGbpWsqCBRUJdakEeN8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FAb5FXtoTcApyMuwm4dPst2MLgRDCinX4ahQVoFRA3pUPBjHgw3XnquAuICIoc+OP +6tG6uvJ+f6CwIsn8HRjnO/G9f9aiob2twzKgCBe7fTiDNJOoDOeD0vSErFdsAgD8I yZ7wamVfA19W9XtbM6s8U5X0tkOUp8y4BRER/iMDQYSLt98ZOh4hA1fn+DEZHWl2CV 0achyBigD3KdyOZ8h5e66M902Jc1gr2OhuDepLXELHoyN2AbAW0ZT6jt/vRNsys0tm 4SaFHjE4VL9+9+lZQydpmgpc8tAJWqNWDgUGmUAhp+xalQDpQNpgXh7UiyNzpT01lS 4fE8qfdnroPGQ== Date: Wed, 29 Mar 2023 23:22:45 +0200 From: Frederic Weisbecker To: "Paul E. McKenney" 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: References: <20230329160203.191380-1-frederic@kernel.org> <20230329160203.191380-4-frederic@kernel.org> <8df51703-1ee4-4b7b-9e05-90b3650e8ee7@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8df51703-1ee4-4b7b-9e05-90b3650e8ee7@paulmck-laptop> X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,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 01:54:20PM -0700, Paul E. McKenney wrote: > 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. No ordering dependency intended here. The early ->lazy_len read is really just an optimization here to avoid locking if it *seems* there is nothing to do with this rdp. But what follows doesn't depend on that read. Thanks.