Skip to contentSkip to conversation

rcu: Disable lazy if call_rcu() called when GPs expedited

PATCH In review Joel Fernandes (Google) 2 participants 4 messages Jan 9, 2023 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rcu: Disable lazy if call_rcu() called when GPs expedited

During suspend, we see failures to suspend 1 in 300-500 suspends. Looking closer, it appears that we are queuing lazy callbacks even though rcu_gp_is_expedited(). These delays appear to not be very welcome by the suspend/resume code as evidenced by these occasional suspend failures.

This commit therefore checks if rcu_gp_is_expedited() and ignores the lazy hint if so.

Ignoring the lazy hint if rcu_gp_is_expedited() makes the 3000 suspend/resume cycles pass reliably on a 12th gen 12-core Intel CPU.

Fixes 3cb278e73be5 ("rcu: Make call_rcu() lazy to save power")

---
Paul, could we take this for 6.2 -rc cycle? Thanks.

 kernel/rcu/tree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +3 -2
index 63545d79da51..93eb03f8ed99 100644
@@ -2594,12 +2594,12 @@ static void check_cb_ovld(struct rcu_data *rdp)
 }
 
 static void
-__call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy)
+__call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)
 {
 	static atomic_t doublefrees;
 	unsigned long flags;
 	struct rcu_data *rdp;
-	bool was_alldone;
+	bool was_alldone, lazy;
 
 	/* Misaligned rcu_head! */
 	WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
@@ -2622,6 +2622,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy)
 	kasan_record_aux_stack_noalloc(head);
 	local_irq_save(flags);
 	rdp = this_cpu_ptr(&rcu_data);
+	lazy = lazy_in && !rcu_gp_is_expedited();
 
 	/* Add the callback to our list. */
 	if (unlikely(!rcu_segcblist_is_enabled(&rdp->cblist))) {
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
maintainer
#1 lore raw
Quoted 11 lines · Joel Fernandes (Google)

During suspend, we see failures to suspend 1 in 300-500 suspends. Looking closer, it appears that we are queuing lazy callbacks even though rcu_gp_is_expedited(). These delays appear to not be very welcome by the suspend/resume code as evidenced by these occasional suspend failures.

This commit therefore checks if rcu_gp_is_expedited() and ignores the lazy hint if so.

Ignoring the lazy hint if rcu_gp_is_expedited() makes the 3000 suspend/resume cycles pass reliably on a 12th gen 12-core Intel CPU.

Yow!!! ;-)

Quoted 14 lines
Fixes 3cb278e73be5 ("rcu: Make call_rcu() lazy to save power")

---
Paul, could we take this for 6.2 -rc cycle? Thanks.

 kernel/rcu/tree.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +0 -0
index 63545d79da51..93eb03f8ed99 100644
@@ -2594,12 +2594,12 @@ static void check_cb_ovld(struct rcu_data *rdp)
 }

kernel/rcu/tree.c static void check_cb_ovld(struct rcu_data *rdp) · line 2602

Quoted 10 lines
kernel/rcu/tree.c +2 -2
 
 static void
-__call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy)
+__call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)
 {
 	static atomic_t doublefrees;
 	unsigned long flags;
 	struct rcu_data *rdp;
-	bool was_alldone;
+	bool was_alldone, lazy;

Please put "lazy" in alpha order. Except that...

kernel/rcu/tree.c __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy) · line 2625

Quoted 7 lines
kernel/rcu/tree.c +1 -0
 	/* Misaligned rcu_head! */
 	WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
@@ -2622,6 +2622,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy)
 	kasan_record_aux_stack_noalloc(head);
 	local_irq_save(flags);
 	rdp = this_cpu_ptr(&rcu_data);
+	lazy = lazy_in && !rcu_gp_is_expedited();

Doesn't this completely disable laziness on Android?

Thanx, Paul

Quoted 4 lines
kernel/rcu/tree.c +0 -0
 	/* Add the callback to our list. */
 	if (unlikely(!rcu_segcblist_is_enabled(&rdp->cblist))) {
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#2 lore raw
Quoted 11 lines · Paul E. McKenney
Quoted 6 lines · Joel Fernandes (Google)

During suspend, we see failures to suspend 1 in 300-500 suspends. Looking closer, it appears that we are queuing lazy callbacks even though rcu_gp_is_expedited(). These delays appear to not be very welcome by the suspend/resume code as evidenced by these occasional suspend failures.

Quoted 7 lines
Quoted 5 lines

This commit therefore checks if rcu_gp_is_expedited() and ignores the lazy hint if so.

Ignoring the lazy hint if rcu_gp_is_expedited() makes the 3000 suspend/resume cycles pass reliably on a 12th gen 12-core Intel CPU.

Yow!!! ;-)

