mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/topology: Count LLCs per node from the sched groups
@ 2026-11-25 13:19 Qiliang Yuan
  0 siblings, 0 replies; only message in thread
From: Qiliang Yuan @ 2026-11-25 13:19 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak, Gautham R. Shenoy
  Cc: linux-kernel, Li kunyu, Qiliang Yuan

adjust_numa_imbalance() sets imb_numa_nr from the number of LLCs under
the LLC's parent domain, so that tasks spill over to another node only
once every LLC of the local node is in use.  It estimates that number
by dividing the parent's span weight by the LLC's.

The division assumes all LLCs in a node are the same size.  On a Hygon
C86-4G 7493 each node has four CCXs of 4, 4, 3 and 3 cores, as two core
slots per node are fused off, giving LLCs of 8, 8, 6 and 6 CPUs out of
28.  CPUs in the larger CCXs compute 28 / 8 = 3 LLCs and the others
28 / 6 = 4, so CPUs of the same node apply different imbalance limits
at every NUMA level.

Count the parent's sched groups instead.  They are built from the child
domains, one per LLC, before imb_numa_nr is computed, and give the same
count as the division when all LLCs are the same size.

imb_numa_nr per domain on a KVM guest with that node layout (2 sockets
x 2 nodes, SLIT 15/25/27, fused-off core slots offlined), read through
a debugfs file added for the test; change is for the 4-core CCXs:

  domain (CPUs)  before, 4-core CCX  before, 3-core CCX  after  change
  NODE (28)                       3                   4      4    +33%
  NUMA (56)                       3                   4      4    +33%
  NUMA (84)                       3                   4      4    +33%
  NUMA (112)                      6                   8      8    +33%

Fixes: e496132ebedd ("sched/fair: Adjust the allowed NUMA imbalance when SD_NUMA spans multiple LLCs")
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 kernel/sched/topology.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 99878da03bce7..7efb2cde5534f 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2893,8 +2893,9 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc)
 {
 	struct sched_domain *parent;
 	unsigned int imb_span = 1;
+	unsigned int nr_llcs = 0;
+	struct sched_group *sg;
 	unsigned int imb = 0;
-	unsigned int nr_llcs;
 
 	WARN_ON(!(sd_llc->flags & SD_SHARE_LLC));
 	WARN_ON(!sd_llc->parent);
@@ -2918,8 +2919,19 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc)
 	 * enough logical CPUs per LLC to avoid SMT
 	 * factors and that there is a correlation
 	 * between LLCs and memory channels.
+	 *
+	 * Count the LLCs through the parent's groups, one
+	 * per LLC, rather than dividing the spans: LLCs
+	 * in a node need not be the same size (e.g. when
+	 * some cores of a CCX are fused off), and the
+	 * quotient then depends on which LLC the CPU is in.
 	 */
-	nr_llcs = sd_llc->parent->span_weight / sd_llc->span_weight;
+	sg = sd_llc->parent->groups;
+	do {
+		nr_llcs++;
+		sg = sg->next;
+	} while (sg != sd_llc->parent->groups);
+
 	if (nr_llcs == 1)
 		imb = sd_llc->parent->span_weight >> 3;
 	else

---
base-commit: c47af85667065c6dd5b79564203c2d29948ef60e
change-id: 20261125-feat-sched-nr-llcs-a1a82664eac0

Best regards,
-- 
Qiliang Yuan <qiliang.yuan@linux.dev>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-25 13:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 13:19 [PATCH] sched/topology: Count LLCs per node from the sched groups Qiliang Yuan

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®