Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp266377rwl; Thu, 30 Mar 2023 15:49:17 -0700 (PDT) X-Google-Smtp-Source: AKy350ZG7qZ23B34aDy9u7TPDb8K156LkvFL0gOOQYgWbVUUp/Dk6x0Gx2e0GVNeNQCMPAOT07tj X-Received: by 2002:a05:6402:4413:b0:502:92d:4f51 with SMTP id y19-20020a056402441300b00502092d4f51mr4819935eda.1.1680216557440; Thu, 30 Mar 2023 15:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680216557; cv=none; d=google.com; s=arc-20160816; b=sBHGJppqmmFFXvAd51CFYpKcerUNqkU4ZJ7cUBx10pg6Ngc3/9lSi23ttnDa4+5BOC scO7oZV7qRzRk5V9XtkIarklBxnXdsmfTu/uH1DXm164topgWze+Qv+uR32cbceWym6W YQuQdL/B9kbYINwmxuGmGdbjgJ4vMnaKUAplaWYPAt7yrK6YGeArUwuXtfGbyGQONwtg Qhn/AMKpQ3QmfDMtHHUZYvkdrbZzxRV1LLHKFn1TxKh+xwaes7wHgIp94Y7U3P+ZMaoJ 9NaehIV9HTRwYNWxBE7//4TIol/GTxYPZeWe3pRJmRFXkzmRrCwO5mcE9OITo1+dKwCt QWZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5adBzBQBE2BCYNMzRhMrcIMa5F8ZKnlt9igo0g1ZLUQ=; b=R4IqceZNR22gcetae5qpRIHxrahxP7wnrs12Minq7r0SqwK+uEHJz3f9RawZfLf/97 1C4KtJMZjVDw0KfwYjI8FupHQ3n8ukO1ICAKNPyDxgfkYqumNMr39K/0ZFzXh1y3/Yg5 bOupHO9CJVvoDfivSc3w536BCFKpTSuMMeJ8KWDXABy/MMgM2KSyz6ZtbHseQI3zsF23 Nrub2LjIKqd0LrzGvQekZA1trQ77Q9fvvNG9ADGZfe9mQTJ6oj/0gsCyMiQlY2IdupMU DdidzAGEtgMtLp2JoZPXQeydnZaf3KLjpe2f/KLAQUkWtM5RG7mlYR3c0U0NESEsjMH0 q02A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=liqSHJog; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d6-20020aa7ce06000000b00501dd7cb827si745964edv.285.2023.03.30.15.48.52; Thu, 30 Mar 2023 15:49:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=liqSHJog; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230519AbjC3WsX (ORCPT + 99 others); Thu, 30 Mar 2023 18:48:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230509AbjC3Wry (ORCPT ); Thu, 30 Mar 2023 18:47:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC28B12844; Thu, 30 Mar 2023 15:47:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E7F66B82A68; Thu, 30 Mar 2023 22:47:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02FC0C433AE; Thu, 30 Mar 2023 22:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680216449; bh=RWTsWggyNWMF3mrQsYn6FXy7a1TnamrnSi7nELkO3xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=liqSHJog9QoVs7xd3BFMUdHHVHx8BYWVROWhnqYnaYzrJhoQYEYQe/w8XUc0xbdqz nskHVEeOKyVKsG4Yx7gHjUv6vnzqDkWF9RfpAuzQdo7gD1ItSnqcr3LqGeRZTjbNG9 b9bhyIGe6ZxGbSZWHNjkpX6vBGCyYmTaQ7fP8a8ja6N8kCPHwEGohfMZ9oOpFw63JA WRsK1Q4mxV+ThmVG354IAj+0WmLHgc+3FpHkQlW/kuVuUgWWLfVaCokreZ8niwxj3R x2gRgVhiEef2SVVrOyCCX9tHRGEbKppXQSnCZvkXYqYIwOx51ouf/dSe96yedzPNq3 Y9BgQyAxnWexg== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 261AD1540488; Thu, 30 Mar 2023 15:47:28 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, hch@lst.de, "Paul E. McKenney" , Sachin Sant , "Zhang, Qiang1" Subject: [PATCH rcu 12/20] srcu: Move heuristics fields from srcu_struct to srcu_usage Date: Thu, 30 Mar 2023 15:47:18 -0700 Message-Id: <20230330224726.662344-12-paulmck@kernel.org> X-Mailer: git-send-email 2.40.0.rc2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit moves the ->srcu_size_jiffies, ->srcu_n_lock_retries, and ->srcu_n_exp_nodelay fields from the srcu_struct structure to the srcu_usage structure to reduce the size of the former in order to improve cache locality. Suggested-by: Christoph Hellwig Tested-by: Sachin Sant Tested-by: "Zhang, Qiang1" Signed-off-by: Paul E. McKenney --- include/linux/srcutree.h | 6 +++--- kernel/rcu/srcutree.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h index 372e35b0e8b6..3023492d8d89 100644 --- a/include/linux/srcutree.h +++ b/include/linux/srcutree.h @@ -73,6 +73,9 @@ struct srcu_usage { unsigned long srcu_gp_seq_needed_exp; /* Furthest future exp GP. */ unsigned long srcu_gp_start; /* Last GP start timestamp (jiffies) */ unsigned long srcu_last_gp_end; /* Last GP end timestamp (ns) */ + unsigned long srcu_size_jiffies; /* Current contention-measurement interval. */ + unsigned long srcu_n_lock_retries; /* Contention events in current interval. */ + unsigned long srcu_n_exp_nodelay; /* # expedited no-delays in current GP phase. */ }; /* @@ -80,9 +83,6 @@ struct srcu_usage { */ struct srcu_struct { unsigned int srcu_idx; /* Current rdr array element. */ - unsigned long srcu_size_jiffies; /* Current contention-measurement interval. */ - unsigned long srcu_n_lock_retries; /* Contention events in current interval. */ - unsigned long srcu_n_exp_nodelay; /* # expedited no-delays in current GP phase. */ struct srcu_data __percpu *sda; /* Per-CPU srcu_data array. */ bool sda_is_static; /* May ->sda be passed to free_percpu()? */ unsigned long srcu_barrier_seq; /* srcu_barrier seq #. */ diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c index 340eb685cf64..291fb520bce0 100644 --- a/kernel/rcu/srcutree.c +++ b/kernel/rcu/srcutree.c @@ -348,11 +348,11 @@ static void spin_lock_irqsave_check_contention(struct srcu_struct *ssp) if (!SRCU_SIZING_IS_CONTEND() || ssp->srcu_sup->srcu_size_state) return; j = jiffies; - if (ssp->srcu_size_jiffies != j) { - ssp->srcu_size_jiffies = j; - ssp->srcu_n_lock_retries = 0; + if (ssp->srcu_sup->srcu_size_jiffies != j) { + ssp->srcu_sup->srcu_size_jiffies = j; + ssp->srcu_sup->srcu_n_lock_retries = 0; } - if (++ssp->srcu_n_lock_retries <= small_contention_lim) + if (++ssp->srcu_sup->srcu_n_lock_retries <= small_contention_lim) return; __srcu_transition_to_big(ssp); } @@ -624,8 +624,8 @@ static unsigned long srcu_get_delay(struct srcu_struct *ssp) if (time_after(j, gpstart)) jbase += j - gpstart; if (!jbase) { - WRITE_ONCE(ssp->srcu_n_exp_nodelay, READ_ONCE(ssp->srcu_n_exp_nodelay) + 1); - if (READ_ONCE(ssp->srcu_n_exp_nodelay) > srcu_max_nodelay_phase) + WRITE_ONCE(ssp->srcu_sup->srcu_n_exp_nodelay, READ_ONCE(ssp->srcu_sup->srcu_n_exp_nodelay) + 1); + if (READ_ONCE(ssp->srcu_sup->srcu_n_exp_nodelay) > srcu_max_nodelay_phase) jbase = 1; } } @@ -783,7 +783,7 @@ static void srcu_gp_start(struct srcu_struct *ssp) rcu_seq_snap(&ssp->srcu_sup->srcu_gp_seq)); spin_unlock_rcu_node(sdp); /* Interrupts remain disabled. */ WRITE_ONCE(ssp->srcu_sup->srcu_gp_start, jiffies); - WRITE_ONCE(ssp->srcu_n_exp_nodelay, 0); + WRITE_ONCE(ssp->srcu_sup->srcu_n_exp_nodelay, 0); smp_mb(); /* Order prior store to ->srcu_gp_seq_needed vs. GP start. */ rcu_seq_start(&ssp->srcu_sup->srcu_gp_seq); state = rcu_seq_state(ssp->srcu_sup->srcu_gp_seq); @@ -1625,7 +1625,7 @@ static void srcu_advance_state(struct srcu_struct *ssp) srcu_flip(ssp); spin_lock_irq_rcu_node(ssp->srcu_sup); rcu_seq_set_state(&ssp->srcu_sup->srcu_gp_seq, SRCU_STATE_SCAN2); - ssp->srcu_n_exp_nodelay = 0; + ssp->srcu_sup->srcu_n_exp_nodelay = 0; spin_unlock_irq_rcu_node(ssp->srcu_sup); } @@ -1640,7 +1640,7 @@ static void srcu_advance_state(struct srcu_struct *ssp) mutex_unlock(&ssp->srcu_sup->srcu_gp_mutex); return; /* readers present, retry later. */ } - ssp->srcu_n_exp_nodelay = 0; + ssp->srcu_sup->srcu_n_exp_nodelay = 0; srcu_gp_end(ssp); /* Releases ->srcu_gp_mutex. */ } } -- 2.40.0.rc2