All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/nohz: Fix NOHZ imbalance by adding options for ILB CPU
@ 2025-08-19  2:57 Adam Li
  2025-08-19 14:00 ` Valentin Schneider
  0 siblings, 1 reply; 21+ messages in thread
From: Adam Li @ 2025-08-19  2:57 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid, cl,
	frederic, linux-kernel, patches, Adam Li

A qualified CPU to run NOHZ idle load balancing (ILB) has to be:
1) housekeeping CPU in housekeeping_cpumask(HK_TYPE_KERNEL_NOISE)
2) and in nohz.idle_cpus_mask
3) and idle
4) and not current CPU

If most CPUs are in nohz_full CPU list there is few housekeeping CPU left.
In the worst case if all CPUs are in nohz_full only the boot CPU is used
for housekeeping. And the housekeeping CPU is usually busier so it will
be unlikely added to nohz.idle_cpus_mask.

Therefore if there is few housekeeping CPUs, find_new_ilb() may likely
failed to find any CPU to do NOHZ idle load balancing. Some NOHZ CPUs may
stay idle while other CPUs are busy.

This patch adds fallback options when looking for ILB CPU if there is
no CPU meeting above requirements. Then it searches in bellow order:
1) Try looking for the first idle housekeeping CPU
2) Try looking for the first idle CPU in nohz.idle_cpus_mask if no SMT.
3) Select the first housekeeping CPU even if it is busy.

With this patch the NOHZ idle balancing happens more frequently.

Signed-off-by: Adam Li <adamli@os.amperecomputing.com>
---
 kernel/sched/fair.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index b173a059315c..12bcc3f81f9b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -12194,19 +12194,45 @@ static inline int on_null_domain(struct rq *rq)
 static inline int find_new_ilb(void)
 {
 	const struct cpumask *hk_mask;
-	int ilb_cpu;
+	struct cpumask ilb_mask;
+	int ilb_cpu, this_cpu = smp_processor_id();
 
 	hk_mask = housekeeping_cpumask(HK_TYPE_KERNEL_NOISE);
 
-	for_each_cpu_and(ilb_cpu, nohz.idle_cpus_mask, hk_mask) {
+	/*
+	 * Look for an idle cpu who is both NOHZ_idle and housekeeping.
+	 * If no such cpu, look for an idle housekeeping cpu.
+	 */
+	if (!cpumask_and(&ilb_mask, nohz.idle_cpus_mask, hk_mask))
+		cpumask_copy(&ilb_mask, hk_mask);
 
-		if (ilb_cpu == smp_processor_id())
+	for_each_cpu(ilb_cpu, &ilb_mask) {
+		if (ilb_cpu == this_cpu)
 			continue;
 
 		if (idle_cpu(ilb_cpu))
 			return ilb_cpu;
 	}
 
+	/*
+	 * If CPU has no SMT, look for an idle NOHZ_idle cpu.
+	 * Run NOHZ ILB may cause jitter on SMT sibling CPU.
+	 */
+	if (!sched_smt_active()) {
+		for_each_cpu(ilb_cpu, nohz.idle_cpus_mask) {
+			if (ilb_cpu == this_cpu)
+				continue;
+
+			if (idle_cpu(ilb_cpu))
+				return ilb_cpu;
+		}
+	}
+
+	/* Select the first housekeeping cpu anyway. */
+	ilb_cpu = cpumask_first(hk_mask);
+	if (ilb_cpu < nr_cpu_ids)
+		return ilb_cpu;
+
 	return -1;
 }
 
-- 
2.34.1


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

end of thread, other threads:[~2025-09-11  8:55 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19  2:57 [PATCH] sched/nohz: Fix NOHZ imbalance by adding options for ILB CPU Adam Li
2025-08-19 14:00 ` Valentin Schneider
2025-08-20  3:35   ` Adam Li
2025-08-20  8:43     ` Valentin Schneider
2025-08-20 11:05       ` Adam Li
2025-08-20 11:46         ` Valentin Schneider
2025-08-21 11:18           ` Adam Li
2025-08-28 10:56             ` Valentin Schneider
2025-08-28 15:44               ` Christoph Lameter (Ampere)
2025-09-03 12:35                 ` Valentin Schneider
2025-09-03 14:14                   ` Vincent Guittot
2025-09-03 20:33                     ` Christoph Lameter (Ampere)
2025-09-11  8:55                       ` Vincent Guittot
2025-08-20 17:31       ` Christoph Lameter (Ampere)
2025-08-21  9:01         ` Valentin Schneider
2025-09-04 13:54         ` Frederic Weisbecker
2025-09-04 15:34           ` Christoph Lameter (Ampere)
2025-09-04 16:13             ` Frederic Weisbecker
2025-09-04 16:18               ` Christoph Lameter (Ampere)
2025-09-05 12:16                 ` Frederic Weisbecker
2025-09-05 16:45                   ` Christoph Lameter (Ampere)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.