[PATCH 2/7] sched: restore preferred CPUs when hotplug removes the last one
From: Yury Norov
Date: Fri Nov 13 2026 - 14:51:20 EST
Offlining the last preferred CPU leaves cpu_preferred_mask empty. Normal
fair load balancing stops, potentially leaving CPUs idle while having
queued tasks.
Currently, steal governor is the only module that may modify the mask,
so it takes care of it by resetting the mask to mirror the active cpumask.
The design allows alternative preferred cpumask managers; relying on
loadable modules to maintain consistency of the core data structure
is not worthwhile in general.
Restore all remaining active CPUs as preferred in sched_cpu_deactivate()
path, without relying on the steal governor to recover.
Signed-off-by: Yury Norov <ynorov@xxxxxxxxxx>
---
kernel/sched/core.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 175b52a7ea79..b5c158c4efad 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8723,6 +8723,14 @@ int sched_cpu_deactivate(unsigned int cpu)
set_cpu_active(cpu, false);
+#ifdef CONFIG_PREFERRED_CPU
+ if (cpumask_empty(cpu_preferred_mask)) {
+ pr_notice("sched: last preferred CPU%u offlined; make all active CPUs preferred\n",
+ cpu);
+ reset_preferred_cpumask();
+ }
+#endif
+
/*
* From this point forward, this CPU will refuse to run any task that
* is not: migrate_disable() or KTHREAD_IS_PER_CPU, and will actively
--
2.53.0