From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Dietmar Eggemann <dietmar.eggemann@arm.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Valentin Schneider <vschneid@redhat.com>,
<linux-kernel@vger.kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Chen Yu <yu.c.chen@intel.com>,
"Shrikanth Hegde" <sshegde@linux.ibm.com>,
Li Chen <chenl311@chinatelecom.cn>,
"Gautham R. Shenoy" <gautham.shenoy@amd.com>
Subject: Re: [PATCH v4 2/9] sched/topology: Extract "imb_numa_nr" calculation into a separate helper
Date: Mon, 16 Mar 2026 09:11:04 +0530 [thread overview]
Message-ID: <fee3a1da-689f-4f8a-aafb-ac958a5a11d7@amd.com> (raw)
In-Reply-To: <7182d0d5-be42-42bb-8864-189ddedbf534@arm.com>
Hello Dietmar,
On 3/16/2026 5:48 AM, Dietmar Eggemann wrote:
>> + /*
>> + * For a single LLC per node, allow an
>> + * imbalance up to 12.5% of the node. This is
>> + * arbitrary cutoff based two factors -- SMT and
>> + * memory channels. For SMT-2, the intent is to
>> + * avoid premature sharing of HT resources but
>> + * SMT-4 or SMT-8 *may* benefit from a different
>> + * cutoff. For memory channels, this is a very
>> + * rough estimate of how many channels may be
>> + * active and is based on recent CPUs with
>> + * many cores.
>> + *
>> + * For multiple LLCs, allow an imbalance
>> + * until multiple tasks would share an LLC
>> + * on one node while LLCs on another node
>> + * remain idle. This assumes that there are
>> + * enough logical CPUs per LLC to avoid SMT
>> + * factors and that there is a correlation
>> + * between LLCs and memory channels.
>> + */
>> + nr_llcs = sd_llc->parent->span_weight / sd_llc->span_weight;
>> + if (nr_llcs == 1)
>> + imb = sd_llc->parent->span_weight >> 3;
>> + else
>> + imb = nr_llcs;
>> +
>> + imb = max(1U, imb);
>> + sd_llc->parent->imb_numa_nr = imb;
>
> Here you set imb_numa_nr e.g. for PKG ...
Ack! That is indeed a redundant assign since it gets reassigned
in the bottom loop. For this commit, we have kept it 1:1 with the
loop that existed before in build_sched_domains().
>
>> +
>> + /*
>> + * Set span based on the first NUMA domain.
>> + *
>> + * NUMA systems always add a NODE domain before
>> + * iterating the NUMA domains. Since this is before
>> + * degeneration, start from sd_llc's parent's
>> + * parent which is the lowest an SD_NUMA domain can
>> + * be relative to sd_llc.
>> + */
>> + parent = sd_llc->parent->parent;
>> + while (parent && !(parent->flags & SD_NUMA))
>> + parent = parent->parent;
>> +
>> + imb_span = parent ? parent->span_weight : sd_llc->parent->span_weight;
>> +
>> + /* Update the upper remainder of the topology */
>> + parent = sd_llc->parent;
>> + while (parent) {
>> + int factor = max(1U, (parent->span_weight / imb_span));
>> +
>> + parent->imb_numa_nr = imb * factor;
>
> ... and here again.
>
> Shouldn't we only set it for 'if (parent->flags & SD_NUMA)'?
>
> Not sure if there are case in which PKG would persist in
>
> ... -> MC -> PKG -> NODE -> NUMA -> ... ?
>
> Although access to sd->imb_numa_nr seems to be guarded by sd->flags &
> SD_NUMA.
Indeed! "imb_numa_nr" only makes sense when looking at NUMA domains
and having it assigned to 1 for lower domains is harmless
(but wasteful indeed). I'm 99% sure we can simply do:
(Only build tested)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 43150591914b..e9068a809dbc 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2623,9 +2623,6 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc)
else
imb = nr_llcs;
- imb = max(1U, imb);
- sd_llc->parent->imb_numa_nr = imb;
-
/*
* Set span based on the first NUMA domain.
*
@@ -2639,10 +2636,14 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc)
while (parent && !(parent->flags & SD_NUMA))
parent = parent->parent;
- imb_span = parent ? parent->span_weight : sd_llc->parent->span_weight;
+ /* No NUMA domain to adjust imbalance for! */
+ if (!parent)
+ return;
+
+ imb = max(1U, imb);
+ imb_span = parent->span_weight;
/* Update the upper remainder of the topology */
- parent = sd_llc->parent;
while (parent) {
int factor = max(1U, (parent->span_weight / imb_span));
---
If we have NUMA domains, we definitely have NODE and NODE sets neither
SD_SHARE_LLC, nor SD_NUMA so likely sd->parent is PKG / NODE domain and
NUMA has to start at sd->parent->parent and it has to break at the first
SD_NUMA domains.
If it doesn't exist, we don't have any NUMA domains and nothing to worry
about, and if we do, the final loop will adjust the NUMA imbalance.
Thoughts? Again, this commit was kept 1:1 with the previous loop but we
can always improve :-)
>
>> + parent = parent->parent;
>> + }
>> +}
>> +
> [...]
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2026-03-16 3:41 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 4:44 [PATCH v4 0/9] sched/topology: Optimize sd->shared allocation K Prateek Nayak
2026-03-12 4:44 ` [PATCH v4 1/9] sched/topology: Compute sd_weight considering cpuset partitions K Prateek Nayak
2026-03-12 9:34 ` Peter Zijlstra
2026-03-12 9:59 ` K Prateek Nayak
2026-03-12 10:01 ` Peter Zijlstra
2026-03-12 10:09 ` K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-03-20 23:58 ` Nathan Chancellor
2026-03-21 3:36 ` K Prateek Nayak
2026-03-21 7:33 ` Chen, Yu C
2026-03-21 7:47 ` Chen, Yu C
2026-03-21 8:59 ` K Prateek Nayak
2026-03-21 9:45 ` K Prateek Nayak
2026-03-21 10:13 ` K Prateek Nayak
2026-03-21 12:48 ` Chen, Yu C
2026-03-24 2:54 ` K Prateek Nayak
2026-03-21 14:13 ` Shrikanth Hegde
2026-03-21 15:14 ` K Prateek Nayak
2026-03-21 16:38 ` [PATCH] sched/topology: Initialize sd_span after assignment to *sd K Prateek Nayak
2026-03-23 9:08 ` Shrikanth Hegde
2026-03-23 17:34 ` K Prateek Nayak
2026-03-23 9:36 ` Peter Zijlstra
2026-03-23 13:24 ` Jon Hunter
2026-03-23 15:36 ` Chen, Yu C
2026-03-23 17:24 ` K Prateek Nayak
2026-03-23 22:41 ` Nathan Chancellor
2026-03-24 9:10 ` [tip: sched/core] sched/topology: Fix sched_domain_span() tip-bot2 for Peter Zijlstra
2026-03-12 4:44 ` [PATCH v4 2/9] sched/topology: Extract "imb_numa_nr" calculation into a separate helper K Prateek Nayak
2026-03-12 13:37 ` kernel test robot
2026-03-12 15:42 ` K Prateek Nayak
2026-03-12 16:02 ` Peter Zijlstra
2026-03-16 0:18 ` Dietmar Eggemann
2026-03-16 3:41 ` K Prateek Nayak [this message]
2026-03-16 8:24 ` Dietmar Eggemann
2026-03-16 8:50 ` K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-03-12 4:44 ` [PATCH v4 3/9] sched/topology: Allocate per-CPU sched_domain_shared in s_data K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-03-12 4:44 ` [PATCH v4 4/9] sched/topology: Switch to assigning "sd->shared" from s_data K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-03-12 4:44 ` [PATCH v4 5/9] sched/topology: Remove sched_domain_shared allocation with sd_data K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-03-12 4:44 ` [PATCH v4 6/9] sched/core: Check for rcu_read_lock_any_held() in idle_get_state() K Prateek Nayak
2026-03-12 9:46 ` Peter Zijlstra
2026-03-12 10:06 ` K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-03-12 4:44 ` [PATCH v4 7/9] sched/fair: Remove superfluous rcu_read_lock() in the wakeup path K Prateek Nayak
2026-03-15 23:36 ` Dietmar Eggemann
2026-03-16 3:19 ` K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] PM: EM: Switch to rcu_dereference_all() in " tip-bot2 for Dietmar Eggemann
2026-03-18 8:08 ` [tip: sched/core] sched/fair: Remove superfluous rcu_read_lock() in the " tip-bot2 for K Prateek Nayak
2026-03-12 4:44 ` [PATCH v4 8/9] sched/fair: Simplify the entry condition for update_idle_cpu_scan() K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-03-12 4:44 ` [PATCH v4 9/9] sched/fair: Simplify SIS_UTIL handling in select_idle_cpu() K Prateek Nayak
2026-03-18 8:08 ` [tip: sched/core] " tip-bot2 for K Prateek Nayak
2026-03-16 0:22 ` [PATCH v4 0/9] sched/topology: Optimize sd->shared allocation Dietmar Eggemann
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=fee3a1da-689f-4f8a-aafb-ac958a5a11d7@amd.com \
--to=kprateek.nayak@amd.com \
--cc=bsegall@google.com \
--cc=chenl311@chinatelecom.cn \
--cc=dietmar.eggemann@arm.com \
--cc=gautham.shenoy@amd.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=sshegde@linux.ibm.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yu.c.chen@intel.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
Powered by JetHome