[PATCH 2/2] sched/deadline: Count only active CPUs when spreading extra_bw
From: Mathieu Desnoyers
Date: Tue Nov 17 2026 - 09:49:58 EST
__dl_add() and __dl_sub() change the total_bw of a root domain. They
also spread the change over the extra_bw of its CPUs, which GRUB uses
for SCHED_FLAG_RECLAIM tasks. __dl_update() changes only the active
CPUs, so the cpus argument must count those. Most callers pass
dl_bw_cpus(), which does.
dl_task_offline_migration() and dl_add_task_root_domain() pass
cpumask_weight(rd->span) instead. That also counts the inactive CPUs of
the span. A span holds one while that CPU goes offline, which is when
dl_task_offline_migration() runs. Each active CPU then gets a smaller
share of the change than it should. A later change made with
dl_bw_cpus() does not undo it exactly. extra_bw stays off until the
next rebuild of the root domains resets it. SCHED_FLAG_RECLAIM tasks
would reclaim a little more or less than their share meanwhile. This
was found by reading.
Fix this by passing dl_bw_cpus() of the CPU whose root domain changes.
Fixes: 59d06cea1198 ("sched/deadline: Fix bandwidth accounting at all levels after offline migration")
Fixes: f9a25f776d78 ("cpusets: Rebuild root domain deadline accounting information")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
---
kernel/sched/deadline.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 8c0c982810c1..d80f3f6bdf3a 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1021,7 +1021,7 @@ static struct rq *dl_task_offline_migration(struct rq *rq, struct task_struct *p
dl_b = &src_rq->rd->dl_bw;
raw_spin_lock(&dl_b->lock);
__dl_sub(dl_b, p->dl.dl_bw,
- cpumask_weight(src_rq->rd->span));
+ dl_bw_cpus(cpu_of(src_rq)));
raw_spin_unlock(&dl_b->lock);
}
/*
@@ -1033,7 +1033,7 @@ static struct rq *dl_task_offline_migration(struct rq *rq, struct task_struct *p
dl_b = &later_rq->rd->dl_bw;
raw_spin_lock(&dl_b->lock);
__dl_add(dl_b, p->dl.dl_bw,
- cpumask_weight(later_rq->rd->span));
+ dl_bw_cpus(cpu_of(later_rq)));
raw_spin_unlock(&dl_b->lock);
p->dl.dl_bw_cpu = later_rq->cpu;
p->dl.dl_bw_gen = dl_bw_gen;
@@ -4283,7 +4283,7 @@ void dl_add_task_root_domain(struct task_struct *p)
dl_b = &rq->rd->dl_bw;
raw_spin_lock(&dl_b->lock);
- __dl_add(dl_b, p->dl.dl_bw, cpumask_weight(rq->rd->span));
+ __dl_add(dl_b, p->dl.dl_bw, dl_bw_cpus(cpu));
raw_spin_unlock(&dl_b->lock);
p->dl.dl_bw_cpu = cpu;
p->dl.dl_bw_gen = dl_bw_gen;
--
2.47.3