From: Imran Khan <imran.f.khan@oracle.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org
Cc: dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] sched/fair: distribute nohz ILB work across idle CPUs.
Date: Tue, 21 Apr 2026 13:06:22 +0800 [thread overview]
Message-ID: <20260421050622.19869-3-imran.f.khan@oracle.com> (raw)
In-Reply-To: <20260421050622.19869-1-imran.f.khan@oracle.com>
find_new_ilb() uses for_each_cpu_and() to iterate nohz.idle_cpus_mask
from the lowest bit upward, returning the first idle housekeeping CPU
it finds. This can (unfairly) select the lowest nohz idle CPU most of
the times.
Fix this by selecting nohz ILB CPU in a round robin way and thus
distributing the nohz ILB work (which can be significant on large
scale systems) across all eligible idle CPUs.
Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
---
kernel/sched/fair.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index bd35275a05b38..93bdb542ff714 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7213,6 +7213,7 @@ static struct {
cpumask_var_t idle_cpus_mask;
int has_blocked_load; /* Idle CPUS has blocked load */
int needs_update; /* Newly idle CPUs need their next_balance collated */
+ int ilb_cpu_last; /* Last CPU selected for nohz ILB */
unsigned long next_balance; /* in jiffy units */
unsigned long next_blocked; /* Next update of blocked load in jiffies */
} nohz ____cacheline_aligned;
@@ -12420,13 +12421,17 @@ static inline int find_new_ilb(void)
hk_mask = housekeeping_cpumask(HK_TYPE_KERNEL_NOISE);
- for_each_cpu_and(ilb_cpu, nohz.idle_cpus_mask, hk_mask) {
+ for_each_cpu_wrap(ilb_cpu, nohz.idle_cpus_mask, nohz.ilb_cpu_last + 1) {
+ if (!cpumask_test_cpu(ilb_cpu, hk_mask))
+ continue;
if (ilb_cpu == smp_processor_id())
continue;
- if (idle_cpu(ilb_cpu))
+ if (idle_cpu(ilb_cpu)) {
+ nohz.ilb_cpu_last = ilb_cpu;
return ilb_cpu;
+ }
}
return -1;
--
2.34.1
prev parent reply other threads:[~2026-04-21 5:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 5:06 [PATCH 0/2] sched/fair: Reduce nohz_idle_balance CPU overhead on large systems Imran Khan
2026-04-21 5:06 ` [PATCH 1/2] sched/fair: scale nohz.next_balance according to number of idle CPUs Imran Khan
2026-04-21 17:30 ` Shrikanth Hegde
2026-04-22 7:54 ` Vincent Guittot
2026-04-22 16:13 ` imran.f.khan
2026-04-24 9:46 ` Vincent Guittot
2026-04-28 10:52 ` imran.f.khan
2026-04-28 15:06 ` Vincent Guittot
2026-04-21 5:06 ` Imran Khan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260421050622.19869-3-imran.f.khan@oracle.com \
--to=imran.f.khan@oracle.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox