Skip to contentSkip to conversation

sched/topology: Balance cluster static-key updates

PATCH New Hui Su 1 participant 1 message Oct 22 Scheduler

lore
Share & tools
lore

Hui Su

author
#0 lore raw

PATCH v3 1/1 sched/topology: Balance cluster static-key updates

build_sched_domains() increments sched_cluster_active once per newly built partition that contains an SD_CLUSTER domain. detach_destroy_domains() instead tested the global static key before decrementing it, so destroying a cluster-less partition could drop a reference owned by another partition and disable cluster-aware scheduling while SD_CLUSTER domains remained installed.

Check the installed domains before detaching them, only while the key is enabled, and decrement only when the removed partition contains an SD_CLUSTER domain.

With two cluster-bearing partitions installed, removing a singleton partition left the baseline count at 1 where 2 partitions still carried SD_CLUSTER; the fixed kernel correctly reports 2. On an asymmetric cluster topology where the parent partition gains no cluster domain, the baseline count drops to 0 while a cluster partition remains installed; the fixed kernel keeps it at 1.

Fixes 8881e1639f1f ("sched/fair: Scan cluster before scanning LLC in wake-up path")

---

Changes in v3:
- Combine SD_CLUSTER detection with the existing domain detach loop, avoiding a second CPU mask walk and RCU read-side section. (Tim Chen)
- Decrement sched_cluster_active after detaching the domains.
- Add Cc: [email protected] for stable backport consideration.

v2: https://lore.kernel.org/r/[email protected]
v1: https://lore.kernel.org/r/[email protected]

---
 kernel/sched/topology.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
kernel/sched/topology.c +10 -4
index 3dab0253976f..3bf28aefac1c 100644
@@ -3314,18 +3314,24 @@ int __init sched_init_domains(const struct cpumask *cpu_map)
 static void detach_destroy_domains(const struct cpumask *cpu_map)
 {
 	unsigned int cpu = cpumask_any(cpu_map);
+	bool has_cluster = false;
 	int i;
 
 	if (rcu_access_pointer(per_cpu(sd_asym_cpucapacity, cpu)))
 		static_branch_dec_cpuslocked(&sched_asym_cpucapacity);
 
-	if (static_branch_unlikely(&sched_cluster_active))
-		static_branch_dec_cpuslocked(&sched_cluster_active);
-
 	rcu_read_lock();
-	for_each_cpu(i, cpu_map)
+	for_each_cpu(i, cpu_map) {
+		if (!has_cluster && static_branch_unlikely(&sched_cluster_active) &&
+		    lowest_flag_domain(i, SD_CLUSTER))
+			has_cluster = true;
+
 		cpu_attach_domain(NULL, &def_root_domain, i);
+	}
 	rcu_read_unlock();
+
+	if (has_cluster)
+		static_branch_dec_cpuslocked(&sched_cluster_active);
 }
 
 /* handle null as "default" */
Signature · 1 line
2.55.0