Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp132052lqp; Wed, 20 Mar 2024 16:26:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXr7On5ZCrQnBN9HzzM1/kEsRtxHKOpGxfa8JUAR+R2D1WQWfll70I2ppOWMBOnq4cQMweh5StauQ6hhh734bWC46bz39EW74LX/eWd2w== X-Google-Smtp-Source: AGHT+IEvdaVn4XZbV8w810HIV7n2SKKvg6TdOE+W0v4WK2LZ5ocGsOYrLIHM4L1k5sFNjTKro26S X-Received: by 2002:a17:902:bb17:b0:1dd:bc27:a09 with SMTP id im23-20020a170902bb1700b001ddbc270a09mr19616242plb.45.1710977196947; Wed, 20 Mar 2024 16:26:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710977196; cv=pass; d=google.com; s=arc-20160816; b=A2mpWAsAnWV8YZJKSnhahRANgTSi/OlSEPGUU8DrQSMCB+zc1w/6FfS3Ph+7dwtqzG vxaLAdAgZF+z3s9IlS8i3h6bE/ldYdjFD4bobmcpEp5eMHQFy5O5UAcr5cnfsOPT5wNR KdI3quC0epg4T0bW3Ak8bgSTGiet3dzxwDPN59HdfInAP3a3LKCrffoZCmoOuMej2lbA JIgHAamtM5YrFgovKcb1JoGn2WJ0HbP9EXtJUJMdLNjaVUf6XRZji1FsH7Bt6IoqtdFr 0RhRUE5EpJcX4TakYpYyHoyjv6xj2cCVaJ/hQQPRmZeqJISOwAbMpMlVCLyCpQ6ZwO92 t5BA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=yLE+beED2HA6g0S8oJ3eDwt/uXzIPkM3etGpO9ljKPw=; fh=q+tREEV+KRScGq0wmY1isqPNPu77hPHtm9WN6WyEJD4=; b=mT4xMj2fSP/3OZRHzmytwLIo4Pu4giI5xpq0ZEQDvBHlIbBQQj20twzpgPnpsVXsYM wlqTk8FgidUFdszTlAM2QhmxJZCGoNYAAiXo3F28G06cT+wQ0GOMZW4kVHdlEyDeNzv1 xyN81YaW4f81DCJk/5SSLx+HHSeVVWDzy4hUwhqGwVD2/bgU/X7lfMWfX6xH3JtfojiZ iZ2rEbPmWQc9SBO2ioJQ1ug5FBIwZSoNl+T+KEBLyuWtoN8y2udc/k24QKtp1FkZV0DI ocCqBZYgMTfOcDUaOGI0S26RB45hnfjVAlffbRe3nMAKe3/3PPH2nvj4G3TU66WRt/of LbCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hStn0eeB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-109487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lw14-20020a1709032ace00b001e021f7cb1fsi7820190plb.525.2024.03.20.16.26.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 16:26:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hStn0eeB; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-109487-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109487-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A17672842EF for ; Wed, 20 Mar 2024 23:26:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F8438613E; Wed, 20 Mar 2024 23:26:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hStn0eeB" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60F9D85C7B; Wed, 20 Mar 2024 23:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710977189; cv=none; b=LMfYXKi0Ll/OKR1XmUOJ5zjxLMcV7jPSOV2QGB8dW/3LaBG3K3+ergP24yao7vz5SS6KzrPZO0ZFd+xYEvsvF+a3VXt/rF5JQYaaJym1jecOH8CQDqUUgUDBWie6UQJHXN2OSZk3u65ydRO/NLC2y1K56k/UBisu7U+Ta5jqIyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710977189; c=relaxed/simple; bh=HUiXtmZVmWbudl79yLaJO/xtAU7ZNwqJ4U3OHT2U+E4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hPRUZvgKllXZozSmr6/4qxiDjko/iGdMaXYWtkNfjOEouvg0iBjpxXNlvoKlwtGyM+irVhN+Ji/RkekxzmxG1i4tOVCf1hjf4kTvGmB5/jqgh3aplmZKW5DFHtJxdbOiDMGbt+LShCDL+W/dDTHNNJqZDThyj6Eq4bJfs8bxh68= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hStn0eeB; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F913C433C7; Wed, 20 Mar 2024 23:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710977188; bh=HUiXtmZVmWbudl79yLaJO/xtAU7ZNwqJ4U3OHT2U+E4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=hStn0eeBLLoNRVpporeWB7R1CAVklf7oicZcI2l3m5gV/IlJWwzAq3/bkLj29FpEe WHH+3vZ9ZqmCWlIHq2Xuc3qxoLQrHZDsTPzM306SPp6DVYNQtKEe4dwhW32iH73dqZ MAMI8Keeh3g6JGQJaQuDurkoWUfsVBYuHOtLG3hB+Tx0wb3dWkAb6w7YLPBKyHUUW2 WWnMXIiN0l5pg1Plh7kVrkl0QREpcbNcVNGdQUZa2zWzsll2KY7M0nvEJG1h+OV7YY UwZdwsyMMxuIxSp8dlqw+IQYo4klHbswhWU9nLK9ePyYP0n2Lx1sgCMeRRNgXEBTVV UvFUfCKWI/sXw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id E4095CE0716; Wed, 20 Mar 2024 16:26:26 -0700 (PDT) Date: Wed, 20 Mar 2024 16:26:26 -0700 From: "Paul E. McKenney" To: Uladzislau Rezki Cc: "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , neeraj.iitr10@gmail.com, rcu@vger.kernel.org Subject: Re: [PATCH v4] rcu/tree: Reduce wake up for synchronize_rcu() common case Message-ID: <2868ad8a-78b7-484a-a48d-c6fcbe1d6881@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20240319185458.3968308-1-joel@joelfernandes.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Mar 20, 2024 at 03:36:13PM +0100, Uladzislau Rezki wrote: > On Tue, Mar 19, 2024 at 02:54:57PM -0400, Joel Fernandes (Google) wrote: > > In the synchronize_rcu() common case, we will have less than > > SR_MAX_USERS_WAKE_FROM_GP number of users per GP. Waking up the kworker > > is pointless just to free the last injected wait head since at that point, > > all the users have already been awakened. > > > > Introduce a new counter to track this and prevent the wakeup in the > > common case. > > > > Signed-off-by: Joel Fernandes (Google) > > --- > > v1->v2: Rebase on paul/dev > > v2->v3: Additional optimization for wait_tail->next == NULL case. > > v3->v4: Apply clean ups from Vlad. Tested rcutorture all scenarios. > > --- > > kernel/rcu/tree.c | 35 ++++++++++++++++++++++++++++++----- > > kernel/rcu/tree.h | 1 + > > 2 files changed, 31 insertions(+), 5 deletions(-) > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > index 9fbb5ab57c84..f3193670fe42 100644 > > --- a/kernel/rcu/tree.c > > +++ b/kernel/rcu/tree.c > > @@ -96,6 +96,7 @@ static struct rcu_state rcu_state = { > > .ofl_lock = __ARCH_SPIN_LOCK_UNLOCKED, > > .srs_cleanup_work = __WORK_INITIALIZER(rcu_state.srs_cleanup_work, > > rcu_sr_normal_gp_cleanup_work), > > + .srs_cleanups_pending = ATOMIC_INIT(0), > > }; > > > > /* Dump rcu_node combining tree at boot to verify correct setup. */ > > @@ -1642,8 +1643,11 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) > > * the done tail list manipulations are protected here. > > */ > > done = smp_load_acquire(&rcu_state.srs_done_tail); > > - if (!done) > > + if (!done) { > > + /* See comments below. */ > > + atomic_dec_return_release(&rcu_state.srs_cleanups_pending); > > return; > > + } > > > > WARN_ON_ONCE(!rcu_sr_is_wait_head(done)); > > head = done->next; > > @@ -1666,6 +1670,9 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) > > > > rcu_sr_put_wait_head(rcu); > > } > > + > > + /* Order list manipulations with atomic access. */ > > + atomic_dec_return_release(&rcu_state.srs_cleanups_pending); > > } > > > > /* > > @@ -1673,7 +1680,7 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) > > */ > > static void rcu_sr_normal_gp_cleanup(void) > > { > > - struct llist_node *wait_tail, *next, *rcu; > > + struct llist_node *wait_tail, *next = NULL, *rcu = NULL; > > int done = 0; > > > > wait_tail = rcu_state.srs_wait_tail; > > @@ -1699,16 +1706,34 @@ static void rcu_sr_normal_gp_cleanup(void) > > break; > > } > > > > - // concurrent sr_normal_gp_cleanup work might observe this update. > > - smp_store_release(&rcu_state.srs_done_tail, wait_tail); > > + /* > > + * Fast path, no more users to process except putting the second last > > + * wait head if no inflight-workers. If there are in-flight workers, > > + * they will remove the last wait head. > > + * > > + * Note that the ACQUIRE orders atomic access with list manipulation. > > + */ > > + if (wait_tail->next && wait_tail->next->next == NULL && > > + rcu_sr_is_wait_head(wait_tail->next) && > > + !atomic_read_acquire(&rcu_state.srs_cleanups_pending)) { > > + rcu_sr_put_wait_head(wait_tail->next); > > + wait_tail->next = NULL; > > + } > > + > > + /* Concurrent sr_normal_gp_cleanup work might observe this update. */ > > ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_done_tail); > > + smp_store_release(&rcu_state.srs_done_tail, wait_tail); > > > > /* > > * We schedule a work in order to perform a final processing > > * of outstanding users(if still left) and releasing wait-heads > > * added by rcu_sr_normal_gp_init() call. > > */ > > - queue_work(sync_wq, &rcu_state.srs_cleanup_work); > > + if (wait_tail->next) { > > + atomic_inc(&rcu_state.srs_cleanups_pending); > > + if (!queue_work(sync_wq, &rcu_state.srs_cleanup_work)) > > + atomic_dec(&rcu_state.srs_cleanups_pending); > > + } > > } > > > > /* > > diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h > > index bae7925c497f..affcb92a358c 100644 > > --- a/kernel/rcu/tree.h > > +++ b/kernel/rcu/tree.h > > @@ -420,6 +420,7 @@ struct rcu_state { > > struct llist_node *srs_done_tail; /* ready for GP users. */ > > struct sr_wait_node srs_wait_nodes[SR_NORMAL_GP_WAIT_HEAD_MAX]; > > struct work_struct srs_cleanup_work; > > + atomic_t srs_cleanups_pending; /* srs inflight worker cleanups. */ > > }; > > > > /* Values for rcu_state structure's gp_flags field. */ > > -- > > 2.34.1 > > > Reviewed-by: Uladzislau Rezki (Sony) Queued and pushed, thank you both! Thanx, Paul