public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Zicheng Qu <quzicheng@huawei.com>
To: K Prateek Nayak <kprateek.nayak@amd.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>, <quzicheng@huawei.com>
Subject: Re: [PATCH] sched/fair: Fix vruntime drift by preventing double lag scaling during reweight
Date: Fri, 9 Jan 2026 16:40:40 +0800	[thread overview]
Message-ID: <23574b3c-e990-45bc-b3f5-8664781adddf@huawei.com> (raw)
In-Reply-To: <0615d2c6-c963-46ff-9088-d85e3821eec8@amd.com>

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'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;
+
                 /*
                  * 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

  reply	other threads:[~2026-01-09  8:40 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 [this message]
2026-01-09 10:21     ` K Prateek Nayak
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=23574b3c-e990-45bc-b3f5-8664781adddf@huawei.com \
    --to=quzicheng@huawei.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --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