Re: [PATCH 2/3] rcu: Enable rcu_normal_wake_from_gp on small systems

2025-06-11 Thread Uladzislau Rezki
On Tue, Jun 10, 2025 at 02:34:10PM -0400, Joel Fernandes wrote:
> 
> 
> On 6/10/2025 1:34 PM, Uladzislau Rezki (Sony) wrote:
> > Automatically enable the rcu_normal_wake_from_gp parameter on
> > systems with a small number of CPUs. The activation threshold
> > is set to 16 CPUs.
> > 
> > This helps to reduce a latency of normal synchronize_rcu() API
> > by waking up GP-waiters earlier and decoupling synchronize_rcu()
> > callers from regular callback handling.
> > 
> > A benchmark running 64 parallel jobs invoking synchronize_rcu()
> > demonstrates a notable latency reduction with the setting enabled.
> > 
> > Latency distribution (microseconds):
> > 
> > 
> >  0  -    : 1
> >  1  - 1  : 4
> >  2  - 2  : 399
> >  3  - 3  : 3197
> >  4  - 4  : 10428
> >  5  - 5  : 17363
> >  6  - 6  : 15529
> >  7  - 7  : 9287
> >  8  - 8  : 4249
> >  9  - 9  : 1915
> >  10 - 10 : 922
> >  11 - 11 : 390
> >  12 - 12 : 187
> >  ...
> > 
> > 
> > 
> >  0  -   : 1
> >  1  - 1 : 234
> >  2  - 2 : 6678
> >  3  - 3 : 33463
> >  4  - 4 : 20669
> >  5  - 5 : 2766
> >  6  - 6 : 183
> >  ...
> > 
> > 
> > Signed-off-by: Uladzislau Rezki (Sony) 
> > ---
> >  kernel/rcu/tree.c | 7 ++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > index 14d4499c6fc3..c0e0b38a08dc 100644
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -1625,7 +1625,9 @@ static void rcu_sr_put_wait_head(struct llist_node 
> > *node)
> > atomic_set_release(&sr_wn->inuse, 0);
> >  }
> >  
> > -/* Disabled by default. */
> > +/* Enable rcu_normal_wake_from_gp automatically on small systems. */
> > +#define WAKE_FROM_GP_CPU_THRESHOLD 16
> > +
> >  static int rcu_normal_wake_from_gp;
> >  module_param(rcu_normal_wake_from_gp, int, 0644);
> >  static struct workqueue_struct *sync_wq;
> > @@ -4847,6 +4849,9 @@ void __init rcu_init(void)
> > sync_wq = alloc_workqueue("sync_wq", WQ_MEM_RECLAIM, 0);
> > WARN_ON(!sync_wq);
> >  
> > +   if (num_possible_cpus() <= WAKE_FROM_GP_CPU_THRESHOLD)
> > +   WRITE_ONCE(rcu_normal_wake_from_gp, 1);
> > +
> I think this will get weird if user explictly specifies
> rcutree.rcu_normal_wake_from_gp=0 ? Then we're silently overriding the param.
> Maybe, initialize it to -1, and then if it was set 0 by user, don't override 
> it.
> But otherwise, set it to 1.  Per your third patch, '1' is a default, not a
> forced value.
> 
Right. That case should be fixed.

--
Uladzislau Rezki



Re: [PATCH 2/3] rcu: Enable rcu_normal_wake_from_gp on small systems

2025-06-10 Thread Joel Fernandes



