linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH tip/core/rcu 0/12] Tree geometry-initialization simplifications for 4.3
@ 2015-07-17 22:30 Paul E. McKenney
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
  0 siblings, 1 reply; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani

Hello!

This series simplifies the arithmetic involved in computing the
geometry of Tree RCU's combining tree.

1.	Provide more diagnostics for stalled GP kthread.  (A bit off-topic,
	but included in this series due to conflicting updates.)

2.	Panic if RCU tree can not accommodate all CPUs, courtesy of
	Alexander Gordeev.

3.	Remove superfluous local variable in rcu_init_geometry(),
	courtesy of Alexander Gordeev.

4.	Cleanup rcu_init_geometry() code and arithmetic, courtesy of
	Alexander Gordeev.

5.	Simplify rcu_init_geometry() capacity arithmetic, courtesy of
	Alexander Gordeev.

6.	Limit rcu_state::levelcnt[] to RCU_NUM_LVLS items, courtesy of
	Alexander Gordeev.

7.	Limit rcu_capacity[] size to RCU_NUM_LVLS items, courtesy of
	Alexander Gordeev.

8.	Remove unnecessary fields from rcu_state structure, courtesy of
	Alexander Gordeev.

9.	Limit count of static data to the number of RCU levels, courtesy
	of Alexander Gordeev.

10.	Simplify arithmetic to calculate number of RCU nodes, courtesy
	of Alexander Gordeev.

11.	Shut up bogus gcc array bounds warning, courtesy of Alexander
	Gordeev.

12.	Reset rcu_fanout_leaf if out of bounds.

							Thanx, Paul

------------------------------------------------------------------------

 b/kernel/rcu/tree.c        |  156 +++++++++++++++++++++------------------------
 b/kernel/rcu/tree.h        |   45 +++++++-----
 b/kernel/rcu/tree_plugin.h |    4 -
 3 files changed, 103 insertions(+), 102 deletions(-)


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread
  2015-07-17 22:30 [PATCH tip/core/rcu 0/12] Tree geometry-initialization simplifications for 4.3 Paul E. McKenney
@ 2015-07-17 22:30 ` Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs Paul E. McKenney
                     ` (10 more replies)
  0 siblings, 11 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Paul E. McKenney

From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 10 ++++++++--
 kernel/rcu/tree.h |  6 +++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 65137bc28b2b..1c58cbd03922 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -1178,9 +1178,11 @@ static void rcu_check_gp_kthread_starvation(struct rcu_state *rsp)
 	j = jiffies;
 	gpa = READ_ONCE(rsp->gp_activity);
 	if (j - gpa > 2 * HZ)
-		pr_err("%s kthread starved for %ld jiffies! g%lu c%lu f%#x\n",
+		pr_err("%s kthread starved for %ld jiffies! g%lu c%lu f%#x s%d ->state=%#lx\n",
 		       rsp->name, j - gpa,
-		       rsp->gpnum, rsp->completed, rsp->gp_flags);
+		       rsp->gpnum, rsp->completed,
+		       rsp->gp_flags, rsp->gp_state,
+		       rsp->gp_kthread ? rsp->gp_kthread->state : 0);
 }
 
 /*
@@ -2041,6 +2043,7 @@ static int __noreturn rcu_gp_kthread(void *arg)
 			wait_event_interruptible(rsp->gp_wq,
 						 READ_ONCE(rsp->gp_flags) &
 						 RCU_GP_FLAG_INIT);
+			rsp->gp_state = RCU_GP_DONE_GPS;
 			/* Locking provides needed memory barrier. */
 			if (rcu_gp_init(rsp))
 				break;
@@ -2073,6 +2076,7 @@ static int __noreturn rcu_gp_kthread(void *arg)
 					(!READ_ONCE(rnp->qsmask) &&
 					 !rcu_preempt_blocked_readers_cgp(rnp)),
 					j);
+			rsp->gp_state = RCU_GP_DONE_FQS;
 			/* Locking provides needed memory barriers. */
 			/* If grace period done, leave loop. */
 			if (!READ_ONCE(rnp->qsmask) &&
@@ -2110,7 +2114,9 @@ static int __noreturn rcu_gp_kthread(void *arg)
 		}
 
 		/* Handle grace-period end. */
+		rsp->gp_state = RCU_GP_CLEANUP;
 		rcu_gp_cleanup(rsp);
+		rsp->gp_state = RCU_GP_CLEANED;
 	}
 }
 
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 4adb7ca0bf47..f1f4784f9107 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -527,7 +527,11 @@ struct rcu_state {
 /* Values for rcu_state structure's gp_flags field. */
 #define RCU_GP_WAIT_INIT 0	/* Initial state. */
 #define RCU_GP_WAIT_GPS  1	/* Wait for grace-period start. */
-#define RCU_GP_WAIT_FQS  2	/* Wait for force-quiescent-state time. */
+#define RCU_GP_DONE_GPS  2	/* Wait done for grace-period start. */
+#define RCU_GP_WAIT_FQS  3	/* Wait for force-quiescent-state time. */
+#define RCU_GP_DONE_FQS  4	/* Wait done for force-quiescent-state time. */
+#define RCU_GP_CLEANUP   5	/* Grace-period cleanup started. */
+#define RCU_GP_CLEANED   6	/* Grace-period cleanup complete. */
 
 extern struct list_head rcu_struct_flavors;
 
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
@ 2015-07-17 22:30   ` Paul E. McKenney
  2015-07-30 12:28     ` Peter Zijlstra
  2015-07-17 22:30   ` [PATCH tip/core/rcu 03/12] rcu: Remove superfluous local variable in rcu_init_geometry() Paul E. McKenney
                     ` (9 subsequent siblings)
  10 siblings, 1 reply; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

Currently a condition when RCU tree is unable to accommodate
the configured number of CPUs is not permitted and causes
a fall back to compile-time values. However, the code has no
means to exceed the RCU tree capacity neither at compile-time
nor in run-time. Therefore, if the condition is met in run-
time then it indicates a serios problem elsewhere and should
be handled with a panic.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 1c58cbd03922..fe8d92987dfa 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -4107,6 +4107,19 @@ static void __init rcu_init_geometry(void)
 		rcu_fanout_leaf, nr_cpu_ids);
 
 	/*
+	 * The boot-time rcu_fanout_leaf parameter is only permitted
+	 * to increase the leaf-level fanout, not decrease it.  Of course,
+	 * the leaf-level fanout cannot exceed the number of bits in
+	 * the rcu_node masks.  Complain and fall back to the compile-
+	 * time values if these limits are exceeded.
+	 */
+	if (rcu_fanout_leaf < RCU_FANOUT_LEAF ||
+	    rcu_fanout_leaf > sizeof(unsigned long) * 8) {
+		WARN_ON(1);
+		return;
+	}
+
+	/*
 	 * Compute number of nodes that can be handled an rcu_node tree
 	 * with the given number of levels.  Setting rcu_capacity[0] makes
 	 * some of the arithmetic easier.
@@ -4117,19 +4130,11 @@ static void __init rcu_init_geometry(void)
 		rcu_capacity[i] = rcu_capacity[i - 1] * RCU_FANOUT;
 
 	/*
-	 * The boot-time rcu_fanout_leaf parameter is only permitted
-	 * to increase the leaf-level fanout, not decrease it.  Of course,
-	 * the leaf-level fanout cannot exceed the number of bits in
-	 * the rcu_node masks.  Finally, the tree must be able to accommodate
-	 * the configured number of CPUs.  Complain and fall back to the
-	 * compile-time values if these limits are exceeded.
+	 * The tree must be able to accommodate the configured number of CPUs.
+	 * If this limit is exceeded than we have a serious problem elsewhere.
 	 */
