Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp756701ybz; Wed, 15 Apr 2020 18:16:39 -0700 (PDT) X-Google-Smtp-Source: APiQypIshiYOy9IJM1GW4tbKuZ/sn5AKRRU5G2hZQlYr3XoL+RyzYbFhsgkj9IchqgLFub08pKNn X-Received: by 2002:a17:906:1352:: with SMTP id x18mr7864418ejb.138.1586999799022; Wed, 15 Apr 2020 18:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586999799; cv=none; d=google.com; s=arc-20160816; b=szQZ/qlEA09+r8BhgkkJacqV4jqpUrZyonMVkTilXVVtOaKAaDRS9uMASjfoqM8e+a 4BQFqq6EjHQ/C2zsFkelEyAsWzeyiI/AP1o/LFe0GGvjRZCkY/qkR7wUY+vYHWqY9Uzi /2hCgmNkzPzv8Gt4kiAWMCevLpNSj0Bf3Y3fxwn6kSIRV8vXBIe+5rO209xzXCEMZKil woQPwAaX5IrnOg8tO2kS6epj8ViAAVjEnSclVHYMaffJS54p9Y8A2D+FNUHYadLK5P25 Wp0y1DI55m3nLe/j6ghn4FOlycKyjjN9PfO5bBmItChKZzn3nsmAW4HiVXqeU5meS9UN JUSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=yHLgIKekTjFlAsFOBjR3USRudL9r3TLtuyxf4mY9+Ug=; b=IX3Wh6KR098U1eR1IuR1WkTAn1G8k1zNVEI3N6oOWqHO5GlcesX8FJqfy0II0Rk8jn 6hGZFW33mp0pK+KHR7OHFFwzB69lKVFiHs5xJWpNWv7YD3HP8r2nj9LA8XYuo614zAXu L1+x1yQLwPFwo5WctyS/+J3TGJ8z1NOKljLEhgStDIDzkpa78wsmE9adh5ndj1usagHF h96DHoCu8P2pVaobOle8NVPVo/k8LXXdfVSEGIZYVT/Y0CuIYDi2IB3MN5smziJs5SQh RCRkhs3hx5KfpRLJTI3mclBvUWux1cw94pZ4NU4uJdJ3TKlAYrSBOoQ2eVoy5DjgClvw p3CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kNauBICb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si11886107edp.213.2020.04.15.18.16.16; Wed, 15 Apr 2020 18:16:39 -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=@kernel.org header.s=default header.b=kNauBICb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391586AbgDPAYE (ORCPT + 99 others); Wed, 15 Apr 2020 20:24:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:35784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729384AbgDPAYB (ORCPT ); Wed, 15 Apr 2020 20:24:01 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2938F20936; Thu, 16 Apr 2020 00:24:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586996641; bh=FCPe1gayukNxr6qjvG7Hl461TNHn+GLs5pWruehW7UA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=kNauBICbBFUNAiQ/ThXe/hN2YgD9t/61tLxnOUklq/4ZPOCM+JFOwv2aPx8YYCU1L eP/ck+uTpuqcdfv59OD6IBTrFqT9/hhWMIJxwGrA7KgRdXvkUcyWmlbtEhzBmXnMOV 0KnO9WMXMXylJ8YtoSIsns10BM+RcXHcG+N1MPPQ= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id EFE403522AD1; Wed, 15 Apr 2020 17:24:00 -0700 (PDT) Date: Wed, 15 Apr 2020 17:24:00 -0700 From: "Paul E. McKenney" To: Wei Yang Cc: josh@joshtriplett.org, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rcu: init and destroy rcu_synchronize when necessary Message-ID: <20200416002400.GL17661@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200415222655.9006-1-richard.weiyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200415222655.9006-1-richard.weiyang@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 15, 2020 at 10:26:55PM +0000, Wei Yang wrote: > We would skip the rcu_synchronize if it is a duplicate call back function. > > This is not necessary to init and destroy for them. > > Signed-off-by: Wei Yang Applied, thank you! I edited the commit log a bit. Could you please check below to make sure that I didn't mess anything up? Thanx, Paul ------------------------------------------------------------------------ commit d9eaddf545fe8e3e2725e2fa0bf87b59b5667c14 Author: Wei Yang Date: Wed Apr 15 22:26:55 2020 +0000 rcu: Initialize and destroy rcu_synchronize only when necessary The __wait_rcu_gp() function unconditionally initializes and cleans up each element of rs_array[], whether used or not. This is slightly wasteful and rather confusing, so this commit skips both initialization and cleanup for duplicate callback functions. Signed-off-by: Wei Yang Signed-off-by: Paul E. McKenney diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c index 3ce63a9..351c322 100644 --- a/kernel/rcu/update.c +++ b/kernel/rcu/update.c @@ -391,13 +391,14 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array, might_sleep(); continue; } - init_rcu_head_on_stack(&rs_array[i].head); - init_completion(&rs_array[i].completion); for (j = 0; j < i; j++) if (crcu_array[j] == crcu_array[i]) break; - if (j == i) + if (j == i) { + init_rcu_head_on_stack(&rs_array[i].head); + init_completion(&rs_array[i].completion); (crcu_array[i])(&rs_array[i].head, wakeme_after_rcu); + } } /* Wait for all callbacks to be invoked. */ @@ -408,9 +409,10 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array, for (j = 0; j < i; j++) if (crcu_array[j] == crcu_array[i]) break; - if (j == i) + if (j == i) { wait_for_completion(&rs_array[i].completion); - destroy_rcu_head_on_stack(&rs_array[i].head); + destroy_rcu_head_on_stack(&rs_array[i].head); + } } } EXPORT_SYMBOL_GPL(__wait_rcu_gp);