On 6/10/2025 1:34 PM, Uladzislau Rezki (Sony) wrote:
> Automatically enable the rcu_normal_wake_from_gp parameter on
> systems with a small number of CPUs. The activation threshold
> is set to 16 CPUs.
> 
> This helps to reduce a latency of normal synchronize_rcu() API
> by waking up GP-waiters earlier and decoupling synchronize_rcu()
> callers from regular callback handling.
> 
> A benchmark running 64 parallel jobs invoking synchronize_rcu()
> demonstrates a notable latency reduction with the setting enabled.
> 
> Latency distribution (microseconds):
> 
> 
>  0  -    : 1
>  1  - 1  : 4
>  2  - 2  : 399
>  3  - 3  : 3197
>  4  - 4  : 10428
>  5  - 5  : 17363
>  6  - 6  : 15529
>  7  - 7  : 9287
>  8  - 8  : 4249
>  9  - 9  : 1915
>  10 - 10 : 922
>  11 - 11 : 390
>  12 - 12 : 187
>  ...
> 
> 
> 
>  0  -   : 1
>  1  - 1 : 234
>  2  - 2 : 6678
>  3  - 3 : 33463
>  4  - 4 : 20669
>  5  - 5 : 2766
>  6  - 6 : 183
>  ...
> 
> 
> Signed-off-by: Uladzislau Rezki (Sony) 
> ---
>  kernel/rcu/tree.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index 14d4499c6fc3..c0e0b38a08dc 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -1625,7 +1625,9 @@ static void rcu_sr_put_wait_head(struct llist_node 
> *node)
>   atomic_set_release(&sr_wn->inuse, 0);
>  }
>  
> -/* Disabled by default. */
> +/* Enable rcu_normal_wake_from_gp automatically on small systems. */
> +#define WAKE_FROM_GP_CPU_THRESHOLD 16
> +
>  static int rcu_normal_wake_from_gp;
>  module_param(rcu_normal_wake_from_gp, int, 0644);
>  static struct workqueue_struct *sync_wq;
> @@ -4847,6 +4849,9 @@ void __init rcu_init(void)
>   sync_wq = alloc_workqueue("sync_wq", WQ_MEM_RECLAIM, 0);
>   WARN_ON(!sync_wq);
>  
> + if (num_possible_cpus() <= WAKE_FROM_GP_CPU_THRESHOLD)
> + WRITE_ONCE(rcu_normal_wake_from_gp, 1);
> +
I think this will get weird if user explictly specifies
rcutree.rcu_normal_wake_from_gp=0 ? Then we're silently overriding the param.
Maybe, initialize it to -1, and then if it was set 0 by user, don't override it.
But otherwise, set it to 1.  Per your third patch, '1' is a default, not a
forced value.

thanks,

 - Joel







[PATCH 2/3] rcu: Enable rcu_normal_wake_from_gp on small systems

2025-06-10 Thread Uladzislau Rezki (Sony)
Automatically enable the rcu_normal_wake_from_gp parameter on
systems with a small number of CPUs. The activation threshold
is set to 16 CPUs.

This helps to reduce a latency of normal synchronize_rcu() API
by waking up GP-waiters earlier and decoupling synchronize_rcu()
callers from regular callback handling.

A benchmark running 64 parallel jobs invoking synchronize_rcu()
demonstrates a notable latency reduction with the setting enabled.

Latency distribution (microseconds):


 0  -    : 1
 1  - 1  : 4
 2  - 2  : 399
 3  - 3  : 3197
 4  - 4  : 10428
 5  - 5  : 17363
 6  - 6  : 15529
 7  - 7  : 9287
 8  - 8  : 4249
 9  - 9  : 1915
 10 - 10 : 922
 11 - 11 : 390
 12 - 12 : 187
 ...



 0  -   : 1
 1  - 1 : 234
 2  - 2 : 6678
 3  - 3 : 33463
 4  - 4 : 20669
 5  - 5 : 2766
 6  - 6 : 183
 ...


Signed-off-by: Uladzislau Rezki (Sony) 
---
 kernel/rcu/tree.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 14d4499c6fc3..c0e0b38a08dc 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -1625,7 +1625,9 @@ static void rcu_sr_put_wait_head(struct llist_node *node)
atomic_set_release(&sr_wn->inuse, 0);
 }
 
-/* Disabled by default. */
+/* Enable rcu_normal_wake_from_gp automatically on small systems. */
+#define WAKE_FROM_GP_CPU_THRESHOLD 16
+
 static int rcu_normal_wake_from_gp;
 module_param(rcu_normal_wake_from_gp, int, 0644);
 static struct workqueue_struct *sync_wq;
@@ -4847,6 +4849,9 @@ void __init rcu_init(void)
sync_wq = alloc_workqueue("sync_wq", WQ_MEM_RECLAIM, 0);
WARN_ON(!sync_wq);
 
+   if (num_possible_cpus() <= WAKE_FROM_GP_CPU_THRESHOLD)
+   WRITE_ONCE(rcu_normal_wake_from_gp, 1);
+
/* Fill in default value for rcutree.qovld boot parameter. */
/* -After- the rcu_node ->lock fields are initialized! */
if (qovld < 0)
-- 
2.39.5