:-D

Quoted 15 lines
Quoted 15 lines
Fixes 3cb278e73be5 ("rcu: Make call_rcu() lazy to save power")

---
Paul, could we take this for 6.2 -rc cycle? Thanks.

kernel/rcu/tree.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +0 -0
index 63545d79da51..93eb03f8ed99 100644
@@ -2594,12 +2594,12 @@ static void check_cb_ovld(struct rcu_data *rdp)
 }
 
Quoted 11 lines

kernel/rcu/tree.c static void check_cb_ovld(struct rcu_data *rdp) · line 2602

Quoted 9 lines

static void

kernel/rcu/tree.c +1 -1
-__call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy)
+__call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)
{
   static atomic_t doublefrees;
   unsigned long flags;
   struct rcu_data *rdp;
kernel/rcu/tree.c +1 -1
-    bool was_alldone;
+    bool was_alldone, lazy;

Please put "lazy" in alpha order. Except that...

Ah sure.

Quoted 10 lines

kernel/rcu/tree.c __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy) · line 2625

Quoted 8 lines
   /* Misaligned rcu_head! */
   WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
kernel/rcu/tree.c +1 -0
@@ -2622,6 +2622,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy)
   kasan_record_aux_stack_noalloc(head);
   local_irq_save(flags);
   rdp = this_cpu_ptr(&rcu_data);
+    lazy = lazy_in && !rcu_gp_is_expedited();

Doesn't this completely disable laziness on Android?

Good point, I am not sure but it could be. Maybe it is safer that I add a new suspend-indicator then, with corresponding
suspend entry/exit calls like we do for expedited.

That way anyone doing it this way will not disable lazy fully.

Thoughts?

Thanks!

- Joel

Quoted 7 lines

Thanx, Paul

Quoted 4 lines
kernel/rcu/tree.c +0 -0
   /* Add the callback to our list. */
   if (unlikely(!rcu_segcblist_is_enabled(&rdp->cblist))) {
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
maintainer
#3 lore raw
Quoted 61 lines · Joel Fernandes
Quoted 11 lines · Paul E. McKenney
Quoted 6 lines · Joel Fernandes (Google)

During suspend, we see failures to suspend 1 in 300-500 suspends. Looking closer, it appears that we are queuing lazy callbacks even though rcu_gp_is_expedited(). These delays appear to not be very welcome by the suspend/resume code as evidenced by these occasional suspend failures.

Quoted 7 lines
Quoted 5 lines

This commit therefore checks if rcu_gp_is_expedited() and ignores the lazy hint if so.

Ignoring the lazy hint if rcu_gp_is_expedited() makes the 3000 suspend/resume cycles pass reliably on a 12th gen 12-core Intel CPU.

Yow!!! ;-)

:-D

Quoted 15 lines
Quoted 15 lines
Fixes 3cb278e73be5 ("rcu: Make call_rcu() lazy to save power")

---
Paul, could we take this for 6.2 -rc cycle? Thanks.

kernel/rcu/tree.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +0 -0
index 63545d79da51..93eb03f8ed99 100644
@@ -2594,12 +2594,12 @@ static void check_cb_ovld(struct rcu_data *rdp)
 }
 
Quoted 11 lines

kernel/rcu/tree.c static void check_cb_ovld(struct rcu_data *rdp) · line 2602

Quoted 9 lines

static void

kernel/rcu/tree.c +1 -1
-__call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy)
+__call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)
{
   static atomic_t doublefrees;
   unsigned long flags;
   struct rcu_data *rdp;
kernel/rcu/tree.c +1 -1
-    bool was_alldone;
+    bool was_alldone, lazy;

Please put "lazy" in alpha order. Except that...

Ah sure.

Quoted 10 lines

kernel/rcu/tree.c __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy) · line 2625

Quoted 8 lines
   /* Misaligned rcu_head! */
   WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
kernel/rcu/tree.c +1 -0
@@ -2622,6 +2622,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy)
   kasan_record_aux_stack_noalloc(head);
   local_irq_save(flags);
   rdp = this_cpu_ptr(&rcu_data);
+    lazy = lazy_in && !rcu_gp_is_expedited();

Doesn't this completely disable laziness on Android?

Quoted 8 lines

Good point, I am not sure but it could be. Maybe it is safer that I add a new suspend-indicator then, with corresponding
suspend entry/exit calls like we do for expedited.

That way anyone doing it this way will not disable lazy fully.

Thoughts?

Makes sense to me!

Just so you know, there is an overlapping patch series in flight here:

https://lore.kernel.org/all/[email protected]/

Thanx, Paul