Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp290812rdb; Tue, 19 Dec 2023 17:46:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZTiDiA7WviUljxkzXE0WkikD7cJzAIIkaIql8qjShDMSmwea7wU6XsJ6H+OfhFnckYS9F X-Received: by 2002:a05:6808:444b:b0:3ba:54d:415 with SMTP id ep11-20020a056808444b00b003ba054d0415mr17574866oib.50.1703036777884; Tue, 19 Dec 2023 17:46:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703036777; cv=none; d=google.com; s=arc-20160816; b=bAtt2tsVlwpwi+E8siPwTfa3ZP21FqAI+QEyF9o5CHuPxOsGKVZ7FbO3lvrN2aDcpZ pKg7N8yI1JbfiC7DQBjKm4Gi1nR8t+mgaIGiHe9nuK/06obRiqG2L1XP1iAZE9l6cq00 3RjzM+2636UHpPDSnwRwUp2DhnVQDbSddAhfliTVZX1lII6t8BMBBeuHwhBoL5r/O8yq 60SOY96pLTiBd2IDSwkGjoO+5uZoCkyollHIw6bTA+NU99Ntld9VTNGt8NFH3aXLOly5 TH89n22dZMxmZVHAmhjhurkOKUlKEzZHsogUOu83lZDg1lSkcwMKjTQ47skMsoMy+pti pFYA== ARC-Message-Signature: i=1; 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=n4W0lHem7m+opQlX6VDN/nubuyISZCFEURzU7bFQc48=; fh=785dg44DIpLZJ9M7c5EKuVY+o2EwuX9e5Yug9Fb6PIw=; b=fhwCopOsfnhAr2s2a6s0jq/O/aq0NPPqdn9woc/tzV1GX7XaZWXSBSskOn/3QjRrKz KTs7iK9ExXPUUOZb3bHGISoKuh83sM8DHMBf+/Fibet+uInbgCuIJ75DYJsew1DS6c+u 2yX2dcLwqJKWhfPYSRo9ASBOlSNWINBfgHJWTfTy8+1Ad2lpf+VWOSrbmU6o2R9y894Z iOxpkhyBXTjL5LDhMBEDyZ9UlmAhImH8+Gbqvw511SKpe/kVA80I4Sqcxphy2RxWBOdZ C3feB0Te/8MV9/SBoCrHejrFo11dwOggyIyfyFUO799OD+LesScwjebXpYHtmKq8sQ23 VM1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="KUUb2y/s"; spf=pass (google.com: domain of linux-kernel+bounces-6263-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6263-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. [139.178.88.99]) by mx.google.com with ESMTPS id j1-20020aa78dc1000000b006d894820f39si3337628pfr.39.2023.12.19.17.46.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:46:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6263-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="KUUb2y/s"; spf=pass (google.com: domain of linux-kernel+bounces-6263-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6263-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 88CEC2883F6 for ; Wed, 20 Dec 2023 01:46:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 012B710A1E; Wed, 20 Dec 2023 01:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KUUb2y/s" X-Original-To: linux-kernel@vger.kernel.org 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 304C9FBE0; Wed, 20 Dec 2023 01:46:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A49AAC433C8; Wed, 20 Dec 2023 01:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703036771; bh=G6Na+o08O7NvAM3bYJH+ZZ+NK7OTd5tAWejkpq8S3is=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=KUUb2y/sHWhFgVekG/obY+YNv4mGHuJZsQjcavJYzw+jXF1hQQBXTSB9neIlQQJy1 ny+2zguYZ3696R/65ejcOATwpMP+VglDW1pCuGf/z5YWIpISr3BRf32kJm8rjaLyxs f1bZqlNaQnrGtTnOEpCByxD7qt9DiLq3c7Jf71fFtB1Y9MJxM1xKQRKVxIAKSiZwWr Xcru5wMtEjs+Vd5j6ep1Y42PmtI9WuyHgDFJbqC/+j7rjZwaSrh8OtDDGcxQ9WV4sb cVleMWNJSFezChCOVVLmtld71r7gzh7zCR2nMtd+8OdOUdl7B11pTLXbhmDiEbQ1OE r/OIKurv/8QKA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 3B9EFCE10DA; Tue, 19 Dec 2023 17:46:11 -0800 (PST) Date: Tue, 19 Dec 2023 17:46:11 -0800 From: "Paul E. McKenney" To: "Uladzislau Rezki (Sony)" Cc: RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Oleksiy Avramchenko , Frederic Weisbecker Subject: Re: [PATCH v3 5/7] rcu: Support direct wake-up of synchronize_rcu() users Message-ID: Reply-To: paulmck@kernel.org References: <20231128080033.288050-1-urezki@gmail.com> <20231128080033.288050-6-urezki@gmail.com> 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: <20231128080033.288050-6-urezki@gmail.com> On Tue, Nov 28, 2023 at 09:00:31AM +0100, Uladzislau Rezki (Sony) wrote: > This patch introduces a small enhancement which allows to do a > direct wake-up of synchronize_rcu() callers. It occurs after a > completion of grace period, thus by the gp-kthread. > > Number of clients is limited by the hard-coded maximum allowed > threshold. The remaining part, if still exists is deferred to > a main worker. > > Signed-off-by: Uladzislau Rezki (Sony) Nice optimization! One question below. > --- > kernel/rcu/tree.c | 39 +++++++++++++++++++++++++++++++++++++-- > 1 file changed, 37 insertions(+), 2 deletions(-) > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index d7b48996825f..69663a6d5050 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -1384,6 +1384,12 @@ static void rcu_poll_gp_seq_end_unlocked(unsigned long *snap) > raw_spin_unlock_irqrestore_rcu_node(rnp, flags); > } > > +/* > + * A max threshold for synchronize_rcu() users which are > + * awaken directly by the rcu_gp_kthread(). Left part is > + * deferred to the main worker. > + */ > +#define SR_MAX_USERS_WAKE_FROM_GP 5 > #define SR_NORMAL_GP_WAIT_HEAD_MAX 5 > > struct sr_wait_node { > @@ -1617,7 +1623,8 @@ static DECLARE_WORK(sr_normal_gp_cleanup, rcu_sr_normal_gp_cleanup_work); > */ > static void rcu_sr_normal_gp_cleanup(void) > { > - struct llist_node *wait_tail; > + struct llist_node *wait_tail, *head, *rcu; > + int done = 0; > > wait_tail = sr.srs_wait_tail; > if (wait_tail == NULL) > @@ -1626,11 +1633,39 @@ static void rcu_sr_normal_gp_cleanup(void) > sr.srs_wait_tail = NULL; > ASSERT_EXCLUSIVE_WRITER(sr.srs_wait_tail); > > + WARN_ON_ONCE(!rcu_sr_is_wait_head(wait_tail)); > + head = wait_tail->next; > + > + /* > + * Process (a) and (d) cases. See an illustration. Apart of > + * that it handles the scenario when all clients are done, > + * wait-head is released if last. The worker is not kicked. > + */ > + llist_for_each_safe(rcu, head, head) { This does appear to be a clever way to save eight bytes on the stack, but is our stack space really so restricted? We are being invoked from the RCU GP kthread, which isn't using much stack, right? If so, let's spend the extra local variable and spare the reader a trip to the llist_for_each_safe() definition. > + if (rcu_sr_is_wait_head(rcu)) { > + if (!rcu->next) { > + rcu_sr_put_wait_head(rcu); > + wait_tail->next = NULL; > + } else { > + wait_tail->next = rcu; > + } > + > + break; > + } > + > + rcu_sr_normal_complete(rcu); > + // It can be last, update a next on this step. > + wait_tail->next = head; > + > + if (++done == SR_MAX_USERS_WAKE_FROM_GP) > + break; > + } > + > // concurrent sr_normal_gp_cleanup work might observe this update. > smp_store_release(&sr.srs_done_tail, wait_tail); > ASSERT_EXCLUSIVE_WRITER(sr.srs_done_tail); > > - if (wait_tail) > + if (wait_tail->next) > queue_work(system_highpri_wq, &sr_normal_gp_cleanup); > } > > -- > 2.39.2 >