Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3004068rwi; Tue, 11 Oct 2022 17:04:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5MxKrdPs4Wz1MHM34B+HBa/C6flrVJX7+0BjvekTMdf077BUR9jez7qNUcMbBhzJa6VjEV X-Received: by 2002:a63:4f15:0:b0:455:ede1:d8c9 with SMTP id d21-20020a634f15000000b00455ede1d8c9mr23387812pgb.452.1665533056891; Tue, 11 Oct 2022 17:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665533056; cv=none; d=google.com; s=arc-20160816; b=N0pteAvL3AKyjX0jGfq4efRpUfxkTczCv55iN8bBpYbURQdZlBzsGD8qSHBRvzTq7I icRSZbzVPo1WASh8YVA3UFtr3idNq7QSl9NOKaSBESghriXV2J0xmBLdElVWMdlcfaSS j7FAJip6C77AhZmWwpeSBPp2ynhqKOEGn5O8lwTX2P1hOWN55lWzkMCtzoosFIMFvXxH Emy0R4lVZyXlyyUCuemQIQsHAH+gPHDbpKBIlcz8ENAh6mudsQSkVat2aVBLHv/4uErs dQkf/4KWQ43W9PNKS37zN9pL0SiEdu5OP8yaUNpV/zZaLBjGnNk4Tyb176UX/vWcIPvv sJCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2up8oYXI/EHVFioKzFzVTYRmRHPm+gCTG27DRC/Ipq8=; b=i+/f82JxAp15162DNppIBMrw61+Ld9dglOJY7bI4rmoXxXABOc+RthwMx+Fl0YAZVS 7T27nfOxmFRvpIM/8/pzisrqK/9vj//MVaGIfgOo/ho3/8G12OhT6FvOFqOb+IjZFBKM XseCl3o2iza5+TSmhzGentQiErfsQAk3XWFLdBTFJd63wE/WQQlbzADNb/RwXEx+OiIl SNCIM/h2kDtcWxghxVSOq9f4qp242oja4Gl+Us54VbO2IEs4SRHkAPoKyTFWtp72KDL+ LN9jUyuzrMMBWp35+gh/alkEI8rGxKza44/+Us8e2PAcAIRrw8iyQdRcx7AHgSubarsO tX/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="mssK7G/q"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a056a00181500b00542be097b0dsi19849484pfa.3.2022.10.11.17.04.05; Tue, 11 Oct 2022 17:04:16 -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=@joelfernandes.org header.s=google header.b="mssK7G/q"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbiJKXr0 (ORCPT + 99 others); Tue, 11 Oct 2022 19:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbiJKXrY (ORCPT ); Tue, 11 Oct 2022 19:47:24 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A2AB12D19 for ; Tue, 11 Oct 2022 16:47:20 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id o65so12185314iof.4 for ; Tue, 11 Oct 2022 16:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2up8oYXI/EHVFioKzFzVTYRmRHPm+gCTG27DRC/Ipq8=; b=mssK7G/qevvoEJ2xSlhh0TtPZbnhwd3lNJFYSHTATmi525DN0KYOlqL+rUhyORcKil ljMjVpoWFOgAaO9Cln4LoaGzP0PqPV1+h57QXXHcqsYmR1hph5RXBylRwrwh4tyDaGNN p0qUPEUcBUPkqEuuGVwvNvO9/A8pWY3EO+P1o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2up8oYXI/EHVFioKzFzVTYRmRHPm+gCTG27DRC/Ipq8=; b=q8l+ljq+AQpbEE97xofak0fV1PMKw15pQubSff1Ulfx+sIXGkXYfvSztTOieavvBd/ L2GrObh9sjSAw7A6JLoSFahuaZZOKLVBGZZGchjrjIgW/NGrCPJnN4DiD10bv1aMGnt4 Y/wp3idTDq7p2dfcsy6uhrWsmWEj5PckNkjCu2r07plpx4gvVYYO0+mgpBYWlAIrDQiZ 1QizbiwRJNufy9VZQcvGVeC+4Ga5cDLN86adKUxdSdNd3OcNEiiqFFRGrsWVjn92McIe jf8EV3HC+sfkm9JVds+Lrp+oUo9fHdYSpXEqyyqsKw9rQzbxamUjYRM1iWA2VSnusWJN 47SQ== X-Gm-Message-State: ACrzQf09FYcAjzqcb++Y62PcMqRphCue2S88iG1z3hiyZRJtgXv/xUce xCjiRmCM9qRLIlJZ/3m3fl/x77w9pOOHqDw1CqQoel60gL4= X-Received: by 2002:a6b:3f08:0:b0:6bc:7551:69f6 with SMTP id m8-20020a6b3f08000000b006bc755169f6mr3076585ioa.156.1665532038885; Tue, 11 Oct 2022 16:47:18 -0700 (PDT) MIME-Version: 1.0 References: <20221010223956.1041247-1-frederic@kernel.org> <20221010223956.1041247-3-frederic@kernel.org> <20221011192150.GA1052160@lothringen> In-Reply-To: <20221011192150.GA1052160@lothringen> From: Joel Fernandes Date: Tue, 11 Oct 2022 19:47:07 -0400 Message-ID: Subject: Re: [PATCH 2/2] rcu/nocb: Spare bypass locking upon normal enqueue To: Frederic Weisbecker Cc: "Paul E . McKenney" , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 On Tue, Oct 11, 2022 at 3:21 PM Frederic Weisbecker wrote: > > On Tue, Oct 11, 2022 at 02:00:40AM +0000, Joel Fernandes wrote: > > On Tue, Oct 11, 2022 at 12:39:56AM +0200, Frederic Weisbecker wrote: > > > When a callback is to be enqueued to the normal queue and not the bypass > > > one, a flush to the bypass queue is always tried anyway. This attempt > > > involves locking the bypass lock unconditionally. Although it is > > > guaranteed not to be contended at this point, because only call_rcu() > > > can lock the bypass lock without holding the nocb lock, it's still not > > > free and the operation can easily be spared most of the time by just > > > checking if the bypass list is empty. The check is safe as nobody can > > > queue nor flush the bypass concurrently. > > > > > > Signed-off-by: Frederic Weisbecker > > > --- > > > kernel/rcu/tree_nocb.h | 6 ++++-- > > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > > > diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h > > > index 094fd454b6c3..30c3d473ffd8 100644 > > > --- a/kernel/rcu/tree_nocb.h > > > +++ b/kernel/rcu/tree_nocb.h > > > @@ -423,8 +423,10 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp, > > > if (*was_alldone) > > > trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, > > > TPS("FirstQ")); > > > - WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, j)); > > > - WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass)); > > > + if (rcu_cblist_n_cbs(&rdp->nocb_bypass)) { > > > + WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, j)); > > > + WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass)); > > > + } > > > return false; // Caller must enqueue the callback. > > > } > > > > Instead of this, since as you mentioned that the bypass lock is not contended > > in this path, isn't it unnecessary to even check or attempt to acquire the > > lock in call_rcu() path? So how about something like the following, or would > > this not work for some reason? > > You're right. But it's a bit error prone and it adds quite some code complication > just for a gain on a rare event (bypass is supposed to be flushed on rare > occasions by the caller). But the "checking of whether to flush" which leads to "acquiring the bypass lock first" , is not a rare event as you pointed out (can be spared most of the time as you said). The alternative I proposed removes the need for the frequent locking (which is another way of implementing what you suggested).