From: Yury Norov <ynorov@nvidia.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org
Cc: Yury Norov <yury.norov@gmail.com>
Subject: Re: [PATCH] sched/core: Make fallback CPU selection NUMA-aware
Date: Mon, 21 Sep 2026 12:15:01 -0400 [thread overview]
Message-ID: <arFYBf58i6J35SLZ@yury> (raw)
In-Reply-To: <20260905033656.311477-1-ynorov@nvidia.com>
Ping?
On Fri, Sep 04, 2026 at 11:36:56PM -0400, Yury Norov wrote:
> select_fallback_rq() checks the local node first, but then scans the task's
> affinity mask in a numerical order. On systems with more than two NUMA
> nodes, that can select a CPU farther away than necessary.
>
> Walk the scheduler's NUMA hop masks and consider each newly reached CPU
> once, preserving locality across the full fallback search and after
> affinity relaxation.
>
> The NUMA masks can be unavailable or incomplete while topology is rebuilt.
> Search any online CPUs not covered by the masks before relaxing affinity
> so fallback selection remains reliable during that window.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> kernel/sched/core.c | 47 ++++++++++++++++++++++++---------------------
> 1 file changed, 25 insertions(+), 22 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index f78275192036..2155bad0e1ab 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3554,34 +3554,37 @@ EXPORT_SYMBOL_GPL(kick_process);
> */
> static int select_fallback_rq(int cpu, struct task_struct *p)
> {
> - int nid = cpu_to_node(cpu);
> - const struct cpumask *nodemask = NULL;
> + int nid = IS_ENABLED(CONFIG_NUMA) ? cpu_to_node(cpu) : NUMA_NO_NODE;
> enum { cpuset, possible, fail } state = cpuset;
> int dest_cpu;
>
> - /*
> - * If the node that the CPU is on has been offlined, cpu_to_node()
> - * will return -1. There is no CPU on the node, and we should
> - * select the CPU on the other node.
> - */
> - if (nid != -1) {
> - nodemask = cpumask_of_node(nid);
> -
> - /* Look for allowed, online CPU in same node. */
> - for_each_cpu(dest_cpu, nodemask) {
> - if (is_cpu_allowed(p, dest_cpu))
> - return dest_cpu;
> - }
> - }
> -
> for (;;) {
> - /* Any allowed, online CPU? */
> - for_each_cpu(dest_cpu, p->cpus_ptr) {
> - if (!is_cpu_allowed(p, dest_cpu))
> - continue;
> + const struct cpumask *prev = cpu_none_mask, *cpus;
> +
> + /* Look for the closest allowed, online CPU. */
> + rcu_read_lock();
> + for_each_numa_hop_mask(cpus, nid) {
> + for_each_cpu_andnot(dest_cpu, cpus, prev) {
> + if (is_cpu_allowed(p, dest_cpu)) {
> + rcu_read_unlock();
> + goto out;
> + }
> + }
> + prev = cpus;
> + }
>
> - goto out;
> + /*
> + * NUMA masks may be unavailable or incomplete while the
> + * topology is being rebuilt. Search CPUs not covered by them
> + * before relaxing the task's affinity.
> + */
> + for_each_cpu_andnot(dest_cpu, p->cpus_ptr, prev) {
> + if (is_cpu_allowed(p, dest_cpu)) {
> + rcu_read_unlock();
> + goto out;
> + }
> }
> + rcu_read_unlock();
>
> /* No more Mr. Nice Guy. */
> switch (state) {
> --
> 2.53.0
prev parent reply other threads:[~2026-09-21 16:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 3:36 Yury Norov
2026-09-21 16:15 ` Yury Norov [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=arFYBf58i6J35SLZ@yury \
--to=ynorov@nvidia.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.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 \
--cc=yury.norov@gmail.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
all inboxes | Powered by JetHome®