Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1453175pxb; Tue, 26 Oct 2021 09:15:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbk48+5z+gU1d9ffDDQL2XmKNPggDUfmjUxJnmSCqgdWt+7qoL2c1y3Bc0ySgteaLROnd+ X-Received: by 2002:a17:907:3d8b:: with SMTP id he11mr31313618ejc.100.1635264942290; Tue, 26 Oct 2021 09:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635264942; cv=none; d=google.com; s=arc-20160816; b=busGT72Dwd6YgHNzKoD3JRlvuHfbnovG7PZ3HdDhUyTbaLek1ctyEpynYzC7kov1Yd Ox0boHILQwPmdbYwFPc5V6x0AOgzdEDjuLXpn85CczthPO3R28liS/fs3i/ioloIb5yt 8P9PwypLOvthS+0LFMwfZuNU0KD4DFO5LmGE60iaspV3RWTPUwqIYxMn7FdfH5dmjXZD /80hs1QZOy7XZTA48VWfdFL4K4XSlwMrXqsl8vgAVdsNOWOEJ8sH9nitfRSmA5Rm3vmg LSrC6HSUHJi+25W6DM7lKCKdjk+ZZxWGIDVMMwyJCP2cvP+196Dgl6jG0e4Nidr/WrPF 6T8Q== 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=V+t8Uh427gXOwBLEDrEt+gH2ARCwSbvbPoEeeptk2yo=; b=E7Pgsg+GaLsEXbu0290HpFiTIfcGkRZ2erCC0Zr7j33YaEYJTJ+Cpl3LA/v5nVEWk3 VpLFGD6AzLf4f/vjZJtyGco5cm25VU8Hh0CTtls2d8mfGs0q4IBua4j31TUUz57H20yJ Px0bIFk8Uxd05FXSU2IVxxoT2bcoSOkWWDpMS+i9bW8Aj1B6sjZV8x5ZM4acB9KORRPc eWZHFMEOebqgKQw++WTn72SQHwjlIxkAKpKTulzI5u/qiAntcpazxVOqZyCscqMOGPnu 2etsDYKq/4Ljf0osrbBWWXSKbDG1um4zbFiv0oGooDxYtDs2cHwuh5QDBKKsG6ElA41h f+2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@forshee.me header.s=google header.b=eNy9xO6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fy17si1480692ejc.207.2021.10.26.09.15.15; Tue, 26 Oct 2021 09:15:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@forshee.me header.s=google header.b=eNy9xO6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231560AbhJZMaI (ORCPT + 99 others); Tue, 26 Oct 2021 08:30:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231570AbhJZMaH (ORCPT ); Tue, 26 Oct 2021 08:30:07 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B669C061767 for ; Tue, 26 Oct 2021 05:27:44 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id n67so986638iod.9 for ; Tue, 26 Oct 2021 05:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=forshee.me; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=V+t8Uh427gXOwBLEDrEt+gH2ARCwSbvbPoEeeptk2yo=; b=eNy9xO6KA1OgHa5Ht2c1KSa5vPFfwYaNhksbiRtYrOw+PwQ5PID0vjiuNkhuIfuVLh cPXX+BXnCxHsvg521P+x0WiIx1Bi2MTmafO9/zZBLwUOZvPzGgh9eiDo4F6UrJthVbV1 ILToS25sji6o1gU3GqgtSJyPc1OPB+rLLOmExy5HsQga2bA1kIo8q9eakPcjTYEF7U1z l+kNWPEtfkaMxxx32CO89vjRfMl2lDTujiKr1MBOWVpNCYytbzeRHbtRSQ1Ab9eTYUGe KGyG6xsAP35lePhAnyfp/L6Yj+AVk+pKQDkbC58tuRJO6ei8NE/qZEbw6FpgActzfmwU B7wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=V+t8Uh427gXOwBLEDrEt+gH2ARCwSbvbPoEeeptk2yo=; b=UE8b8qZLAAp/2gg5u0+IockXuuV/KQMlNf6e14B++sTGsaBzlM7EiTo+wxgO0HtBhm /AzXt3LociOTjsrpUauZt6odjLRxZQWYOH11lbPOf5GSyTMr81F+uC/JgDxDbrMuS2SX 4I7k2509+7XMbw4+p1vRMu0+GaEQOUobOsCH6Z/2ydpCqKAEXtjmCdic85kA7q1hDsLA nGOCZiW0hX/VUQ+zEqGAjAhQGlNB0YnziSGFpwtJhrGUCCQKMDUjF3LfYjJPb9riiJBX PU/vC+JhBncE8yu+JEdhu18Z5YylahfGnmRKCmDiYE6oZSiXY85UzFPtvOoL4KBiJrGn a8uw== X-Gm-Message-State: AOAM5313P//tZGV71rdAH7kmFW5PyJFN3q9qNcwaC8adxGOeQpECMzUM 0mjZAUgpQKBDRdyI5WVnQARoDNJERegMudCgpHA= X-Received: by 2002:a02:5409:: with SMTP id t9mr7620884jaa.43.1635251263393; Tue, 26 Oct 2021 05:27:43 -0700 (PDT) Received: from localhost ([2605:a601:ac0f:820:fca3:95d3:b064:21ae]) by smtp.gmail.com with ESMTPSA id t2sm5770986ilg.1.2021.10.26.05.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 05:27:42 -0700 (PDT) Date: Tue, 26 Oct 2021 07:27:42 -0500 From: Seth Forshee To: Jakub Kicinski Cc: "David S. Miller" , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "Paul E. McKenney" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: sch: eliminate unnecessary RCU waits in mini_qdisc_pair_swap() Message-ID: References: <20211022161747.81609-1-seth@forshee.me> <20211025124828.1e4900e3@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211025124828.1e4900e3@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 25, 2021 at 12:48:28PM -0700, Jakub Kicinski wrote: > On Fri, 22 Oct 2021 11:17:46 -0500 Seth Forshee wrote: > > From: Seth Forshee > > > > Currently rcu_barrier() is used to ensure that no readers of the > > inactive mini_Qdisc buffer remain before it is reused. This waits for > > any pending RCU callbacks to complete, when all that is actually > > required is to wait for one RCU grace period to elapse after the buffer > > was made inactive. This means that using rcu_barrier() may result in > > unnecessary waits. > > > > To improve this, store the current RCU state when a buffer is made > > inactive and use poll_state_synchronize_rcu() to check whether a full > > grace period has elapsed before reusing it. If a full grace period has > > not elapsed, wait for a grace period to elapse, and in the non-RT case > > use synchronize_rcu_expedited() to hasten it. > > > > Since this approach eliminates the RCU callback it is no longer > > necessary to synchronize_rcu() in the tp_head==NULL case. However, the > > RCU state should still be saved for the previously active buffer. > > > > Before this change I would typically see mini_qdisc_pair_swap() take > > tens of milliseconds to complete. After this change it typcially > > finishes in less than 1 ms, and often it takes just a few microseconds. > > > > Thanks to Paul for walking me through the options for improving this. > > > > Cc: "Paul E. McKenney" > > Signed-off-by: Seth Forshee > > LGTM, but please rebase and retest on top of latest net-next. Will do. > > void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp, > > struct tcf_proto *tp_head) > > { > > @@ -1423,28 +1419,30 @@ void mini_qdisc_pair_swap(struct mini_Qdisc_pair *miniqp, > > > > if (!tp_head) { > > RCU_INIT_POINTER(*miniqp->p_miniq, NULL); > > - /* Wait for flying RCU callback before it is freed. */ > > - rcu_barrier(); > > - return; > > - } > > + } else { > > + miniq = !miniq_old || miniq_old == &miniqp->miniq2 ? > > + &miniqp->miniq1 : &miniqp->miniq2; > > > > - miniq = !miniq_old || miniq_old == &miniqp->miniq2 ? > > - &miniqp->miniq1 : &miniqp->miniq2; > > nit: any reason this doesn't read: > > miniq = miniq_old != &miniqp->miniq1 ? > &miniqp->miniq1 : &miniqp->miniq2; > > Surely it's not equal to miniq1 or miniq2 if it's NULL. I agree, that looks simpler and functionally equivalent. It seems off-topic for this patch though; I'm only touching that line to change the indentation. Thanks, Seth