synchronize_rcu(): high latency on idle system
Subsystems (4)
Hello folks,
I'd like to put the patch below out for comments to see if folks think the approach is a valid fix to reduce the latency of synchronize_rcu(). The motivation is that an otherwise idle system takes about 3 ticks per network interface in unregister_netdev() due to multiple calls to synchronize_rcu(), which adds up to quite a few seconds for tearing down thousands of interfaces. By flushing pending rcu callbacks in the idle loop, the system makes progress hundreds of times faster. If this is indeed a sane thing to, it probably needs to be done for other architectures than x86. And yes, the network stack shouldn't call synchronize_rcu() quite so much, but fixing that is a little more involved.
-ben
arch/x86/kernel/process_32.c +3 -0
@@ -188,6 +188,9 @@ void cpu_idle(void)rmb (); idle = pm_idle; +if (rcu_pending (cpu)) +rcu_check_callbacks (cpu,0 ); +if (!idle) idle = default_idle;
Quoted 3 lines
And yes, the
network stack shouldn't callsynchronize_rcu()quite so much, but fixing that is a little more involved.
... but the correct solution.
-Andi
Quoted 12 lines · Benjamin LaHaise
Hello folks,
I'd like to put the patch below out for comments to see if folks think the approach is a valid fix to reduce the latency of
synchronize_rcu(). The motivation is that an otherwise idle system takes about 3 ticks per network interface inunregister_netdev()due to multiple calls tosynchronize_rcu(), which adds up to quite a few seconds for tearing down thousands of interfaces. By flushing pending rcu callbacks in the idle loop, the system makes progress hundreds of times faster. If this is indeed a sane thing to, it probably needs to be done for other architectures than x86. And yes, the network stack shouldn't callsynchronize_rcu()quite so much, but fixing that is a little more involved.
So, instead of only relying on the tick to drive the RCU state machine, you add the idle loop to it. This seems to make sense, esp because nohz is held off until rcu is idle too.
Even though Andi is right in that its not the proper solution to your problem, I think its worth doing anyway for the general benefit of RCU.
But lets ask Paul, he is Mr RCU after all :-)
Quoted 14 lines
arch/x86/kernel/process_32.c +3
-0@@ -188,6 +188,9 @@ void cpu_idle(void)rmb (); idle = pm_idle; +if (rcu_pending (cpu)) +rcu_check_callbacks (cpu,0 ); +if (!idle) idle = default_idle;
Quoted 15 lines · Peter Zijlstra
Quoted 12 lines · Benjamin LaHaise
Hello folks,
I'd like to put the patch below out for comments to see if folks think the approach is a valid fix to reduce the latency of
synchronize_rcu(). The motivation is that an otherwise idle system takes about 3 ticks per network interface inunregister_netdev()due to multiple calls tosynchronize_rcu(), which adds up to quite a few seconds for tearing down thousands of interfaces. By flushing pending rcu callbacks in the idle loop, the system makes progress hundreds of times faster. If this is indeed a sane thing to, it probably needs to be done for other architectures than x86. And yes, the network stack shouldn't callsynchronize_rcu()quite so much, but fixing that is a little more involved.
Quoted 8 lines
So, instead of only relying on the tick to drive the RCU state machine, you add the idle loop to it. This seems to make sense, esp because nohz is held off until rcu is idle too.
Even though Andi is right in that its not the proper solution to your problem, I think its worth doing anyway for the general benefit of RCU.
But lets ask Paul, he is Mr RCU after all :-)
;-)
At first glance, looks workable!
One concern is how often it gets invoked. If rcu_check_callbacks() is invoked too often on lots of idle CPUs, it could degrade system performance due to contention on the RCU internal locks and due to cacheline bouncing. Now, my guess is that the rcu_pending() call should throttle things nicely, but it would be good to test. All the testing ideas thus far have been involved and unlikely to test it well, for example:
CPU 0: lots of synchronize_rcu() calls.
CPU 1: lots of synchronize_rcu() calls.
CPU 2: idle.
CPU 3: CPU-bound workload.
Compare the rate of progress made by CPU 3 with CPUs 0 and 1 active or not. But this would not test much -- the load that CPUs 0, 1, and 2 might be placing on the bus/cache/RCU-locks would not be visible to CPU 3. One could cache-thrash between CPU 3 and 4, but this requires a >=5-CPU system.
Will think on it some more.
Quoted 10 lines
arch/x86/kernel/process_32.c void cpu_idle(void) · line 192
Quoted 10 lines
arch/x86/kernel/process_32.c +2
-0@@ -188,6 +188,9 @@ void cpu_idle(void)rmb (); idle = pm_idle; +if (rcu_pending (cpu)) +rcu_check_callbacks (cpu,0 );
Given that it is not legal to have RCU read-side critical sections in the idle loop, how about the following?
+ rcu_check_callbacks(cpu, 1);
Perhaps also changing the name of rcu_check_callbacks()'s second parameter from "user" to something like "in_quiescent_state". Might speed up grace-period recognition in some cases -- wouldn't need to wait for the next trip through the scheduler in some cases.
Thanx, Paul
Quoted 5 lines
Quoted 4 lines
arch/x86/kernel/process_32.c +1
-0+if (!idle) idle = default_idle;
Quoted 15 lines · On Saturday 12 January 2008 10:23:11 Peter Zijlstra wrote:
Quoted 12 lines · Benjamin LaHaise
Hello folks,
I'd like to put the patch below out for comments to see if folks think the approach is a valid fix to reduce the latency of
synchronize_rcu(). The motivation is that an otherwise idle system takes about 3 ticks per network interface inunregister_netdev()due to multiple calls tosynchronize_rcu(), which adds up to quite a few seconds for tearing down thousands of interfaces. By flushing pending rcu callbacks in the idle loop, the system makes progress hundreds of times faster. If this is indeed a sane thing to, it probably needs to be done for other architectures than x86. And yes, the network stack shouldn't callsynchronize_rcu()quite so much, but fixing that is a little more involved.
Quoted 3 lines
So, instead of only relying on the tick to drive the RCU state machine, you add the idle loop to it. This seems to make sense, esp because nohz is held off until rcu is idle too.
For NOHZ I agree it would be probably better to just force a quiescent cycle than to schedule a one jiffie tick like it is currently done.
For non NOHZ I'm not so sure.
-Andi
Quoted 5 lines · Andi Kleen
Quoted 3 lines
And yes, the
network stack shouldn't callsynchronize_rcu()quite so much, but fixing that is a little more involved.... but the correct solution.
There has to be at least 1 synchronize_rcu() or equivalent in the unregister_netdev() path. I suspect the easiest way to fix it might be to use call_rcu() to actually free the network device, as anything else will limit performance of single threaded teardown (ie, when an l2tp daemon gets terminated via kill -9). This means an API change that exposes rcu for unregister_netdev().
-ben
Signature · 2 lines
"Time is of no importance, Mr. President, only life is important." Don't Email: <[email protected]>.
Quoted 5 lines · On Saturday 12 January 2008 18:51:35 Benjamin LaHaise wrote:
Quoted 4 lines · Andi Kleen
Quoted 3 lines
And yes, the
network stack shouldn't callsynchronize_rcu()quite so much, but fixing that is a little more involved.
Quoted 8 lines
Quoted 1 line
... but the correct solution.
There has to be at least 1
synchronize_rcu()or equivalent in theunregister_netdev()path. I suspect the easiest way to fix it might be to usecall_rcu()to actually free the network device, as anything else will limit performance of single threaded teardown (ie, when an l2tp daemon gets terminated via kill -9). This means an API change that exposes rcu forunregister_netdev().
The call_rcu() could be in free_netdev() couldn't it?
-Andi
Quoted 8 lines · On Sat, 12 Jan 2008 19:35:58 +0100 Andi Kleen <[email protected]> wrote:
Quoted 7 lines · On Saturday 12 January 2008 18:51:35 Benjamin LaHaise wrote:
Quoted 5 lines · Andi Kleen
Quoted 3 lines
And yes, the
network stack shouldn't callsynchronize_rcu()quite so much, but fixing that is a little more involved.... but the correct solution.
Quoted 8 lines
Quoted 6 lines
There has to be at least 1
synchronize_rcu()or equivalent in theunregister_netdev()path. I suspect the easiest way to fix it might be to usecall_rcu()to actually free the network device, as anything else will limit performance of single threaded teardown (ie, when an l2tp daemon gets terminated via kill -9). This means an API change that exposes rcu forunregister_netdev().The
call_rcu()could be infree_netdev()couldn't it?
I think it should be in netdev_unregister_kobject(). But that would only get rid of one of the two calls to synchronize_rcu() in the unregister_netdev. The other synchronize_rcu() is for qdisc's and not sure if that one can be removed?
Signature · 1 line
Stephen Hemminger <[email protected]>
Quoted 3 lines
I think it should be in
netdev_unregister_kobject(). But that would only get rid of one of the two calls tosynchronize_rcu()in theunregister_netdev.
Would be already an improvement.
Quoted 2 lines
The other
synchronize_rcu()is for qdisc's and not sure if that one can be removed?
The standard way to remove such calls is to set a "deleted" flag in the object, then check and ignore such objects in the reader and finally remove the object with call_rcu
I have not checked if that is really feasible for qdiscs.
-Andi
Quoted 9 lines · On Sun, 13 Jan 2008 16:34:17 +0100 Andi Kleen <[email protected]> wrote:
Quoted 3 lines
I think it should be in
netdev_unregister_kobject(). But that would only get rid of one of the two calls tosynchronize_rcu()in theunregister_netdev.Would be already an improvement.
Quoted 2 lines
The other
synchronize_rcu()is for qdisc's and not sure if that one can be removed?
Quoted 7 lines
The standard way to remove such calls is to set a "deleted" flag in the object, then check and ignore such objects in the reader and finally remove the object with
call_rcuI have not checked if that is really feasible for qdiscs.
-Andi
Actually, the synchronize_rcu() is now acting a barrier between two sections in the current unregister process. It can't be removed.
But, an alternative unregister_and_free_netdev() could be created that uses call_rcu. Basically:
void unregistr_and_free_netdev() {
do stuff before barrier...
setup rcu callback
call_rcu();
}
static void netdev_after_rcu() {
rtnl_lock();
do stuff after barier
rtnl_unlock();
free_netdev
}Signature · 1 line
Stephen Hemminger <[email protected]>