-	if (rcu_fanout_leaf < RCU_FANOUT_LEAF ||
-	    rcu_fanout_leaf > sizeof(unsigned long) * 8 ||
-	    n > rcu_capacity[MAX_RCU_LVLS]) {
-		WARN_ON(1);
-		return;
-	}
+	if (n > rcu_capacity[MAX_RCU_LVLS])
+		panic("rcu_init_geometry: rcu_capacity[] is too small");
 
 	/* Calculate the number of rcu_nodes at each level of the tree. */
 	for (i = 1; i <= MAX_RCU_LVLS; i++)
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 03/12] rcu: Remove superfluous local variable in rcu_init_geometry()
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs Paul E. McKenney
@ 2015-07-17 22:30   ` Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 04/12] rcu: Cleanup rcu_init_geometry() code and arithmetics Paul E. McKenney
                     ` (8 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

Local variable 'n' mimics 'nr_cpu_ids' while the both are
used within one function. There is no reason for 'n' to
exist whatsoever.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index fe8d92987dfa..ad49dbed44fb 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -4083,7 +4083,6 @@ static void __init rcu_init_geometry(void)
 	ulong d;
 	int i;
 	int j;
-	int n = nr_cpu_ids;
 	int rcu_capacity[MAX_RCU_LVLS + 1];
 
 	/*
@@ -4133,15 +4132,16 @@ static void __init rcu_init_geometry(void)
 	 * The tree must be able to accommodate the configured number of CPUs.
 	 * If this limit is exceeded than we have a serious problem elsewhere.
 	 */
-	if (n > rcu_capacity[MAX_RCU_LVLS])
+	if (nr_cpu_ids > rcu_capacity[MAX_RCU_LVLS])
 		panic("rcu_init_geometry: rcu_capacity[] is too small");
 
 	/* Calculate the number of rcu_nodes at each level of the tree. */
 	for (i = 1; i <= MAX_RCU_LVLS; i++)
-		if (n <= rcu_capacity[i]) {
-			for (j = 0; j <= i; j++)
-				num_rcu_lvl[j] =
-					DIV_ROUND_UP(n, rcu_capacity[i - j]);
+		if (nr_cpu_ids <= rcu_capacity[i]) {
+			for (j = 0; j <= i; j++) {
+				int cap = rcu_capacity[i - j];
+				num_rcu_lvl[j] = DIV_ROUND_UP(nr_cpu_ids, cap);
+			}
 			rcu_num_lvls = i;
 			for (j = i + 1; j <= MAX_RCU_LVLS; j++)
 				num_rcu_lvl[j] = 0;
@@ -4152,7 +4152,7 @@ static void __init rcu_init_geometry(void)
 	rcu_num_nodes = 0;
 	for (i = 0; i <= MAX_RCU_LVLS; i++)
 		rcu_num_nodes += num_rcu_lvl[i];
-	rcu_num_nodes -= n;
+	rcu_num_nodes -= nr_cpu_ids;
 }
 
 /*
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 04/12] rcu: Cleanup rcu_init_geometry() code and arithmetics
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 03/12] rcu: Remove superfluous local variable in rcu_init_geometry() Paul E. McKenney
@ 2015-07-17 22:30   ` Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 05/12] rcu: Simplify rcu_init_geometry() capacity arithmetics Paul E. McKenney
                     ` (7 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

This update simplifies rcu_init_geometry() code flow
and makes calculation of the total number of rcu_node
structures more easy to read.

The update relies on the fact num_rcu_lvl[] is never
accessed beyond rcu_num_lvls index by the rest of the
code. Therefore, there is no need initialize the whole
num_rcu_lvl[].

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index ad49dbed44fb..37ca8a867a1c 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -4082,7 +4082,6 @@ static void __init rcu_init_geometry(void)
 {
 	ulong d;
 	int i;
-	int j;
 	int rcu_capacity[MAX_RCU_LVLS + 1];
 
 	/*
@@ -4135,24 +4134,21 @@ static void __init rcu_init_geometry(void)
 	if (nr_cpu_ids > rcu_capacity[MAX_RCU_LVLS])
 		panic("rcu_init_geometry: rcu_capacity[] is too small");
 
+	/* Calculate the number of levels in the tree. */
+	for (i = 1; nr_cpu_ids > rcu_capacity[i]; i++) {
+	}
+	rcu_num_lvls = i;
+
 	/* Calculate the number of rcu_nodes at each level of the tree. */
-	for (i = 1; i <= MAX_RCU_LVLS; i++)
-		if (nr_cpu_ids <= rcu_capacity[i]) {
-			for (j = 0; j <= i; j++) {
-				int cap = rcu_capacity[i - j];
-				num_rcu_lvl[j] = DIV_ROUND_UP(nr_cpu_ids, cap);
-			}
-			rcu_num_lvls = i;
-			for (j = i + 1; j <= MAX_RCU_LVLS; j++)
-				num_rcu_lvl[j] = 0;
-			break;
-		}
+	for (i = 0; i < rcu_num_lvls; i++) {
+		int cap = rcu_capacity[rcu_num_lvls - i];
+		num_rcu_lvl[i] = DIV_ROUND_UP(nr_cpu_ids, cap);
+	}
 
 	/* Calculate the total number of rcu_node structures. */
 	rcu_num_nodes = 0;
-	for (i = 0; i <= MAX_RCU_LVLS; i++)
+	for (i = 0; i < rcu_num_lvls; i++)
 		rcu_num_nodes += num_rcu_lvl[i];
-	rcu_num_nodes -= nr_cpu_ids;
 }
 
 /*
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 05/12] rcu: Simplify rcu_init_geometry() capacity arithmetics
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
                     ` (2 preceding siblings ...)
  2015-07-17 22:30   ` [PATCH tip/core/rcu 04/12] rcu: Cleanup rcu_init_geometry() code and arithmetics Paul E. McKenney
@ 2015-07-17 22:30   ` Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 06/12] rcu: Limit rcu_state::levelcnt[] to RCU_NUM_LVLS items Paul E. McKenney
                     ` (6 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

Current code suggests that introducing the extra level to
rcu_capacity[] array makes some of the arithmetic easier.
Well, in fact it appears rather confusing and unnecessary.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 37ca8a867a1c..2103beedb49f 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -4082,7 +4082,7 @@ static void __init rcu_init_geometry(void)
 {
 	ulong d;
 	int i;
-	int rcu_capacity[MAX_RCU_LVLS + 1];
+	int rcu_capacity[MAX_RCU_LVLS];
 
 	/*
 	 * Initialize any unspecified boot parameters.
@@ -4119,29 +4119,27 @@ static void __init rcu_init_geometry(void)
 
 	/*
 	 * Compute number of nodes that can be handled an rcu_node tree
-	 * with the given number of levels.  Setting rcu_capacity[0] makes
-	 * some of the arithmetic easier.
+	 * with the given number of levels.
 	 */
-	rcu_capacity[0] = 1;
-	rcu_capacity[1] = rcu_fanout_leaf;
-	for (i = 2; i <= MAX_RCU_LVLS; i++)
+	rcu_capacity[0] = rcu_fanout_leaf;
+	for (i = 1; i < MAX_RCU_LVLS; i++)
 		rcu_capacity[i] = rcu_capacity[i - 1] * RCU_FANOUT;
 
 	/*
 	 * The tree must be able to accommodate the configured number of CPUs.
 	 * If this limit is exceeded than we have a serious problem elsewhere.
 	 */
-	if (nr_cpu_ids > rcu_capacity[MAX_RCU_LVLS])
+	if (nr_cpu_ids > rcu_capacity[MAX_RCU_LVLS - 1])
 		panic("rcu_init_geometry: rcu_capacity[] is too small");
 
 	/* Calculate the number of levels in the tree. */
-	for (i = 1; nr_cpu_ids > rcu_capacity[i]; i++) {
+	for (i = 0; nr_cpu_ids > rcu_capacity[i]; i++) {
 	}
-	rcu_num_lvls = i;
+	rcu_num_lvls = i + 1;
 
 	/* Calculate the number of rcu_nodes at each level of the tree. */
 	for (i = 0; i < rcu_num_lvls; i++) {
-		int cap = rcu_capacity[rcu_num_lvls - i];
+		int cap = rcu_capacity[(rcu_num_lvls - 1) - i];
 		num_rcu_lvl[i] = DIV_ROUND_UP(nr_cpu_ids, cap);
 	}
 
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 06/12] rcu: Limit rcu_state::levelcnt[] to RCU_NUM_LVLS items
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
                     ` (3 preceding siblings ...)
  2015-07-17 22:30   ` [PATCH tip/core/rcu 05/12] rcu: Simplify rcu_init_geometry() capacity arithmetics Paul E. McKenney
@ 2015-07-17 22:30   ` Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 07/12] rcu: Limit rcu_capacity[] size " Paul E. McKenney
                     ` (5 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

Variable rcu_num_lvls is limited by RCU_NUM_LVLS macro.
In turn, rcu_state::levelcnt[] array is never accessed
beyond rcu_num_lvls. Thus, rcu_state::levelcnt[] is safe
to limit to RCU_NUM_LVLS items.

Since rcu_num_lvls could be changed during boot (as result
of rcutree.rcu_fanout_leaf kernel parameter update) one might
assume a new value could overflow the value of RCU_NUM_LVLS.
However, that is not the case, since leaf-level fanout is only
permitted to increase, resulting in rcu_num_lvls possibly to
decrease.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index f1f4784f9107..a6faae53ea8f 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -443,7 +443,7 @@ do {									\
 struct rcu_state {
 	struct rcu_node node[NUM_RCU_NODES];	/* Hierarchy. */
 	struct rcu_node *level[RCU_NUM_LVLS];	/* Hierarchy levels. */
-	u32 levelcnt[MAX_RCU_LVLS + 1];		/* # nodes in each level. */
+	u32 levelcnt[RCU_NUM_LVLS];		/* # nodes in each level. */
 	u8 levelspread[RCU_NUM_LVLS];		/* kids/node in each level. */
 	u8 flavor_mask;				/* bit in flavor mask. */
 	struct rcu_data __percpu *rda;		/* pointer of percu rcu_data. */
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 07/12] rcu: Limit rcu_capacity[] size to RCU_NUM_LVLS items
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
                     ` (4 preceding siblings ...)
  2015-07-17 22:30   ` [PATCH tip/core/rcu 06/12] rcu: Limit rcu_state::levelcnt[] to RCU_NUM_LVLS items Paul E. McKenney
@ 2015-07-17 22:30   ` Paul E. McKenney
  2015-07-17 22:30   ` [PATCH tip/core/rcu 08/12] rcu: Remove unnecessary fields from rcu_state structure Paul E. McKenney
                     ` (4 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

Number of items in rcu_capacity[] array is defined by macro
MAX_RCU_LVLS. However, that array is never accessed beyond
RCU_NUM_LVLS index. Therefore, we can limit the array to
RCU_NUM_LVLS items and eliminate MAX_RCU_LVLS. As result,
in most cases the memory is conserved.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 12 ++++++------
 kernel/rcu/tree.h |  2 --
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 2103beedb49f..2ec7b796f660 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3998,19 +3998,19 @@ static void __init rcu_init_one(struct rcu_state *rsp,
 		"rcu_node_0",
 		"rcu_node_1",
 		"rcu_node_2",
-		"rcu_node_3" };  /* Match MAX_RCU_LVLS */
+		"rcu_node_3" };
 	static const char * const fqs[] = {
 		"rcu_node_fqs_0",
 		"rcu_node_fqs_1",
 		"rcu_node_fqs_2",
-		"rcu_node_fqs_3" };  /* Match MAX_RCU_LVLS */
+		"rcu_node_fqs_3" };
 	static u8 fl_mask = 0x1;
 	int cpustride = 1;
 	int i;
 	int j;
 	struct rcu_node *rnp;
 
-	BUILD_BUG_ON(MAX_RCU_LVLS > ARRAY_SIZE(buf));  /* Fix buf[] init! */
+	BUILD_BUG_ON(RCU_NUM_LVLS > ARRAY_SIZE(buf));  /* Fix buf[] init! */
 
 	/* Silence gcc 4.8 false positive about array index out of range. */
 	if (rcu_num_lvls <= 0 || rcu_num_lvls > RCU_NUM_LVLS)
@@ -4082,7 +4082,7 @@ static void __init rcu_init_geometry(void)
 {
 	ulong d;
 	int i;
-	int rcu_capacity[MAX_RCU_LVLS];
+	int rcu_capacity[RCU_NUM_LVLS];
 
 	/*
 	 * Initialize any unspecified boot parameters.
@@ -4122,14 +4122,14 @@ static void __init rcu_init_geometry(void)
 	 * with the given number of levels.
 	 */
 	rcu_capacity[0] = rcu_fanout_leaf;
-	for (i = 1; i < MAX_RCU_LVLS; i++)
+	for (i = 1; i < RCU_NUM_LVLS; i++)
 		rcu_capacity[i] = rcu_capacity[i - 1] * RCU_FANOUT;
 
 	/*
 	 * The tree must be able to accommodate the configured number of CPUs.
 	 * If this limit is exceeded than we have a serious problem elsewhere.
 	 */
-	if (nr_cpu_ids > rcu_capacity[MAX_RCU_LVLS - 1])
+	if (nr_cpu_ids > rcu_capacity[RCU_NUM_LVLS - 1])
 		panic("rcu_init_geometry: rcu_capacity[] is too small");
 
 	/* Calculate the number of levels in the tree. */
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index a6faae53ea8f..d625e9ff0faf 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -36,8 +36,6 @@
  * Of course, your mileage may vary.
  */
 
-#define MAX_RCU_LVLS 4
-
 #ifdef CONFIG_RCU_FANOUT
 #define RCU_FANOUT CONFIG_RCU_FANOUT
 #else /* #ifdef CONFIG_RCU_FANOUT */
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 08/12] rcu: Remove unnecessary fields from rcu_state structure
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
                     ` (5 preceding siblings ...)
  2015-07-17 22:30   ` [PATCH tip/core/rcu 07/12] rcu: Limit rcu_capacity[] size " Paul E. McKenney
@ 2015-07-17 22:30   ` Paul E. McKenney
  2015-07-17 22:31   ` [PATCH tip/core/rcu 09/12] rcu: Limit count of static data to the number of RCU levels Paul E. McKenney
                     ` (3 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

Members rcu_state::levelcnt[] and rcu_state::levelspread[]
are only used at init. There is no reason to keep them
afterwards.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 27 +++++++++++++++------------
 kernel/rcu/tree.h |  2 --
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 2ec7b796f660..7226e25ba97f 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3967,22 +3967,22 @@ void rcu_scheduler_starting(void)
  * Compute the per-level fanout, either using the exact fanout specified
  * or balancing the tree, depending on the rcu_fanout_exact boot parameter.
  */
-static void __init rcu_init_levelspread(struct rcu_state *rsp)
+static void __init rcu_init_levelspread(int *levelspread, const int *levelcnt)
 {
 	int i;
 
 	if (rcu_fanout_exact) {
-		rsp->levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf;
+		levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf;
 		for (i = rcu_num_lvls - 2; i >= 0; i--)
-			rsp->levelspread[i] = RCU_FANOUT;
+			levelspread[i] = RCU_FANOUT;
 	} else {
 		int ccur;
 		int cprv;
 
 		cprv = nr_cpu_ids;
 		for (i = rcu_num_lvls - 1; i >= 0; i--) {
-			ccur = rsp->levelcnt[i];
-			rsp->levelspread[i] = (cprv + ccur - 1) / ccur;
+			ccur = levelcnt[i];
+			levelspread[i] = (cprv + ccur - 1) / ccur;
 			cprv = ccur;
 		}
 	}
@@ -4005,6 +4005,9 @@ static void __init rcu_init_one(struct rcu_state *rsp,
 		"rcu_node_fqs_2",
 		"rcu_node_fqs_3" };
 	static u8 fl_mask = 0x1;
+
+	int levelcnt[RCU_NUM_LVLS];		/* # nodes in each level. */
+	int levelspread[RCU_NUM_LVLS];		/* kids/node in each level. */
 	int cpustride = 1;
 	int i;
 	int j;
@@ -4019,19 +4022,19 @@ static void __init rcu_init_one(struct rcu_state *rsp,
 	/* Initialize the level-tracking arrays. */
 
 	for (i = 0; i < rcu_num_lvls; i++)
-		rsp->levelcnt[i] = num_rcu_lvl[i];
+		levelcnt[i] = num_rcu_lvl[i];
 	for (i = 1; i < rcu_num_lvls; i++)
-		rsp->level[i] = rsp->level[i - 1] + rsp->levelcnt[i - 1];
-	rcu_init_levelspread(rsp);
+		rsp->level[i] = rsp->level[i - 1] + levelcnt[i - 1];
+	rcu_init_levelspread(levelspread, levelcnt);
 	rsp->flavor_mask = fl_mask;
 	fl_mask <<= 1;
 
 	/* Initialize the elements themselves, starting from the leaves. */
 
 	for (i = rcu_num_lvls - 1; i >= 0; i--) {
-		cpustride *= rsp->levelspread[i];
+		cpustride *= levelspread[i];
 		rnp = rsp->level[i];
-		for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) {
+		for (j = 0; j < levelcnt[i]; j++, rnp++) {
 			raw_spin_lock_init(&rnp->lock);
 			lockdep_set_class_and_name(&rnp->lock,
 						   &rcu_node_class[i], buf[i]);
@@ -4051,10 +4054,10 @@ static void __init rcu_init_one(struct rcu_state *rsp,
 				rnp->grpmask = 0;
 				rnp->parent = NULL;
 			} else {
-				rnp->grpnum = j % rsp->levelspread[i - 1];
+				rnp->grpnum = j % levelspread[i - 1];
 				rnp->grpmask = 1UL << rnp->grpnum;
 				rnp->parent = rsp->level[i - 1] +
-					      j / rsp->levelspread[i - 1];
+					      j / levelspread[i - 1];
 			}
 			rnp->level = i;
 			INIT_LIST_HEAD(&rnp->blkd_tasks);
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index d625e9ff0faf..3413f3c5c8b2 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -441,8 +441,6 @@ do {									\
 struct rcu_state {
 	struct rcu_node node[NUM_RCU_NODES];	/* Hierarchy. */
 	struct rcu_node *level[RCU_NUM_LVLS];	/* Hierarchy levels. */
-	u32 levelcnt[RCU_NUM_LVLS];		/* # nodes in each level. */
-	u8 levelspread[RCU_NUM_LVLS];		/* kids/node in each level. */
 	u8 flavor_mask;				/* bit in flavor mask. */
 	struct rcu_data __percpu *rda;		/* pointer of percu rcu_data. */
 	void (*call)(struct rcu_head *head,	/* call_rcu() flavor. */
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 09/12] rcu: Limit count of static data to the number of RCU levels
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
                     ` (6 preceding siblings ...)
  2015-07-17 22:30   ` [PATCH tip/core/rcu 08/12] rcu: Remove unnecessary fields from rcu_state structure Paul E. McKenney
@ 2015-07-17 22:31   ` Paul E. McKenney
  2015-07-17 22:31   ` [PATCH tip/core/rcu 10/12] rcu: Simplify arithmetic to calculate number of RCU nodes Paul E. McKenney
                     ` (2 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

Although a number of RCU levels may be less than the current
maximum of four, some static data associated with each level
are allocated for all four levels. As result, the extra data
never get accessed and just wast memory. This update limits
count of allocated items to the number of used RCU levels.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 21 ++++-----------------
 kernel/rcu/tree.h | 12 ++++++++++++
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 7226e25ba97f..e53bbc53bcd5 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -124,13 +124,8 @@ module_param(rcu_fanout_exact, bool, 0444);
 static int rcu_fanout_leaf = RCU_FANOUT_LEAF;
 module_param(rcu_fanout_leaf, int, 0444);
 int rcu_num_lvls __read_mostly = RCU_NUM_LVLS;
-static int num_rcu_lvl[] = {  /* Number of rcu_nodes at specified level. */
-	NUM_RCU_LVL_0,
-	NUM_RCU_LVL_1,
-	NUM_RCU_LVL_2,
-	NUM_RCU_LVL_3,
-	NUM_RCU_LVL_4,
-};
+/* Number of rcu_nodes at specified level. */
+static int num_rcu_lvl[] = NUM_RCU_LVL_INIT;
 int rcu_num_nodes __read_mostly = NUM_RCU_NODES; /* Total # rcu_nodes in use. */
 
 /*
@@ -3994,16 +3989,8 @@ static void __init rcu_init_levelspread(int *levelspread, const int *levelcnt)
 static void __init rcu_init_one(struct rcu_state *rsp,
 		struct rcu_data __percpu *rda)
 {
-	static const char * const buf[] = {
-		"rcu_node_0",
-		"rcu_node_1",
-		"rcu_node_2",
-		"rcu_node_3" };
-	static const char * const fqs[] = {
-		"rcu_node_fqs_0",
-		"rcu_node_fqs_1",
-		"rcu_node_fqs_2",
-		"rcu_node_fqs_3" };
+	static const char * const buf[] = RCU_NODE_NAME_INIT;
+	static const char * const fqs[] = RCU_FQS_NAME_INIT;
 	static u8 fl_mask = 0x1;
 
 	int levelcnt[RCU_NUM_LVLS];		/* # nodes in each level. */
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 3413f3c5c8b2..d44856b6170a 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -68,6 +68,9 @@
 #  define NUM_RCU_LVL_2	      0
 #  define NUM_RCU_LVL_3	      0
 #  define NUM_RCU_LVL_4	      0
+#  define NUM_RCU_LVL_INIT    { NUM_RCU_LVL_0 }
+#  define RCU_NODE_NAME_INIT  { "rcu_node_0" }
+#  define RCU_FQS_NAME_INIT   { "rcu_node_fqs_0" }
 #elif NR_CPUS <= RCU_FANOUT_2
 #  define RCU_NUM_LVLS	      2
 #  define NUM_RCU_LVL_0	      1
@@ -75,6 +78,9 @@
 #  define NUM_RCU_LVL_2	      (NR_CPUS)
 #  define NUM_RCU_LVL_3	      0
 #  define NUM_RCU_LVL_4	      0
+#  define NUM_RCU_LVL_INIT    { NUM_RCU_LVL_0, NUM_RCU_LVL_1 }
+#  define RCU_NODE_NAME_INIT  { "rcu_node_0", "rcu_node_1" }
+#  define RCU_FQS_NAME_INIT   { "rcu_node_fqs_0", "rcu_node_fqs_1" }
 #elif NR_CPUS <= RCU_FANOUT_3
 #  define RCU_NUM_LVLS	      3
 #  define NUM_RCU_LVL_0	      1
@@ -82,6 +88,9 @@
 #  define NUM_RCU_LVL_2	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
 #  define NUM_RCU_LVL_3	      (NR_CPUS)
 #  define NUM_RCU_LVL_4	      0
+#  define NUM_RCU_LVL_INIT    { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 }
+#  define RCU_NODE_NAME_INIT  { "rcu_node_0", "rcu_node_1", "rcu_node_2" }
+#  define RCU_FQS_NAME_INIT   { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" }
 #elif NR_CPUS <= RCU_FANOUT_4
 #  define RCU_NUM_LVLS	      4
 #  define NUM_RCU_LVL_0	      1
@@ -89,6 +98,9 @@
 #  define NUM_RCU_LVL_2	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
 #  define NUM_RCU_LVL_3	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
 #  define NUM_RCU_LVL_4	      (NR_CPUS)
+#  define NUM_RCU_LVL_INIT    { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 }
+#  define RCU_NODE_NAME_INIT  { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" }
+#  define RCU_FQS_NAME_INIT   { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" }
 #else
 # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS"
 #endif /* #if (NR_CPUS) <= RCU_FANOUT_1 */
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 10/12] rcu: Simplify arithmetic to calculate number of RCU nodes
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
                     ` (7 preceding siblings ...)
  2015-07-17 22:31   ` [PATCH tip/core/rcu 09/12] rcu: Limit count of static data to the number of RCU levels Paul E. McKenney
@ 2015-07-17 22:31   ` Paul E. McKenney
  2015-07-17 22:31   ` [PATCH tip/core/rcu 11/12] rcu: Shut up bogus gcc array bounds warning Paul E. McKenney
  2015-07-17 22:31   ` [PATCH tip/core/rcu 12/12] rcu: Reset rcu_fanout_leaf if out of bounds Paul E. McKenney
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

This update makes arithmetic to calculate number of RCU nodes
more straight and easy to read.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.h        | 17 ++++-------------
 kernel/rcu/tree_plugin.h |  4 ++--
 2 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index d44856b6170a..581f8d3c5b28 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -64,10 +64,7 @@
 #if NR_CPUS <= RCU_FANOUT_1
 #  define RCU_NUM_LVLS	      1
 #  define NUM_RCU_LVL_0	      1
-#  define NUM_RCU_LVL_1	      (NR_CPUS)
-#  define NUM_RCU_LVL_2	      0
-#  define NUM_RCU_LVL_3	      0
-#  define NUM_RCU_LVL_4	      0
+#  define NUM_RCU_NODES	      NUM_RCU_LVL_0
 #  define NUM_RCU_LVL_INIT    { NUM_RCU_LVL_0 }
 #  define RCU_NODE_NAME_INIT  { "rcu_node_0" }
 #  define RCU_FQS_NAME_INIT   { "rcu_node_fqs_0" }
@@ -75,9 +72,7 @@
 #  define RCU_NUM_LVLS	      2
 #  define NUM_RCU_LVL_0	      1
 #  define NUM_RCU_LVL_1	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
-#  define NUM_RCU_LVL_2	      (NR_CPUS)
-#  define NUM_RCU_LVL_3	      0
-#  define NUM_RCU_LVL_4	      0
+#  define NUM_RCU_NODES	      (NUM_RCU_LVL_0 + NUM_RCU_LVL_1)
 #  define NUM_RCU_LVL_INIT    { NUM_RCU_LVL_0, NUM_RCU_LVL_1 }
 #  define RCU_NODE_NAME_INIT  { "rcu_node_0", "rcu_node_1" }
 #  define RCU_FQS_NAME_INIT   { "rcu_node_fqs_0", "rcu_node_fqs_1" }
@@ -86,8 +81,7 @@
 #  define NUM_RCU_LVL_0	      1
 #  define NUM_RCU_LVL_1	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
 #  define NUM_RCU_LVL_2	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
-#  define NUM_RCU_LVL_3	      (NR_CPUS)
-#  define NUM_RCU_LVL_4	      0
+#  define NUM_RCU_NODES	      (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2)
 #  define NUM_RCU_LVL_INIT    { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2 }
 #  define RCU_NODE_NAME_INIT  { "rcu_node_0", "rcu_node_1", "rcu_node_2" }
 #  define RCU_FQS_NAME_INIT   { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2" }
@@ -97,7 +91,7 @@
 #  define NUM_RCU_LVL_1	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_3)
 #  define NUM_RCU_LVL_2	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_2)
 #  define NUM_RCU_LVL_3	      DIV_ROUND_UP(NR_CPUS, RCU_FANOUT_1)
-#  define NUM_RCU_LVL_4	      (NR_CPUS)
+#  define NUM_RCU_NODES	      (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3)
 #  define NUM_RCU_LVL_INIT    { NUM_RCU_LVL_0, NUM_RCU_LVL_1, NUM_RCU_LVL_2, NUM_RCU_LVL_3 }
 #  define RCU_NODE_NAME_INIT  { "rcu_node_0", "rcu_node_1", "rcu_node_2", "rcu_node_3" }
 #  define RCU_FQS_NAME_INIT   { "rcu_node_fqs_0", "rcu_node_fqs_1", "rcu_node_fqs_2", "rcu_node_fqs_3" }
@@ -105,9 +99,6 @@
 # error "CONFIG_RCU_FANOUT insufficient for NR_CPUS"
 #endif /* #if (NR_CPUS) <= RCU_FANOUT_1 */
 
-#define RCU_SUM (NUM_RCU_LVL_0 + NUM_RCU_LVL_1 + NUM_RCU_LVL_2 + NUM_RCU_LVL_3 + NUM_RCU_LVL_4)
-#define NUM_RCU_NODES (RCU_SUM - NR_CPUS)
-
 extern int rcu_num_lvls;
 extern int rcu_num_nodes;
 
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 013485fb2b06..5dac0a10a985 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -84,8 +84,8 @@ static void __init rcu_bootup_announce_oddness(void)
 		pr_info("\tRCU torture testing starts during boot.\n");
 	if (IS_ENABLED(CONFIG_RCU_CPU_STALL_INFO))
 		pr_info("\tAdditional per-CPU info printed with stalls.\n");
-	if (NUM_RCU_LVL_4 != 0)
-		pr_info("\tFour-level hierarchy is enabled.\n");
+	if (RCU_NUM_LVLS >= 4)
+		pr_info("\tFour(or more)-level hierarchy is enabled.\n");
 	if (RCU_FANOUT_LEAF != 16)
 		pr_info("\tBuild-time adjustment of leaf fanout to %d.\n",
 			RCU_FANOUT_LEAF);
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 11/12] rcu: Shut up bogus gcc array bounds warning
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
                     ` (8 preceding siblings ...)
  2015-07-17 22:31   ` [PATCH tip/core/rcu 10/12] rcu: Simplify arithmetic to calculate number of RCU nodes Paul E. McKenney
@ 2015-07-17 22:31   ` Paul E. McKenney
  2015-07-17 22:31   ` [PATCH tip/core/rcu 12/12] rcu: Reset rcu_fanout_leaf if out of bounds Paul E. McKenney
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Alexander Gordeev, Paul E. McKenney

From: Alexander Gordeev <agordeev@redhat.com>

Because gcc does not realize a loop would not be entered ever
(i.e. in case of rcu_num_lvls == 1):

  for (i = 1; i < rcu_num_lvls; i++)
	  rsp->level[i] = rsp->level[i - 1] + levelcnt[i - 1];

some compiler (pre- 5.x?) versions give a bogus warning:

  kernel/rcu/tree.c: In function ‘rcu_init_one.isra.55’:
  kernel/rcu/tree.c:4108:13: warning: array subscript is above array bounds [-Warray-bounds]
     rsp->level[i] = rsp->level[i - 1] + rsp->levelcnt[i - 1];
               ^
Fix that warning by adding an extra item to rcu_state::level[]
array. Once the bogus warning is fixed in gcc and kernel drops
support of older versions, the dummy item may be removed from
the array.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Suggested-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 581f8d3c5b28..faee5242d6ff 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -443,7 +443,9 @@ do {									\
  */
 struct rcu_state {
 	struct rcu_node node[NUM_RCU_NODES];	/* Hierarchy. */
-	struct rcu_node *level[RCU_NUM_LVLS];	/* Hierarchy levels. */
+	struct rcu_node *level[RCU_NUM_LVLS + 1];
+						/* Hierarchy levels (+1 to */
+						/*  shut bogus gcc warning) */
 	u8 flavor_mask;				/* bit in flavor mask. */
 	struct rcu_data __percpu *rda;		/* pointer of percu rcu_data. */
 	void (*call)(struct rcu_head *head,	/* call_rcu() flavor. */
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH tip/core/rcu 12/12] rcu: Reset rcu_fanout_leaf if out of bounds
  2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
                     ` (9 preceding siblings ...)
  2015-07-17 22:31   ` [PATCH tip/core/rcu 11/12] rcu: Shut up bogus gcc array bounds warning Paul E. McKenney
@ 2015-07-17 22:31   ` Paul E. McKenney
  10 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-17 22:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh,
	tglx, peterz, rostedt, dhowells, edumazet, dvhart, fweisbec,
	oleg, bobby.prani, Paul E. McKenney

From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>

Currently if the rcu_fanout_leaf boot parameter is out of bounds (that
is, less than RCU_FANOUT_LEAF or greater than the number of bits in an
unsigned long), a warning is issued and execution continues with the
out-of-bounds value.  This can result in all manner of failures, so this
patch resets rcu_fanout_leaf to RCU_FANOUT_LEAF when an out-of-bounds
condition is detected.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/tree.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index e53bbc53bcd5..a2147d7b51c0 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -4103,6 +4103,7 @@ static void __init rcu_init_geometry(void)
 	 */
 	if (rcu_fanout_leaf < RCU_FANOUT_LEAF ||
 	    rcu_fanout_leaf > sizeof(unsigned long) * 8) {
+		rcu_fanout_leaf = RCU_FANOUT_LEAF;
 		WARN_ON(1);
 		return;
 	}
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-17 22:30   ` [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs Paul E. McKenney
@ 2015-07-30 12:28     ` Peter Zijlstra
  2015-07-30 15:25       ` Paul E. McKenney
  0 siblings, 1 reply; 21+ messages in thread
From: Peter Zijlstra @ 2015-07-30 12:28 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, rostedt, dhowells, edumazet,
	dvhart, fweisbec, oleg, bobby.prani, Alexander Gordeev

On Fri, Jul 17, 2015 at 03:30:53PM -0700, Paul E. McKenney wrote:
> +	if (n > rcu_capacity[MAX_RCU_LVLS])
> +		panic("rcu_init_geometry: rcu_capacity[] is too small");

How can this ever happen? We _know_ NR_CPUS at compile time, there's no
way we can get more CPUs than that -- even if the hardware has more,
we'll stop enumerating.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-30 12:28     ` Peter Zijlstra
@ 2015-07-30 15:25       ` Paul E. McKenney
  2015-07-30 15:32         ` Peter Zijlstra
  0 siblings, 1 reply; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-30 15:25 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, rostedt, dhowells, edumazet,
	dvhart, fweisbec, oleg, bobby.prani, Alexander Gordeev

On Thu, Jul 30, 2015 at 02:28:35PM +0200, Peter Zijlstra wrote:
> On Fri, Jul 17, 2015 at 03:30:53PM -0700, Paul E. McKenney wrote:
> > +	if (n > rcu_capacity[MAX_RCU_LVLS])
> > +		panic("rcu_init_geometry: rcu_capacity[] is too small");
> 
> How can this ever happen? We _know_ NR_CPUS at compile time, there's no
> way we can get more CPUs than that -- even if the hardware has more,
> we'll stop enumerating.

You can make this happen by building with CONFIG_RCU_FANOUT=2 and
CONFIG_RCU_FANOUT_LEAF=2, then running on a system with more than 16 CPUs.
The kernel boot parameter rcutree.rcu_fanout_leaf=2 can be substituted for
CONFIG_RCU_FANOUT_LEAF=2, hence the need for a runtime test.  I do this
sort of thing for my rcutorture testing in order to test a four-level
rcu_node tree with only 16 CPUs.

							Thanx, Paul


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-30 15:25       ` Paul E. McKenney
@ 2015-07-30 15:32         ` Peter Zijlstra
  2015-07-30 15:34           ` Peter Zijlstra
  2015-07-30 15:54           ` Paul E. McKenney
  0 siblings, 2 replies; 21+ messages in thread
From: Peter Zijlstra @ 2015-07-30 15:32 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, rostedt, dhowells, edumazet,
	dvhart, fweisbec, oleg, bobby.prani, Alexander Gordeev

On Thu, Jul 30, 2015 at 08:25:17AM -0700, Paul E. McKenney wrote:
> On Thu, Jul 30, 2015 at 02:28:35PM +0200, Peter Zijlstra wrote:
> > On Fri, Jul 17, 2015 at 03:30:53PM -0700, Paul E. McKenney wrote:
> > > +	if (n > rcu_capacity[MAX_RCU_LVLS])
> > > +		panic("rcu_init_geometry: rcu_capacity[] is too small");
> > 
> > How can this ever happen? We _know_ NR_CPUS at compile time, there's no
> > way we can get more CPUs than that -- even if the hardware has more,
> > we'll stop enumerating.
> 
> You can make this happen by building with CONFIG_RCU_FANOUT=2 and
> CONFIG_RCU_FANOUT_LEAF=2, then running on a system with more than 16 CPUs.
> The kernel boot parameter rcutree.rcu_fanout_leaf=2 can be substituted for
> CONFIG_RCU_FANOUT_LEAF=2, hence the need for a runtime test.  I do this
> sort of thing for my rcutorture testing in order to test a four-level
> rcu_node tree with only 16 CPUs.

How about we make the build fail if NR_CPUS exceeds that maximum fanout?

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-30 15:32         ` Peter Zijlstra
@ 2015-07-30 15:34           ` Peter Zijlstra
  2015-07-30 16:01             ` Paul E. McKenney
  2015-07-30 15:54           ` Paul E. McKenney
  1 sibling, 1 reply; 21+ messages in thread
From: Peter Zijlstra @ 2015-07-30 15:34 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, rostedt, dhowells, edumazet,
	dvhart, fweisbec, oleg, bobby.prani, Alexander Gordeev

On Thu, Jul 30, 2015 at 05:32:51PM +0200, Peter Zijlstra wrote:
> On Thu, Jul 30, 2015 at 08:25:17AM -0700, Paul E. McKenney wrote:
> > On Thu, Jul 30, 2015 at 02:28:35PM +0200, Peter Zijlstra wrote:
> > > On Fri, Jul 17, 2015 at 03:30:53PM -0700, Paul E. McKenney wrote:
> > > > +	if (n > rcu_capacity[MAX_RCU_LVLS])
> > > > +		panic("rcu_init_geometry: rcu_capacity[] is too small");
> > > 
> > > How can this ever happen? We _know_ NR_CPUS at compile time, there's no
> > > way we can get more CPUs than that -- even if the hardware has more,
> > > we'll stop enumerating.
> > 
> > You can make this happen by building with CONFIG_RCU_FANOUT=2 and
> > CONFIG_RCU_FANOUT_LEAF=2, then running on a system with more than 16 CPUs.
> > The kernel boot parameter rcutree.rcu_fanout_leaf=2 can be substituted for
> > CONFIG_RCU_FANOUT_LEAF=2, hence the need for a runtime test.  I do this
> > sort of thing for my rcutorture testing in order to test a four-level
> > rcu_node tree with only 16 CPUs.
> 
> How about we make the build fail if NR_CPUS exceeds that maximum fanout?

Or better yet, auto-select these numbers based on NR_CPUS and remove the
configs.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-30 15:32         ` Peter Zijlstra
  2015-07-30 15:34           ` Peter Zijlstra
@ 2015-07-30 15:54           ` Paul E. McKenney
  2015-07-30 16:22             ` Peter Zijlstra
  1 sibling, 1 reply; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-30 15:54 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, rostedt, dhowells, edumazet,
	dvhart, fweisbec, oleg, bobby.prani, Alexander Gordeev

On Thu, Jul 30, 2015 at 05:32:51PM +0200, Peter Zijlstra wrote:
> On Thu, Jul 30, 2015 at 08:25:17AM -0700, Paul E. McKenney wrote:
> > On Thu, Jul 30, 2015 at 02:28:35PM +0200, Peter Zijlstra wrote:
> > > On Fri, Jul 17, 2015 at 03:30:53PM -0700, Paul E. McKenney wrote:
> > > > +	if (n > rcu_capacity[MAX_RCU_LVLS])
> > > > +		panic("rcu_init_geometry: rcu_capacity[] is too small");
> > > 
> > > How can this ever happen? We _know_ NR_CPUS at compile time, there's no
> > > way we can get more CPUs than that -- even if the hardware has more,
> > > we'll stop enumerating.
> > 
> > You can make this happen by building with CONFIG_RCU_FANOUT=2 and
> > CONFIG_RCU_FANOUT_LEAF=2, then running on a system with more than 16 CPUs.
> > The kernel boot parameter rcutree.rcu_fanout_leaf=2 can be substituted for
> > CONFIG_RCU_FANOUT_LEAF=2, hence the need for a runtime test.  I do this
> > sort of thing for my rcutorture testing in order to test a four-level
> > rcu_node tree with only 16 CPUs.
> 
> How about we make the build fail if NR_CPUS exceeds that maximum fanout?

Good point, and it already does, and I clearly was confused, apologies.

So the real way to make this happen is (for example) to build
with CONFIG_RCU_FANOUT=2 and CONFIG_RCU_FANOUT_LEAF=16 (the
default), which could accommodate up to 128 CPUs.  Then boot with
rcutree.rcu_fanout_leaf=2 on a system with more than 16 CPUs, with
rcutree.rcu_fanout_leaf=3 on a system with more than 24 CPUs, and so on.

Of course, the truly macho way to get this error message is to build
with CONFIG_RCU_FANOUT=64 and CONFIG_RCU_FANOUT_LEAF=64, then boot with
rcutree.rcu_fanout_leaf=63 on a system with more than 16,515,072 CPUs.
Of course, you get serious style points if the system manages to stay
up for more than 24 hours without a hardware failure.  ;-)

							Thanx, Paul


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-30 15:34           ` Peter Zijlstra
@ 2015-07-30 16:01             ` Paul E. McKenney
  0 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-30 16:01 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, rostedt, dhowells, edumazet,
	dvhart, fweisbec, oleg, bobby.prani, Alexander Gordeev

On Thu, Jul 30, 2015 at 05:34:24PM +0200, Peter Zijlstra wrote:
> On Thu, Jul 30, 2015 at 05:32:51PM +0200, Peter Zijlstra wrote:
> > On Thu, Jul 30, 2015 at 08:25:17AM -0700, Paul E. McKenney wrote:
> > > On Thu, Jul 30, 2015 at 02:28:35PM +0200, Peter Zijlstra wrote:
> > > > On Fri, Jul 17, 2015 at 03:30:53PM -0700, Paul E. McKenney wrote:
> > > > > +	if (n > rcu_capacity[MAX_RCU_LVLS])
> > > > > +		panic("rcu_init_geometry: rcu_capacity[] is too small");
> > > > 
> > > > How can this ever happen? We _know_ NR_CPUS at compile time, there's no
> > > > way we can get more CPUs than that -- even if the hardware has more,
> > > > we'll stop enumerating.
> > > 
> > > You can make this happen by building with CONFIG_RCU_FANOUT=2 and
> > > CONFIG_RCU_FANOUT_LEAF=2, then running on a system with more than 16 CPUs.
> > > The kernel boot parameter rcutree.rcu_fanout_leaf=2 can be substituted for
> > > CONFIG_RCU_FANOUT_LEAF=2, hence the need for a runtime test.  I do this
> > > sort of thing for my rcutorture testing in order to test a four-level
> > > rcu_node tree with only 16 CPUs.
> > 
> > How about we make the build fail if NR_CPUS exceeds that maximum fanout?
> 
> Or better yet, auto-select these numbers based on NR_CPUS and remove the
> configs.

The current strategy is to default CONFIG_RCU_FANOUT to 32 on 32-bit
systems and to 64 on 64-bit systems, and to default CONFIG_RCU_FANOUT_LEAF
to 16.  This accommodates up to 4,194,304 CPUs, which should be enough
for anyone (famous last words!).  At boot time, RCU automatically shrinks
its combining tree based on the value of nr_cpu_ids.  So the overall
effect is that very few people should need to mess with these RCU
parameters.

The purpose of the CONFIG_RCU_FANOUT_LEAF=16 default is to keep
lock contention down to a dull roar on systems that deliver the
scheduling-clock interrupts simultaneously across all CPUs, and you should
boot with skew_tick if you want to set CONFIG_RCU_FANOUT_LEAF larger.

							Thanx, Paul


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-30 15:54           ` Paul E. McKenney
@ 2015-07-30 16:22             ` Peter Zijlstra
  2015-07-31 15:53               ` Paul E. McKenney
  0 siblings, 1 reply; 21+ messages in thread
From: Peter Zijlstra @ 2015-07-30 16:22 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, rostedt, dhowells, edumazet,
	dvhart, fweisbec, oleg, bobby.prani, Alexander Gordeev

On Thu, Jul 30, 2015 at 08:54:54AM -0700, Paul E. McKenney wrote:

> Good point, and it already does, and I clearly was confused, apologies.
> 
> So the real way to make this happen is (for example) to build
> with CONFIG_RCU_FANOUT=2 and CONFIG_RCU_FANOUT_LEAF=16 (the
> default), which could accommodate up to 128 CPUs.  Then boot with
> rcutree.rcu_fanout_leaf=2 on a system with more than 16 CPUs, with
> rcutree.rcu_fanout_leaf=3 on a system with more than 24 CPUs, and so on.

Ah, runtime overrides and operator error, but then we can WARN(), reset
the arguments and try again, right? No need to panic the machine and
fail to boot.

> Of course, the truly macho way to get this error message is to build
> with CONFIG_RCU_FANOUT=64 and CONFIG_RCU_FANOUT_LEAF=64, then boot with
> rcutree.rcu_fanout_leaf=63 on a system with more than 16,515,072 CPUs.
> Of course, you get serious style points if the system manages to stay
> up for more than 24 hours without a hardware failure.  ;-)

Yes, I'll go power up the nuclear reactor in the basement first :-)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs
  2015-07-30 16:22             ` Peter Zijlstra
@ 2015-07-31 15:53               ` Paul E. McKenney
  0 siblings, 0 replies; 21+ messages in thread
From: Paul E. McKenney @ 2015-07-31 15:53 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, rostedt, dhowells, edumazet,
	dvhart, fweisbec, oleg, bobby.prani, Alexander Gordeev

On Thu, Jul 30, 2015 at 06:22:02PM +0200, Peter Zijlstra wrote:
> On Thu, Jul 30, 2015 at 08:54:54AM -0700, Paul E. McKenney wrote:
> 
> > Good point, and it already does, and I clearly was confused, apologies.
> > 
> > So the real way to make this happen is (for example) to build
> > with CONFIG_RCU_FANOUT=2 and CONFIG_RCU_FANOUT_LEAF=16 (the
> > default), which could accommodate up to 128 CPUs.  Then boot with
> > rcutree.rcu_fanout_leaf=2 on a system with more than 16 CPUs, with
> > rcutree.rcu_fanout_leaf=3 on a system with more than 24 CPUs, and so on.
> 
> Ah, runtime overrides and operator error, but then we can WARN(), reset
> the arguments and try again, right? No need to panic the machine and
> fail to boot.

Good point, like the patch below?  Which also legitimizes my
example after the fact, as it previously simply prohibited having
rcutree.rcu_fanout_leaf less than CONFIG_RCU_FANOUT_LEAF.  :-/

> > Of course, the truly macho way to get this error message is to build
> > with CONFIG_RCU_FANOUT=64 and CONFIG_RCU_FANOUT_LEAF=64, then boot with
> > rcutree.rcu_fanout_leaf=63 on a system with more than 16,515,072 CPUs.
> > Of course, you get serious style points if the system manages to stay
> > up for more than 24 hours without a hardware failure.  ;-)
> 
> Yes, I'll go power up the nuclear reactor in the basement first :-)

Only one?  ;-)

							Thanx, Paul

------------------------------------------------------------------------

    rcu: Eliminate panic when silly boot-time fanout specified
    
    This commit loosens rcutree.rcu_fanout_leaf range checks
    and replaces a panic() with a fallback to compile-time values.
    This fallback is accompanied by a WARN_ON(), and both occur when the
    rcutree.rcu_fanout_leaf value is too small to accommodate the number of
    CPUs.  For example, given the current four-level limit for the rcu_node
    tree, a system with more than 16 CPUs built with CONFIG_FANOUT=2 must
    have rcutree.rcu_fanout_leaf larger than 2.
    
    Reported-by: Peter Zijlstra <peterz@infradead.org>
    Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 01b5b68a237a..2a5d4696bdb9 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3059,9 +3059,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			cache-to-cache transfer latencies.
 
 	rcutree.rcu_fanout_leaf= [KNL]
-			Increase the number of CPUs assigned to each
-			leaf rcu_node structure.  Useful for very large
-			systems.
+			Change the number of CPUs assigned to each
+			leaf rcu_node structure.  Useful for very
+			large systems, which will choose the value 64,
+			and for NUMA systems with large remote-access
+			latencies, which will choose a value aligned
+			with the appropriate hardware boundaries.
 
 	rcutree.jiffies_till_sched_qs= [KNL]
 			Set required age in jiffies for a
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index ce43fac5ff91..9f8040396d3e 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -4216,13 +4216,12 @@ static void __init rcu_init_geometry(void)
 		rcu_fanout_leaf, nr_cpu_ids);
 
 	/*
-	 * The boot-time rcu_fanout_leaf parameter is only permitted
-	 * to increase the leaf-level fanout, not decrease it.  Of course,
-	 * the leaf-level fanout cannot exceed the number of bits in
-	 * the rcu_node masks.  Complain and fall back to the compile-
-	 * time values if these limits are exceeded.
+	 * The boot-time rcu_fanout_leaf parameter must be at least two
+	 * and cannot exceed the number of bits in the rcu_node masks.
+	 * Complain and fall back to the compile-time values if this
+	 * limit is exceeded.
 	 */
-	if (rcu_fanout_leaf < RCU_FANOUT_LEAF ||
+	if (rcu_fanout_leaf < 2 ||
 	    rcu_fanout_leaf > sizeof(unsigned long) * 8) {
 		rcu_fanout_leaf = RCU_FANOUT_LEAF;
 		WARN_ON(1);
@@ -4239,10 +4238,13 @@ static void __init rcu_init_geometry(void)
 
 	/*
 	 * The tree must be able to accommodate the configured number of CPUs.
-	 * If this limit is exceeded than we have a serious problem elsewhere.
+	 * If this limit is exceeded, fall back to the compile-time values.
 	 */
-	if (nr_cpu_ids > rcu_capacity[RCU_NUM_LVLS - 1])
-		panic("rcu_init_geometry: rcu_capacity[] is too small");
+	if (nr_cpu_ids > rcu_capacity[RCU_NUM_LVLS - 1]) {
+		rcu_fanout_leaf = RCU_FANOUT_LEAF;
+		WARN_ON(1);
+		return;
+	}
 
 	/* Calculate the number of levels in the tree. */
 	for (i = 0; nr_cpu_ids > rcu_capacity[i]; i++) {


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2015-07-31 15:53 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-17 22:30 [PATCH tip/core/rcu 0/12] Tree geometry-initialization simplifications for 4.3 Paul E. McKenney
2015-07-17 22:30 ` [PATCH tip/core/rcu 01/12] rcu: Provide more diagnostics for stalled GP kthread Paul E. McKenney
2015-07-17 22:30   ` [PATCH tip/core/rcu 02/12] rcu: Panic if RCU tree can not accommodate all CPUs Paul E. McKenney
2015-07-30 12:28     ` Peter Zijlstra
2015-07-30 15:25       ` Paul E. McKenney
2015-07-30 15:32         ` Peter Zijlstra
2015-07-30 15:34           ` Peter Zijlstra
2015-07-30 16:01             ` Paul E. McKenney
2015-07-30 15:54           ` Paul E. McKenney
2015-07-30 16:22             ` Peter Zijlstra
2015-07-31 15:53               ` Paul E. McKenney
2015-07-17 22:30   ` [PATCH tip/core/rcu 03/12] rcu: Remove superfluous local variable in rcu_init_geometry() Paul E. McKenney
2015-07-17 22:30   ` [PATCH tip/core/rcu 04/12] rcu: Cleanup rcu_init_geometry() code and arithmetics Paul E. McKenney
2015-07-17 22:30   ` [PATCH tip/core/rcu 05/12] rcu: Simplify rcu_init_geometry() capacity arithmetics Paul E. McKenney
2015-07-17 22:30   ` [PATCH tip/core/rcu 06/12] rcu: Limit rcu_state::levelcnt[] to RCU_NUM_LVLS items Paul E. McKenney
2015-07-17 22:30   ` [PATCH tip/core/rcu 07/12] rcu: Limit rcu_capacity[] size " Paul E. McKenney
2015-07-17 22:30   ` [PATCH tip/core/rcu 08/12] rcu: Remove unnecessary fields from rcu_state structure Paul E. McKenney
2015-07-17 22:31   ` [PATCH tip/core/rcu 09/12] rcu: Limit count of static data to the number of RCU levels Paul E. McKenney
2015-07-17 22:31   ` [PATCH tip/core/rcu 10/12] rcu: Simplify arithmetic to calculate number of RCU nodes Paul E. McKenney
2015-07-17 22:31   ` [PATCH tip/core/rcu 11/12] rcu: Shut up bogus gcc array bounds warning Paul E. McKenney
2015-07-17 22:31   ` [PATCH tip/core/rcu 12/12] rcu: Reset rcu_fanout_leaf if out of bounds Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).