[PATCH v2 2/3] sched/fair: Skip rq_offline_fair() work for CPUs that stay active
From: Qiliang Yuan
Date: Wed Nov 18 2026 - 19:57:50 EST
A sched domain rebuild, triggered by CPU hotplug or a cpuset partition
change, calls rq_attach_root() for every active CPU in the affected
domains. That takes the CPU offline and back online with the rq lock
held and interrupts disabled, so rq_offline_fair() runs for CPUs that
are not going down.
Commit af98d8a36a96 ("sched/fair: Fix CPU bandwidth limit bypass during
CPU hotplug") made unthrottle_offline_cfs_rqs() return early for active
CPUs, but clear_tg_offline_cfs_rqs(), added by commit f60a631ab9ed
("sched/fair: Fix tg->load when offlining a CPU"), still walks every
task group and drops the CPU's tg->load_avg contribution, which
update_tg_load_avg() then adds back. With thousands of cpu cgroups each
rebuild costs O(nr_cpus * nr_task_groups).
Return early from rq_offline_fair() unless the CPU is going down, which
covers both walks, and drop the active check from
unthrottle_offline_cfs_rqs().
With 4000 cpu cgroups on a 32-CPU VM booted with rt_group_sched=0,
switching a 4-CPU cpuset to a partition root and offlining or onlining
one CPU take (median of 20 partition switches and 16 hotplug operations):
operation before (ms) after (ms) change
partition root 14.86 8.35 -44%
cpu offline 49.99 33.91 -32%
cpu online 36.10 31.02 -14%
Signed-off-by: Qiliang Yuan <qiliang.yuan@xxxxxxxxx>
---
kernel/sched/fair.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index db9ab8ce36500..1b38c4c47b656 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7859,10 +7859,6 @@ static void __maybe_unused unthrottle_offline_cfs_rqs(struct rq *rq)
lockdep_assert_rq_held(rq);
- // Do not unthrottle for an active CPU
- if (cpumask_test_cpu(cpu_of(rq), cpu_active_mask))
- return;
-
/*
* The rq clock has already been updated in the
* set_rq_offline(), so we should skip updating
@@ -15093,6 +15089,9 @@ static void rq_offline_fair(struct rq *rq, bool hotplug)
{
update_sysctl();
+ if (!hotplug)
+ return;
+
/* Ensure any throttled groups are reachable by pick_next_task */
unthrottle_offline_cfs_rqs(rq);
--
2.43.0