From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com,
rostedt@goodmis.org, "Paul E. McKenney" <paulmck@kernel.org>
Subject: [PATCH rcu 08/19] srcu: Add boot-time control over srcu_node array allocation
Date: Fri, 4 Feb 2022 15:38:51 -0800 [thread overview]
Message-ID: <20220204233902.1902-8-paulmck@kernel.org> (raw)
In-Reply-To: <20220204233858.GA1469@paulmck-ThinkPad-P17-Gen-1>
This commit adds an srcu_tree.convert_to_big kernel parameter that either
refuses to convert at all (0), converts immediately at init_srcu_struct()
time (1), or lets rcutorture convert it (2). An addition contention-based
dynamic convertion choice will be added, along with documentation.
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/rcu/srcutree.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 550991cc213d3..d1f1ff930acf5 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -39,6 +39,15 @@ module_param(exp_holdoff, ulong, 0444);
static ulong counter_wrap_check = (ULONG_MAX >> 2);
module_param(counter_wrap_check, ulong, 0444);
+/*
+ * Control conversion to SRCU_SIZE_BIG:
+ * 0: Don't convert at all (default).
+ * 1: Convert at init_srcu_struct() time.
+ * 2: Convert when rcutorture invokes srcu_torture_stats_print().
+ */
+static int convert_to_big;
+module_param(convert_to_big, int, 0444);
+
/* Early-boot callback-management, so early that no lock is required! */
static LIST_HEAD(srcu_boot_list);
static bool __read_mostly srcu_init_done;
@@ -113,7 +122,7 @@ static void init_srcu_struct_data(struct srcu_struct *ssp)
* Allocated and initialize SRCU combining tree. Returns @true if
* allocation succeeded and @false otherwise.
*/
-static bool init_srcu_struct_nodes(struct srcu_struct *ssp)
+static bool init_srcu_struct_nodes(struct srcu_struct *ssp, gfp_t gfp_flags)
{
int cpu;
int i;
@@ -125,7 +134,7 @@ static bool init_srcu_struct_nodes(struct srcu_struct *ssp)
/* Initialize geometry if it has not already been initialized. */
rcu_init_geometry();
- ssp->node = kcalloc(rcu_num_nodes, sizeof(*ssp->node), GFP_ATOMIC);
+ ssp->node = kcalloc(rcu_num_nodes, sizeof(*ssp->node), gfp_flags);
if (!ssp->node)
return false;
@@ -204,6 +213,16 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
init_srcu_struct_data(ssp);
ssp->srcu_gp_seq_needed_exp = 0;
ssp->srcu_last_gp_end = ktime_get_mono_fast_ns();
+ if (READ_ONCE(ssp->srcu_size_state) == SRCU_SIZE_SMALL && convert_to_big == 1) {
+ if (!init_srcu_struct_nodes(ssp, GFP_ATOMIC)) {
+ if (!is_static) {
+ free_percpu(ssp->sda);
+ ssp->sda = NULL;
+ }
+ return -ENOMEM;
+ }
+ WRITE_ONCE(ssp->srcu_size_state, SRCU_SIZE_BIG);
+ }
smp_store_release(&ssp->srcu_gp_seq_needed, 0); /* Init done. */
return 0;
}
@@ -627,7 +646,7 @@ static void srcu_gp_end(struct srcu_struct *ssp)
ss_state = smp_load_acquire(&ssp->srcu_size_state);
if (ss_state && ss_state != SRCU_SIZE_BIG) {
if (ss_state == SRCU_SIZE_ALLOC)
- init_srcu_struct_nodes(ssp);
+ init_srcu_struct_nodes(ssp, GFP_KERNEL);
else
smp_store_release(&ssp->srcu_size_state, ss_state + 1);
}
@@ -1456,6 +1475,8 @@ void srcu_torture_stats_print(struct srcu_struct *ssp, char *tt, char *tf)
s1 += c1;
}
pr_cont(" T(%ld,%ld)\n", s0, s1);
+ if (READ_ONCE(ssp->srcu_size_state) == SRCU_SIZE_SMALL && convert_to_big == 2)
+ WRITE_ONCE(ssp->srcu_size_state, SRCU_SIZE_ALLOC);
}
EXPORT_SYMBOL_GPL(srcu_torture_stats_print);
--
2.31.1.189.g2e36527f23
next prev parent reply other threads:[~2022-02-04 23:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-04 23:38 [PATCH rcu 0/19] SRCU updates for v5.18 Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 01/19] srcu: Tighten cleanup_srcu_struct() GP checks Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 02/19] srcu: Fix s/is/if/ typo in srcu_node comment Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 03/19] srcu: Make srcu_funnel_gp_start() cache ->mynode in snp_leaf Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 04/19] srcu: Dynamically allocate srcu_node array Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 05/19] srcu: Make Tree SRCU able to operate without snp_node array Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 06/19] srcu: Add size-state transitioning code Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 07/19] srcu: Make rcutorture dump the SRCU size state Paul E. McKenney
2022-02-04 23:38 ` Paul E. McKenney [this message]
2022-02-04 23:38 ` [PATCH rcu 09/19] srcu: Use export for srcu_struct defined by DEFINE_STATIC_SRCU() Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 10/19] srcu: Compute snp_seq earlier in srcu_funnel_gp_start() Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 11/19] srcu: Use invalid initial value for srcu_node GP sequence numbers Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 12/19] srcu: Avoid NULL dereference in srcu_torture_stats_print() Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 13/19] srcu: Prevent cleanup_srcu_struct() from freeing non-dynamic ->sda Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 14/19] srcu: Explain srcu_funnel_gp_start() call to list_add() is safe Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 15/19] srcu: Create concurrency-safe helper for initiating size transition Paul E. McKenney
2022-02-04 23:38 ` [PATCH rcu 16/19] srcu: Add contention-triggered addition of srcu_node tree Paul E. McKenney
2022-02-04 23:39 ` [PATCH rcu 17/19] srcu: Make srcu_size_state_name static Paul E. McKenney
2022-02-04 23:39 ` [PATCH rcu 18/19] srcu: Automatically determine size-transition strategy at boot Paul E. McKenney
2022-02-04 23:39 ` [PATCH rcu 19/19] srcu: Add contention check to call_srcu() srcu_data ->lock acquisition Paul E. McKenney
[not found] ` <20220205030303.2408-1-hdanton@sina.com>
2022-02-05 5:20 ` Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220204233902.1902-8-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox