Skip to contentSkip to conversation

rcu: Speed up calling of RCU tasks callbacks

PATCH Applied Steven Rostedt 4 participants 6 messages May 24, 2018 – May 25, 2018 RCU

lore
Share & tools
lore

Steven Rostedt

author reviewer
#0 lore raw

PATCH v4 1/1 rcu: Speed up calling of RCU tasks callbacks

From: Steven Rostedt (VMware) <[email protected]>

Joel Fernandes found that the synchronize_rcu_tasks() was taking a significant amount of time. He demonstrated it with the following test:

 # cd /sys/kernel/tracing
 # while [ 1 ]; do x=1; done &
 # echo '__schedule_bug:traceon' > set_ftrace_filter
 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m1.064s
user 0m0.000s
sys 0m0.004s

Where it takes a little over a second to perform the synchronize, because there's a loop that waits 1 second at a time for tasks to get through their quiescent points when there's a task that must be waited for.

After discussion we came up with a simple way to wait for holdouts but increase the time for each iteration of the loop but no more than a full second.

With the new patch we have:

 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m0.131s
user 0m0.000s
sys 0m0.004s

Which drops it down to 13% of what the original wait time was.

---

kernel/rcu/update.c +15 -2
index 68fa19a5e7bd..452e47841a86 100644
@@ -715,6 +715,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
 	struct rcu_head *list;
 	struct rcu_head *next;
 	LIST_HEAD(rcu_tasks_holdouts);
+	int fract;
 
 	/* Run on housekeeping CPUs by default.  Sysadm can move if desired. */
 	housekeeping_affine(current, HK_FLAG_RCU);
@@ -796,13 +797,25 @@ static int __noreturn rcu_tasks_kthread(void *arg)
 		 * holdouts.  When the list is empty, we are done.
 		 */
 		lastreport = jiffies;
-		while (!list_empty(&rcu_tasks_holdouts)) {
+
+		/* Start off with HZ/10 wait and slowly back off to 1 HZ wait*/
+		fract = 10;
+
+		for (;;) {
 			bool firstreport;
 			bool needreport;
 			int rtst;
 			struct task_struct *t1;
 
-			schedule_timeout_interruptible(HZ);
+			if (list_empty(&rcu_tasks_holdouts))
+				break;
+
+			/* Slowly back off waiting for holdouts */
+			schedule_timeout_interruptible(HZ/fract);
+
+			if (fract > 1)
+				fract--;
+
 			rtst = READ_ONCE(rcu_task_stall_timeout);
 			needreport = rtst > 0 &&
 				     time_after(jiffies, lastreport + rtst);
Reviewed-by on v4 1/1
#1 lore raw
Quoted 26 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

Joel Fernandes found that the synchronize_rcu_tasks() was taking a significant amount of time. He demonstrated it with the following test:

 # cd /sys/kernel/tracing
 # while [ 1 ]; do x=1; done &
 # echo '__schedule_bug:traceon' > set_ftrace_filter
 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m1.064s
user 0m0.000s
sys 0m0.004s

Where it takes a little over a second to perform the synchronize, because there's a loop that waits 1 second at a time for tasks to get through their quiescent points when there's a task that must be waited for.

After discussion we came up with a simple way to wait for holdouts but increase the time for each iteration of the loop but no more than a full second.

With the new patch we have:

Quoted 7 lines
 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m0.131s
user 0m0.000s
sys 0m0.004s

Which drops it down to 13% of what the original wait time was.

Should be 90% of original?

Quoted 33 lines

---

kernel/rcu/update.c +6 -1
index 68fa19a5e7bd..452e47841a86 100644
@@ -715,6 +715,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
 	struct rcu_head *list;
 	struct rcu_head *next;
 	LIST_HEAD(rcu_tasks_holdouts);
+	int fract;
 
 	/* Run on housekeeping CPUs by default.  Sysadm can move if desired. */
 	housekeeping_affine(current, HK_FLAG_RCU);
@@ -796,13 +797,25 @@ static int __noreturn rcu_tasks_kthread(void *arg)
 		 * holdouts.  When the list is empty, we are done.
 		 */
 		lastreport = jiffies;
-		while (!list_empty(&rcu_tasks_holdouts)) {
+
+		/* Start off with HZ/10 wait and slowly back off to 1 HZ wait*/
+		fract = 10;
+
+		for (;;) {
 			bool firstreport;
 			bool needreport;
 			int rtst;
 			struct task_struct *t1;
 

kernel/rcu/update.c static int __noreturn rcu_tasks_kthread(void *arg) · line 818

Quoted 10 lines
kernel/rcu/update.c +9 -1
-			schedule_timeout_interruptible(HZ);
+			if (list_empty(&rcu_tasks_holdouts))
+				break;
+
+			/* Slowly back off waiting for holdouts */
+			schedule_timeout_interruptible(HZ/fract);
+
+			if (fract > 1)
+				fract--;
+

Other than minor change log change, looks good to me:

thanks,

- Joel

author reviewer
#2 lore raw
Quoted 29 lines · On Thu, 24 May 2018 16:19:18 -0700 Joel Fernandes <[email protected]>…
Quoted 28 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

Joel Fernandes found that the synchronize_rcu_tasks() was taking a significant amount of time. He demonstrated it with the following test:

 # cd /sys/kernel/tracing
 # while [ 1 ]; do x=1; done &
 # echo '__schedule_bug:traceon' > set_ftrace_filter
 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m1.064s
user 0m0.000s
sys 0m0.004s

Where it takes a little over a second to perform the synchronize, because there's a loop that waits 1 second at a time for tasks to get through their quiescent points when there's a task that must be waited for.

After discussion we came up with a simple way to wait for holdouts but increase the time for each iteration of the loop but no more than a full second.

With the new patch we have:

 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;
Quoted 7 lines
Quoted 5 lines

real 0m0.131s
user 0m0.000s
sys 0m0.004s

Which drops it down to 13% of what the original wait time was.

Should be 90% of original?

That would be if I said "drops it down X" but I said "drops it down to X of what the original wait time was". And 0.131 is 13% of 1.064. :-)

Quoted 3 lines

Other than minor change log change, looks good to me:

Awesome, thanks!

-- Steve

#3 lore raw
Quoted 36 lines · Steven Rostedt
Quoted 33 lines · On Thu, 24 May 2018 16:19:18 -0700 Joel Fernandes <[email protected]>…
Quoted 32 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

Joel Fernandes found that the synchronize_rcu_tasks() was taking a significant amount of time. He demonstrated it with the following test:

 # cd /sys/kernel/tracing
 # while [ 1 ]; do x=1; done &
 # echo '__schedule_bug:traceon' > set_ftrace_filter
 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m1.064s
user 0m0.000s
sys 0m0.004s

Where it takes a little over a second to perform the synchronize, because there's a loop that waits 1 second at a time for tasks to get through their quiescent points when there's a task that must be waited for.

After discussion we came up with a simple way to wait for holdouts but increase the time for each iteration of the loop but no more than a full second.

With the new patch we have:

 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m0.131s
user 0m0.000s
sys 0m0.004s

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Which drops it down to 13% of what the original wait time was.

Should be 90% of original?

That would be if I said "drops it down X" but I said "drops it down to X of what the original wait time was". And 0.131 is 13% of 1.064. :-)

I think that you are confusing "drops it down to" with "drops it down by". You said the former. You should say the latter.
IOW, I agree with Joel.

Quoted 8 lines
Quoted 3 lines

Other than minor change log change, looks good to me:

Awesome, thanks!

-- Steve

Signature · 1 line
~Randy
#4 lore raw
Quoted 39 lines · Randy Dunlap
Quoted 38 lines · Steven Rostedt
Quoted 35 lines · On Thu, 24 May 2018 16:19:18 -0700 Joel Fernandes <[email protected]>…
Quoted 33 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

Joel Fernandes found that the synchronize_rcu_tasks() was taking a significant amount of time. He demonstrated it with the following test:

 # cd /sys/kernel/tracing
 # while [ 1 ]; do x=1; done &
 # echo '__schedule_bug:traceon' > set_ftrace_filter
 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m1.064s
user 0m0.000s
sys 0m0.004s

Where it takes a little over a second to perform the synchronize, because there's a loop that waits 1 second at a time for tasks to get through their quiescent points when there's a task that must be waited for.

After discussion we came up with a simple way to wait for holdouts but increase the time for each iteration of the loop but no more than a full second.

With the new patch we have:

 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m0.131s
user 0m0.000s
sys 0m0.004s

Which drops it down to 13% of what the original wait time was.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Should be 90% of original?

That would be if I said "drops it down X" but I said "drops it down to X of what the original wait time was". And 0.131 is 13% of 1.064. :-)

I think that you are confusing "drops it down to" with "drops it down by". You said the former. You should say the latter.
IOW, I agree with Joel.

Please forget this. After reading the numbers, your comments look correct.

Signature · 1 line
~Randy
#5 lore raw
In reply to Steven Rostedt
Quoted 32 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

Joel Fernandes found that the synchronize_rcu_tasks() was taking a significant amount of time. He demonstrated it with the following test:

 # cd /sys/kernel/tracing
 # while [ 1 ]; do x=1; done &
 # echo '__schedule_bug:traceon' > set_ftrace_filter
 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m1.064s
user 0m0.000s
sys 0m0.004s

Where it takes a little over a second to perform the synchronize, because there's a loop that waits 1 second at a time for tasks to get through their quiescent points when there's a task that must be waited for.

After discussion we came up with a simple way to wait for holdouts but increase the time for each iteration of the loop but no more than a full second.

With the new patch we have:

 # time echo '!__schedule_bug:traceon' > set_ftrace_filter;

real 0m0.131s
user 0m0.000s
sys 0m0.004s

Quoted 6 lines

Which drops it down to 13% of what the original wait time was.

I queued both commits, thank you all!

Thanx, Paul

Quoted 42 lines

---

kernel/rcu/update.c +15 -2
index 68fa19a5e7bd..452e47841a86 100644
@@ -715,6 +715,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
 	struct rcu_head *list;
 	struct rcu_head *next;
 	LIST_HEAD(rcu_tasks_holdouts);
+	int fract;
 
 	/* Run on housekeeping CPUs by default.  Sysadm can move if desired. */
 	housekeeping_affine(current, HK_FLAG_RCU);
@@ -796,13 +797,25 @@ static int __noreturn rcu_tasks_kthread(void *arg)
 		 * holdouts.  When the list is empty, we are done.
 		 */
 		lastreport = jiffies;
-		while (!list_empty(&rcu_tasks_holdouts)) {
+
+		/* Start off with HZ/10 wait and slowly back off to 1 HZ wait*/
+		fract = 10;
+
+		for (;;) {
 			bool firstreport;
 			bool needreport;
 			int rtst;
 			struct task_struct *t1;
 
-			schedule_timeout_interruptible(HZ);
+			if (list_empty(&rcu_tasks_holdouts))
+				break;
+
+			/* Slowly back off waiting for holdouts */
+			schedule_timeout_interruptible(HZ/fract);
+
+			if (fract > 1)
+				fract--;
+
 			rtst = READ_ONCE(rcu_task_stall_timeout);
 			needreport = rtst > 0 &&
 				     time_after(jiffies, lastreport + rtst);