From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Zicheng Qu <quzicheng@huawei.com>, <mingo@redhat.com>,
<peterz@infradead.org>, <juri.lelli@redhat.com>,
<vincent.guittot@linaro.org>, <dietmar.eggemann@arm.com>,
<rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>,
<vschneid@redhat.com>, <linux-kernel@vger.kernel.org>
Cc: <tanghui20@huawei.com>
Subject: Re: [PATCH] sched/fair: Fix vruntime drift by preventing double lag scaling during reweight
Date: Fri, 9 Jan 2026 15:51:30 +0530 [thread overview]
Message-ID: <14af463a-d21e-4239-9091-a667f200acff@amd.com> (raw)
In-Reply-To: <23574b3c-e990-45bc-b3f5-8664781adddf@huawei.com>
Hello Zicheng,
On 1/9/2026 2:10 PM, Zicheng Qu wrote:
> Hi Prateek,
>
> On 1/9/2026 12:50 PM, K Prateek Nayak wrote:
>> If I'm not mistaken, the problem is that we'll see "curr->on_rq" and
>> then do:
>>
>> if (curr && curr->on_rq)
>> load += scale_load_down(curr->load.weight);
>>
>> lag *= load + scale_load_down(se->load.weight);
>>
>>
>> which shouldn't be the case since we are accounting "se" twice when
>> it is also the "curr" and avg_vruntime() would have also accounted it
>> already since "curr->on_rq" and then we do everything twice for "se".
> Thanks for the analysis — I agree your concern is reasonable, but I
> think the issue here is slightly different from "accounting se twice",
> but a semantic mismatch in how place_entity() is used.
>
> place_entity() is meant to compensate lag for entities being inserted
> into the runqueue, accounting for the effect of a new entity on the
> weighted average vruntime. That assumption holds when an se is joining
> the rq. However, when se == cfs_rq->curr, the entity never left the
> runqueue and avg_vruntime() has not changed, so applying enqueue-style
> lag scaling is not appropriate.
I believe the intention is to discount the contribution of the
task and then re-account it again after the reweigh. I don't think
se being the "curr" makes it any different except for the fact that
its vruntime and load contribution isn't reflected in the sum and
is added in by avg_vruntime()
>> I'm wondering if instead of adding a flag, we can do:
> Yes, I totally agree that adding a new flag is unnecessary. We
> can handle this directly in place_entity() by skipping lag scaling in
> case of `se == cfs_rq->curr`, for example:
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index da46c3164537..1b279bf43f38 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -5123,6 +5123,15 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
>
> lag = se->vlag;
>
> + /*
> + * place_entity() compensates lag for entities being inserted into the
> + * runqueue. When se == cfs_rq->curr, the entity never left the rq and
> + * avg_vruntime() did not change, so enqueue-style lag scaling does not
> + * apply.
> + */
> + if (se == cfs_rq->curr)
> + goto skip_lag_scale;
This affects the place_entity() from enqueue_task() where se is dequeued
(se->on_rq == 0) but it is still the curr - can happen when rq drops
lock for newidle balance and a concurrent wakeup is queuing the task.
You need to check for "se == cfs_rq->curr && se->on_rq" here and then
this bit should be good.
Let me stare more at the avg_vruntime() since "curr->on_rq" would add
its vruntime too in that calculation.
> +
> /*
> * If we want to place a task and preserve lag, we have to
> * consider the effect of the new entity on the weighted
> @@ -5185,6 +5194,7 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
> lag = div_s64(lag, load);
> }
>
> +skip_lag_scale:
> se->vruntime = vruntime - lag;
>
> if (se->rel_deadline) {
>
> Best regards,
> Zicheng
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2026-01-09 10:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-26 0:17 [PATCH] sched/fair: Fix vruntime drift by preventing double lag scaling during reweight Zicheng Qu
2026-01-08 6:27 ` Zicheng Qu
2026-01-09 4:50 ` K Prateek Nayak
2026-01-09 8:40 ` Zicheng Qu
2026-01-09 10:21 ` K Prateek Nayak [this message]
2026-01-12 4:03 ` Zicheng Qu
2026-01-26 21:23 ` Peter Zijlstra
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=14af463a-d21e-4239-9091-a667f200acff@amd.com \
--to=kprateek.nayak@amd.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=quzicheng@huawei.com \
--cc=rostedt@goodmis.org \
--cc=tanghui20@huawei.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox