rcu/nocb: Remove unnecessary WakeOvfIsDeferred wake path
Joel Fernandes
maintainerRFC PATCH 1/1 rcu/nocb: Remove unnecessary WakeOvfIsDeferred wake path
The WakeOvfIsDeferred code path in __call_rcu_nocb_wake() attempts to wake rcuog when the callback count exceeds qhimark and callbacks aren't done with their GP (newly queued or awaiting GP). However, a lot of testing proves this wake is always redundant or useless.
In the flooding case, rcuog is always waiting for a GP to finish. So waking up the rcuog thread is pointless. The timer wakeup adds overhead, rcuog simply wakes up and goes back to sleep achieving nothing.
This path also adds a full memory barrier, and additional timer expiry modifications unnecessarily.
The root cause is that WakeOvfIsDeferred fires when !rcu_segcblist_ready_cbs() (GP not complete), but waking rcuog cannot accelerate GP completion.
This commit therefore removes this path, which also adding some rdp counters to ensure we don't have lost wake ups.
Tested with rcutorture scenarios: TREE01, TREE05, TREE08 (all NOCB configurations) - all pass. Also stress tested using a kernel module that floods call_rcu() to trigger the overload conditions and made the observations confirming the findings.
--- kernel/rcu/tree.h | 3 ++- kernel/rcu/tree_nocb.h | 43 +++++++++++++++++------------------------- 2 files changed, 19 insertions(+), 27 deletions(-)
kernel/rcu/tree.h +2 -1
@@ -257,6 +257,8 @@ struct rcu_data {unsigned long nocb_gp_loops;/* # passes through wait code. */ struct swait_queue_head nocb_gp_wq;/* For nocb kthreads to sleep on. */ bool nocb_cb_sleep;/* Is the nocb CB thread asleep? */ +bool nocb_gp_wake_attempt;/* Was rcuog wake attempted? */ +bool nocb_gp_serving;/* Is rcuog serving this rdp? */ struct task_struct *nocb_cb_kthread;struct list_head nocb_head_rdp;/* * Head of rcu_data list in wakeup chain,
@@ -301,7 +303,6 @@ struct rcu_data {#define RCU_NOCB_WAKE_BYPASS 1#define RCU_NOCB_WAKE_LAZY 2#define RCU_NOCB_WAKE 3 -#define RCU_NOCB_WAKE_FORCE 4#define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 250) + (HZ > 500))/* For jiffies_till_first_fqs and */
kernel/rcu/tree_nocb.h +17 -26
110 lines not on this page · raw message
Signature · 1 line
2.34.1
Frederic Weisbecker
maintainerQuoted 12 lines · Joel Fernandes
The WakeOvfIsDeferred code path in
__call_rcu_nocb_wake()attempts to wake rcuog when the callback count exceeds qhimark and callbacks aren't done with their GP (newly queued or awaiting GP). However, a lot of testing proves this wake is always redundant or useless.In the flooding case, rcuog is always waiting for a GP to finish. So waking up the rcuog thread is pointless. The timer wakeup adds overhead, rcuog simply wakes up and goes back to sleep achieving nothing.
This path also adds a full memory barrier, and additional timer expiry modifications unnecessarily.
Quoted 6 lines
The root cause is that WakeOvfIsDeferred fires when !rcu_segcblist_ready_cbs() (GP not complete), but waking rcuog cannot accelerate GP completion.
This commit therefore removes this path, which also adding some rdp counters to ensure we don't have lost wake ups.
There should be two patches: one that removes the useless path and the other that adds the debugging.
Quoted 7 lines
Tested with rcutorture scenarios: TREE01, TREE05, TREE08 (all NOCB configurations) - all pass. Also stress tested using a kernel module that floods
call_rcu()to trigger the overload conditions and made the observations confirming the findings.Signed-off-by Joel Fernandes <[email protected]>
Cool! Just a few comments:
Quoted 18 lines
kernel/rcu/tree_nocb.h +2
-2@@ -549,24 +546,26 @@ static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone, lazy_len =READ_ONCE (rdp->lazy_len);if (was_alldone) { rdp->qlen_last_fqs_check = len; + rdp->nocb_gp_wake_attempt = true; +rcu_nocb_unlock (rdp);// Only lazy CBs in bypass list if (lazy_len && bypass_len == lazy_len) { -rcu_nocb_unlock (rdp);wake_nocb_gp_defer (rdp,RCU_NOCB_WAKE_LAZY ,TPS ("WakeLazy" )); }else if (!irqs_disabled_flags (flags)) {/* ... if queue was empty ... */ -rcu_nocb_unlock (rdp);wake_nocb_gp (rdp, false);trace_rcu_nocb_wake (rcu_state.name, rdp->cpu,TPS ("WakeEmpty" )); }else {
kernel/rcu/tree_nocb.h static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone, · line 568
Quoted 10 lines
kernel/rcu/tree_nocb.h +4
-2-rcu_nocb_unlock (rdp);wake_nocb_gp_defer (rdp,RCU_NOCB_WAKE ,TPS ("WakeEmptyIsDeferred" )); } + +return ; }else if (len > rdp->qlen_last_fqs_check + qhimark) { -/* ... or if many callbacks queued. */ +/* Callback overload condition. */ +WARN_ON_ONCE (!rdp->nocb_gp_wake_attempt && !rdp->nocb_gp_serving);
With this test, the point of ->nocb_gp_serving is unclear given that both states are cleared in the same place but ->nocb_gp_serving is set later by the gp kthread. ->nocb_gp_serving implies ->nocb_gp_wake_attempt so the above test is the same as WARN_ON_ONCE(!rdp->nocb_gp_wake_attempt).
In fact ->nocb_gp_wake_attempt alone probably makes sense?
kernel/rcu/tree_nocb.h static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone, · line 578
Quoted 8 lines
kernel/rcu/tree_nocb.h +0
-1rdp->qlen_last_fqs_check = len; j = jiffies; if (j != rdp->nocb_gp_adv_time &&@@ -575,21 +574,10 @@ static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone,rcu_advance_cbs_nowake (rdp->mynode, rdp); rdp->nocb_gp_adv_time = j; } -smp_mb ();/* Enqueue before timer_pending(). */
You need to remove the pairing smp_mb__after_spin_lock() in do_nocb_deferred_wakeup_timer().
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Joel Fernandes
maintainerHi Frederic,
Quoted 17 lines · Frederic Weisbecker
Quoted 16 lines · Joel Fernandes
The WakeOvfIsDeferred code path in
__call_rcu_nocb_wake()attempts to wake rcuog when the callback count exceeds qhimark and callbacks aren't done with their GP (newly queued or awaiting GP). However, a lot of testing proves this wake is always redundant or useless.In the flooding case, rcuog is always waiting for a GP to finish. So waking up the rcuog thread is pointless. The timer wakeup adds overhead, rcuog simply wakes up and goes back to sleep achieving nothing.
This path also adds a full memory barrier, and additional timer expiry modifications unnecessarily.
The root cause is that WakeOvfIsDeferred fires when !rcu_segcblist_ready_cbs() (GP not complete), but waking rcuog cannot accelerate GP completion.
Quoted 5 lines
Quoted 2 lines
This commit therefore removes this path, which also adding some rdp counters to ensure we don't have lost wake ups.
There should be two patches: one that removes the useless path and the other that adds the debugging.
Sure, will split.
Quoted 43 lines
Quoted 6 lines
Tested with rcutorture scenarios: TREE01, TREE05, TREE08 (all NOCB configurations) - all pass. Also stress tested using a kernel module that floods
call_rcu()to trigger the overload conditions and made the observations confirming the findings.Signed-off-by Joel Fernandes <[email protected]>Cool! Just a few comments:
Quoted 18 lines
kernel/rcu/tree_nocb.h +2
-2@@ -549,24 +546,26 @@ static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone, lazy_len =READ_ONCE (rdp->lazy_len);if (was_alldone) { rdp->qlen_last_fqs_check = len; + rdp->nocb_gp_wake_attempt = true; +rcu_nocb_unlock (rdp);// Only lazy CBs in bypass list if (lazy_len && bypass_len == lazy_len) { -rcu_nocb_unlock (rdp);wake_nocb_gp_defer (rdp,RCU_NOCB_WAKE_LAZY ,TPS ("WakeLazy" )); }else if (!irqs_disabled_flags (flags)) {/* ... if queue was empty ... */ -rcu_nocb_unlock (rdp);wake_nocb_gp (rdp, false);trace_rcu_nocb_wake (rcu_state.name, rdp->cpu,TPS ("WakeEmpty" )); }else {kernel/rcu/tree_nocb.h static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone, · line 568
Quoted 10 lines
kernel/rcu/tree_nocb.h +4
-2-rcu_nocb_unlock (rdp);wake_nocb_gp_defer (rdp,RCU_NOCB_WAKE ,TPS ("WakeEmptyIsDeferred" )); } + +return ; }else if (len > rdp->qlen_last_fqs_check + qhimark) { -/* ... or if many callbacks queued. */ +/* Callback overload condition. */ +WARN_ON_ONCE (!rdp->nocb_gp_wake_attempt && !rdp->nocb_gp_serving);With this test, the point of ->nocb_gp_serving is unclear given that both states are cleared in the same place but ->nocb_gp_serving is set later by the gp kthread. ->nocb_gp_serving implies ->nocb_gp_wake_attempt so the above test is the same as
WARN_ON_ONCE(!rdp->nocb_gp_wake_attempt).
Quoted 1 line
In fact ->nocb_gp_wake_attempt alone probably makes sense?
Ah true, I got a bit paranoid about false positive warnings hence I added the extra variable, however on further analysis I realized the nocb lock takes care of preventing potential false positive warnings. So yes, I will just use the single variable. Thanks.
Quoted 12 lines
kernel/rcu/tree_nocb.h static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone, · line 578
Quoted 9 lines
kernel/rcu/tree_nocb.h +0
-1rdp->qlen_last_fqs_check = len; j = jiffies; if (j != rdp->nocb_gp_adv_time &&@@ -575,21 +574,10 @@ static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone,rcu_advance_cbs_nowake (rdp->mynode, rdp); rdp->nocb_gp_adv_time = j; } -smp_mb ();/* Enqueue before timer_pending(). */ You need to remove the pairing
smp_mb__after_spin_lock()indo_nocb_deferred_wakeup_timer().
Ah, will do. Thanks!
- Joel