mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] sched/fair: Avoid false sharing in nohz struct
@ 2025-12-19  1:38 Shubhang Kaushik Prasanna Kumar
  2025-12-19 13:56 ` Guo, Wangyang
  0 siblings, 1 reply; 7+ messages in thread
From: Shubhang Kaushik Prasanna Kumar @ 2025-12-19  1:38 UTC (permalink / raw)
  To: wangyang.guo
  Cc: benjamin.lei, bsegall, dietmar.eggemann, juri.lelli,
	linux-kernel, mgorman, mingo, peterz, rostedt, tianyou.li,
	tim.c.chen, vincent.guittot, vschneid

Hi Wangyang Guo,

While the intuition behind isolating the `nr_cpus` counter seems correct, could you please justify the added padding ? As this is a high contention path in the scheduler, we shouldn't be inflating global structures with padding on logic alone. I’d like to see some benchmarking such as `perf c2c` results from a multi-core system proving the `false sharing` scenario as a measurable bottleneck.

I am also concerned about the internal layout. By sandwiching the timer fields between two `__cacheline_aligned` boundaries, we might just be shifting the contention rather than fixing it.  See to it that fields like `next_balance` aren't being squeezed into a new conflict zone. Would like to review the benchmark data and the struct layout before we move forward.

Thanks,
Shubhang Kaushik

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [PATCH] sched/fair: Avoid false sharing in nohz struct
@ 2025-12-11  5:56 Wangyang Guo
  2025-12-21 13:05 ` Shrikanth Hegde
  0 siblings, 1 reply; 7+ messages in thread
From: Wangyang Guo @ 2025-12-11  5:56 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider
  Cc: linux-kernel, Wangyang Guo, Benjamin Lei, Tim Chen, Tianyou Li

There are two potential false sharing issue in nohz struct:
1. idle_cpus_mask is a read-mostly field, but share the same cacheline
   with frequently updated nr_cpus.
2. Data followed by nohz still share the same cacheline and has
   potential false sharing issue.

This patch tries to resolve the above two problems by isolating the
frequently updated fields in a single cacheline.

Reported-by: Benjamin Lei <benjamin.lei@intel.com>
Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
Reviewed-by: Tianyou Li <tianyou.li@intel.com>
Signed-off-by: Wangyang Guo <wangyang.guo@intel.com>
---
 kernel/sched/fair.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 5b752324270b..bcc2766b7986 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7193,13 +7193,14 @@ static DEFINE_PER_CPU(cpumask_var_t, should_we_balance_tmpmask);
 #ifdef CONFIG_NO_HZ_COMMON
 
 static struct {
-	cpumask_var_t idle_cpus_mask;
-	atomic_t nr_cpus;
+	/* Isolate frequently updated fields in a cacheline to avoid false sharing issue. */
+	atomic_t nr_cpus ____cacheline_aligned;
 	int has_blocked;		/* Idle CPUS has blocked load */
 	int needs_update;		/* Newly idle CPUs need their next_balance collated */
 	unsigned long next_balance;     /* in jiffy units */
 	unsigned long next_blocked;	/* Next update of blocked load in jiffies */
-} nohz ____cacheline_aligned;
+	cpumask_var_t idle_cpus_mask ____cacheline_aligned;
+} nohz;
 
 #endif /* CONFIG_NO_HZ_COMMON */
 
-- 
2.47.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-23  8:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-19  1:38 [PATCH] sched/fair: Avoid false sharing in nohz struct Shubhang Kaushik Prasanna Kumar
2025-12-19 13:56 ` Guo, Wangyang
  -- strict thread matches above, loose matches on Subject: below --
2025-12-11  5:56 Wangyang Guo
2025-12-21 13:05 ` Shrikanth Hegde
2025-12-22  2:21   ` Guo, Wangyang
2025-12-23  7:27     ` Shrikanth Hegde
2025-12-23  8:03       ` Guo, Wangyang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®