[PATCH v2 0/3] sched/fair: Cut per-group work from sched domain rebuilds

From: Qiliang Yuan

Date: Wed Nov 18 2026 - 19:57:37 EST


A sched domain rebuild, from CPU hotplug or a cpuset partition change,
moves every active CPU to a new root domain through rq_attach_root().
For each of them rq_offline_fair() and rq_online_fair() walk all task
groups with the rq lock held and interrupts disabled, so a rebuild
costs O(nr_cpus * nr_task_groups). Dietmar pointed at the offline side
when f60a631ab9ed was reviewed [1]. Hosts running AI agent harnesses
commonly carry over a thousand cpu cgroups, and their VMs hot-add
vCPUs at run time.

Patch 1 tells the rq_online() and rq_offline() callbacks whether the
CPU actually changes state. Patches 2 and 3 use that to skip the two
fair walks when it doesn't.

With 4000 cpu cgroups on a 32-CPU VM booted with rt_group_sched=0
(median of 20 partition switches and 16 hotplug operations, all three
kernels measured in the same run):

operation base (ms) patch 1-2 (ms) patch 1-3 (ms) change
partition root 14.86 8.35 1.20 -92%
cpu offline 49.99 33.91 16.49 -67%
cpu online 36.10 31.02 12.87 -64%

Each rq_attach_root() call, which runs with interrupts disabled, takes
(1280 calls over the 20 partition switches):

kernel median (us) p90 (us) max (us) change
base 229 256 6987
patch 1-2 122 162 988 -47%
patch 1-3 2 3 118 -99%

With all three patches, partition switches and onlining no longer grow
with the number of groups; offlining still walks them once for the CPU
that goes down. With RT_GROUP_SCHED enabled, the rt.c runtime walks
remain.

K Prateek Nayak proposed separate rq_attach_root() and rq_detach_root()
callbacks for the root domain moves instead [2]. This series follows
Peter's suggestion of a hotplug argument to rq_online() and rq_offline();
I'm happy to redo it on top of Prateek's approach if that is preferred.

[1] https://lore.kernel.org/r/dbd36b16-4acb-415a-9bbd-258b2e022475@xxxxxxx
[2] https://lore.kernel.org/r/e1a63a3c-3975-4b05-8ab4-518c37d867d6@xxxxxxx

Signed-off-by: Qiliang Yuan <qiliang.yuan@xxxxxxxxx>
---
V1 -> V2:
- Pass a hotplug argument to rq_online() and rq_offline() instead of
adding a member to struct rq, as Peter suggested
- Skip both fair task group walks on rebuilds, which leaves no second
loop to merge
- Rebase onto tip/sched/core, where sched_ext no longer implements
rq_online() and rq_offline(), and update the numbers from a new run

CPU hotplug and partition flips were also run with SCHED_FIFO tasks
(rt_group_sched=1, RT_RUNTIME_SHARE on and off), SCHED_DEADLINE tasks
and scx_simple loaded, plus the sched_ext selftests, with the same
results as on tip/sched/core (b251360cb2e6c).

v1: https://lore.kernel.org/r/20261111-bug-sched-fair-offline-active-v1-0-4f54523c5a70@xxxxxxxxx

---
Qiliang Yuan (3):
sched: Tell rq_online() and rq_offline() whether the CPU changes state
sched/fair: Skip rq_offline_fair() work for CPUs that stay active
sched/fair: Avoid re-syncing runtime_enabled on root domain changes

kernel/sched/core.c | 12 ++++++------
kernel/sched/deadline.c | 4 ++--
kernel/sched/fair.c | 15 ++++++++-------
kernel/sched/rt.c | 4 ++--
kernel/sched/sched.h | 8 ++++----
kernel/sched/topology.c | 13 ++++++++++---
6 files changed, 32 insertions(+), 24 deletions(-)
---
base-commit: b251360cb2e6c7b74d962831f5797a4520511b36
change-id: 20261111-bug-sched-fair-offline-active-8d063e735d3f

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