From: sashiko-bot@kernel.org
To: quzicheng315@gmail.com
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH v3] sched/fair: Rebuild load weight when switching to fair
Date: Sat, 30 May 2026 05:06:08 +0000 [thread overview]
Message-ID: <20260530050609.0D0FB1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260528131238.3879110-1-quzicheng315@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Updating task load weight without scaling its PELT averages corrupts load_sum when attaching to fair.
--
commit 5e323dec0121afc6858dcf6c332ec85a8dc01718
Author: Zicheng Qu <quzicheng@huawei.com>
sched/fair: Rebuild load weight when switching to fair
Tasks running outside the fair scheduling class may not keep their
load weight in sync. This commit rebuilds the load weight from the
switching_to hook before enqueueing back into fair.
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 62a2dcb0d03e6..3671b512dcf7f 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
[ ... ]
> @@ -14957,6 +14957,15 @@ static void switched_from_fair(struct rq *rq, struct task_struct *p)
> detach_task_cfs_rq(p);
> }
>
> +static void switching_to_fair(struct rq *rq, struct task_struct *p)
> +{
> + /*
> + * Tasks may come from classes that don't keep se.load up to date.
> + * Rebuild it before the task is enqueued.
> + */
> + set_load_weight(p, false);
[Severity: High]
Does updating the task load weight without scaling its PELT averages corrupt
load_sum when attaching to fair?
When a task transitions to fair, switched_to_fair() enqueues it by calling
attach_task_cfs_rq() -> attach_entity_load_avg(). The attach_entity_load_avg()
function relies on se.load.weight matching se.avg.load_avg to reconstruct the
unweighted load_sum:
kernel/sched/fair.c:attach_entity_load_avg() {
...
se->avg.load_sum = div_u64(se->avg.load_sum, se_weight(se));
...
}
Since load_avg is based on the old weight but se_weight() returns the newly
updated weight, load_sum ends up mathematically scaled by old_weight /
new_weight. If a task's nice value was changed to a lower priority (smaller
weight) while outside fair, load_sum could be artificially inflated by a
massive factor, polluting cfs_rq->avg and disrupting CPU load balancing.
> +}
> +
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260528131238.3879110-1-quzicheng315@gmail.com?part=1
prev parent reply other threads:[~2026-05-30 5:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 13:52 [PATCH] sched_ext: Rebuild fair weight when disabling BPF scheduler Zicheng Qu
2026-05-26 15:18 ` sashiko-bot
2026-05-26 17:20 ` Andrea Righi
2026-05-27 9:40 ` [PATCH v2] sched_ext: Rebuild fair weight on ext to fair switches quzicheng315
2026-05-27 11:26 ` Peter Zijlstra
2026-05-28 2:53 ` Zicheng Qu
2026-05-28 9:25 ` Peter Zijlstra
2026-05-28 13:12 ` [PATCH v3] sched/fair: Rebuild load weight when switching to fair quzicheng315
2026-05-28 14:27 ` Tejun Heo
2026-05-30 5:06 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260530050609.0D0FB1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=quzicheng315@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.