[PATCH 2/2] sched/topology: Claim sched_domain_shared by span weight

From: Keisuke Nishimura

Date: Thu Dec 03 2026 - 07:54:11 EST


Currently, init_sched_domain_shared() selects the first
sched_domain_shared in the domain span that is either unclaimed
or claimed with the same SD flag (SD_ASYM_CPUCAPACITY or SD_SHARE_LLC).

This allows nested domains with different spans to share the same
sched_domain_shared when both claim it with SD_ASYM_CPUCAPACITY.
Consider the following nested SD_ASYM_CPUCAPACITY_FULL domains:

CPU 0 1 2 3
Capacity 512 1024 1024 1024
SD_ASYM_CPUCAPACITY_FULL (inner) [---------]
SD_ASYM_CPUCAPACITY_FULL (outer) [---------------------]

Current This patch
Domain alloc_flags SDS Span weight SDS
Inner SD_ASYM_CPUCAPACITY SDS[0] 2 SDS[0]
Outer SD_ASYM_CPUCAPACITY SDS[0] 4 SDS[1]

Use the span weight instead of the SD flag as the claim key.
Neither caller claims SD_NUMA domains, and non-NUMA domains
containing the same CPU are nested, so they have different weights
whenever their spans differ.

Fixes: 9e005ed21152 ("sched/topology: Allow multiple domains to claim sched_domain_shared")
Signed-off-by: Keisuke Nishimura <keisuke.nishimura@xxxxxxxx>
---
include/linux/sched/topology.h | 11 ++++-------
kernel/sched/topology.c | 15 +++++++--------
2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
index f96812d71c51..378cd469134b 100644
--- a/include/linux/sched/topology.h
+++ b/include/linux/sched/topology.h
@@ -70,17 +70,14 @@ struct sched_domain_shared {
union {
int nr_idle_scan;
/*
- * Used during allocation to claim the sched_domain_shared
- * object at multiple levels.
+ * Span weight used to claim this object during allocation.
+ * Distinct overlapping spans (non-NUMA) have different weights.
*
* Note: between build and the first periodic LB tick, which
* rewrites the union via update_idle_cpu_scan(), readers of
- * nr_idle_scan may observe the transient SD_* flag value as
- * the scan bound. The flag bits are small positive integers,
- * so the effect is just a slightly relaxed scan bound for one
- * window and self-heals on the first tick.
+ * nr_idle_scan may observe the span weight as the scan bound.
*/
- int alloc_flags;
+ int alloc_weight;
};
#ifdef CONFIG_SCHED_CACHE
unsigned long util_avg;
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index c9f91da1462b..fe75a7876388 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2954,7 +2954,7 @@ static void adjust_numa_imbalance(struct sched_domain *sd_llc)
}

static void
-init_sched_domain_shared(struct s_data *d, struct sched_domain *sd, int flags)
+init_sched_domain_shared(struct s_data *d, struct sched_domain *sd)
{
struct sched_domain_shared *sds = NULL;
int cpu;
@@ -2967,8 +2967,7 @@ init_sched_domain_shared(struct s_data *d, struct sched_domain *sd, int flags)
* load balancing.
*
* Find the first CPU in sched_domain_span(sd) with an
- * unclaimed domain (!alloc_flags) or where the alloc_flag
- * matches the requested flag (SD_* flag)
+ * unclaimed object (!alloc_weight) or one with the same span weight.
*
* If the domain only has single CPU, allow temporary overlap
* in allocation since the domains will be degenerated later.
@@ -2976,9 +2975,9 @@ init_sched_domain_shared(struct s_data *d, struct sched_domain *sd, int flags)
for_each_cpu(cpu, sched_domain_span(sd)) {
sds = *per_cpu_ptr(d->sds, cpu);

- if (!sds->alloc_flags ||
- sds->alloc_flags == flags) {
- sds->alloc_flags = flags;
+ if (!sds->alloc_weight ||
+ sds->alloc_weight == sd->span_weight) {
+ sds->alloc_weight = sd->span_weight;
sd->shared = sds;
break;
}
@@ -3035,7 +3034,7 @@ static bool claim_asym_sched_domain_shared(struct s_data *d, int cpu)
if (!sd_asym || (sd_asym->flags & SD_NUMA))
return false;

- init_sched_domain_shared(d, sd_asym, SD_ASYM_CPUCAPACITY);
+ init_sched_domain_shared(d, sd_asym);
return true;
}

@@ -3196,7 +3195,7 @@ build_sched_domains(const struct cpumask *cpu_map, struct sched_domain_attr *att
* sd->shared and leaks the first reference.
*/
if (!sd->shared)
- init_sched_domain_shared(&d, sd, SD_SHARE_LLC);
+ init_sched_domain_shared(&d, sd);

/*
* In presence of higher domains, adjust the
--
2.34.1