Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp291228lqp; Thu, 4 Apr 2024 13:19:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzJ0u0fgb15hkETLpSB6AI0DnKOL2+IktnAxeo5kvoAhzkr4Rbg66diDsYm2RA7IigdM9ga8DDv71W2RiKna3KNo/fp3jET7PR5PP/BA== X-Google-Smtp-Source: AGHT+IHAo3aTqFTZuFc3U9pBXTVsiU8JpB3X1cqYoZYZU5Y4AIKxY0HjZ2gcK3+C1fdCZpiFsrwm X-Received: by 2002:a05:6808:2193:b0:3c3:d50d:cac2 with SMTP id be19-20020a056808219300b003c3d50dcac2mr3941543oib.49.1712261966505; Thu, 04 Apr 2024 13:19:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712261966; cv=pass; d=google.com; s=arc-20160816; b=t6o1SnZTFA9MyeMBHUoJIPEMgob3aipYsHvR/yi5xUU84E0yn0jJiEOlF3VsCMa4Jm NkPHyjZo7Br0dd+tDgYkZx5NigCpmlctuLt8bgFZQtPsL2ruA6aBsz0pSwo56046Bjo7 pqEHLd2d95ya2LE7H77K5rGseHo8svA7M6fwA+7ZMYSVh+3fm1lOnU+i2DhYvkABtO36 kmEfPSs6NzWbh4kGYDkps8+aezOovTrpuKzUP6RoDwPjoH60IwOiGdScfK70huTEsACQ bUyDJM1DPkxXQLM4DWZDpuE2Y2Z3AHb+HEt+XvQB4wi19thn/0Uh/WviFroh9vep+uXZ fxlA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=b5bpATQzLb/JeY4x1+qJv9k+2eodGRndOBIH49EHmx8=; fh=VpHBcKHofi4qxr3uw1p+RyV3ATAuh04BtL6NFqhNNtQ=; b=xTj/92JxlVnLtePrYAcu1TLzQieY5AkeHFb8RE9dx7yXnbDFSsgF2S/Q+uUWBdKgIU Y+g552dkYVhvwEbeNcdg6x7/z2QxTXaC8mIIO4ej16JWjcd3lGvdHDH3pi8pQ9mYJ7TY BRF/S5rMjgpF3aTx1KyMqWJET2BnqAaSX7HjACPMZSG8MCWnsIJcj/51OFhak2yfTNiZ Oc68FR3q8pOFJXCXQ7K8Ff+5A/Yhk8op0FT9Xhw2pkIGXUWniXD3vGLPOx4bnRN3/rz3 D2MEpmG2wMNHv8qvaR6fNyaDRHFQsPIubDGbOn3gj2QZTljEnbJp6CgisxPMVGzIQWk8 Wlxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oq4t3J+u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-132091-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132091-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t9-20020ac85889000000b00432cadf7a59si128012qta.43.2024.04.04.13.19.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 13:19:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132091-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oq4t3J+u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-132091-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132091-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3AF171C20A34 for ; Thu, 4 Apr 2024 20:19:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E29E81350D8; Thu, 4 Apr 2024 20:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oq4t3J+u" 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 F1084133413; Thu, 4 Apr 2024 20:19:14 +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=1712261955; cv=none; b=O2Z5Jze28+45JvPW83BLkr+39iD/qGStBb8oKFu/k49G1/zCuFOdL97YkBSqoyZUDFeqwMHSDFS6FI2wvSESlhmGL1RFcQ8mtff7Na9u7gV2Ua9Ya3kDxpvFrrVMD4d6VylofPmK2DOKx9xbZVxD4hi2PFWnHHtxGsFU67tXVcs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712261955; c=relaxed/simple; bh=NS25OfLBD8D7Z7nX6XcFM2Jj4Yv1a95IhOl67KbfY8g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=slQyxlZacVSNLXRk3mbjbL2ENpJUaku7A0OHuG9etwJojSZaG9qjAogrRnbpEGUnIha7BfJiY9hH5G7hQY/vWJSgwvROHP8+sh0JRZ4XwcTNd//BbmJ9JRMvMORQEJbPObIYnyJOsGkRuP1zmYyJO6FuFeH1aFnT3wtzMkHPbC4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oq4t3J+u; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32A99C433C7; Thu, 4 Apr 2024 20:19:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712261954; bh=NS25OfLBD8D7Z7nX6XcFM2Jj4Yv1a95IhOl67KbfY8g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oq4t3J+uL/lSQwkTjpPBKJRUTrpFUuVCx8gq+Qqj+12XoNRw1sZnJscdV2aX7rnO0 JQsx3KDDrp3U8SBI3hFYmHVvdEDydn4wRd5GavqwAATcJoks318K2sgQL5C+AtE/AA sh1vfmAcdHXHFuw6g+3OYugBJ4gs9HdU7mBZgUEEg38HYezWNnJCO4oZJaJ0Lf/dvi PEBMVwpVL+VcKxi3WAVA+bSvFe32yV5XRcHQRAaL8Q4SGPgKLcLXSUpd9HApV5s3nA 2sn651qA28MYbMqAgtFBgWDOUAqlZnwNyG6zwoCb/lXNLE+IkxgVJkv7i5q/Eq0sBm jOCS5a0Wy2Hfg== Date: Thu, 4 Apr 2024 22:19:11 +0200 From: Frederic Weisbecker To: "Joel Fernandes (Google)" Cc: linux-kernel@vger.kernel.org, "Paul E. McKenney" , Neeraj Upadhyay , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , urezki@gmail.com, neeraj.iitr10@gmail.com, rcu@vger.kernel.org Subject: Re: [PATCH v4] rcu/tree: Reduce wake up for synchronize_rcu() common case Message-ID: 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240319185458.3968308-1-joel@joelfernandes.org> Le Tue, Mar 19, 2024 at 02:54:57PM -0400, Joel Fernandes (Google) a ?crit : > 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) { Can this really happen? And if not should we warn? > + /* See comments below. */ > + atomic_dec_return_release(&rcu_state.srs_cleanups_pending); And if not should we really do that? > 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); Can we have a sanity check here ensuring this never goes negative? Thanks.