From: Peter Zijlstra <peterz@infradead.org>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: mingo@redhat.com, juri.lelli@redhat.com,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
kprateek.nayak@amd.com, linux-kernel@vger.kernel.org,
shubhang@os.amperecomputing.com
Subject: Re: [PATCH v2] sched: fair: Prevent negative lag increase during delayed dequeue
Date: Thu, 23 Apr 2026 11:41:07 +0200 [thread overview]
Message-ID: <20260423094107.GT3102624@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAKfTPtDNAa8+G91srcasAaVWd8Q80BC=TJf3aEyBSTT-JBjLBA@mail.gmail.com>
On Thu, Apr 23, 2026 at 09:28:22AM +0200, Vincent Guittot wrote:
> On Thu, 23 Apr 2026 at 00:20, Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Wed, Apr 22, 2026 at 04:28:28PM +0200, Peter Zijlstra wrote:
> >
> > > Let me ponder this a bit...
> >
> > Like this? Or am I still making a mess of things? AFAICT this is the
> > exact same as your initial version.
> >
> > ---
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index 69361c63353a..24e8c78b110a 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -847,13 +847,13 @@ static s64 entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se, u64 avrunt
> > * Similarly, check that the entity didn't gain positive lag when DELAY_ZERO
> > * is set.
> > *
> > - * Return true if the lag has been adjusted.
> > + * Return true if the lag of a delayed entity has been adjusted.
> > */
> > static __always_inline
> > bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
> > {
> > s64 vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq));
> > - bool ret;
> > + bool ret = false;
> >
> > WARN_ON_ONCE(!se->on_rq);
> >
> > @@ -862,8 +862,9 @@ bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
> > vlag = max(vlag, se->vlag);
> > if (sched_feat(DELAY_ZERO))
> > vlag = min(vlag, 0);
> > +
> > + ret = (vlag != se->vlag);
>
> No this is not enough.
Argh yes. I think I finally see. How about this then?
---
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 69361c63353a..f4d1457d1837 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -847,13 +847,19 @@ static s64 entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se, u64 avrunt
* Similarly, check that the entity didn't gain positive lag when DELAY_ZERO
* is set.
*
- * Return true if the lag has been adjusted.
+ * Return true if the vlag has been modified. Specifically:
+ *
+ * se->vlag != avg_vruntime() - se->vruntime
+ *
+ * This can be due to clamping in entity_lag() or clamping due to
+ * sched_delayed. Either way, when vlag is modified and the entity is
+ * retained, the tree needs to be adjusted.
*/
static __always_inline
bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
{
- s64 vlag = entity_lag(cfs_rq, se, avg_vruntime(cfs_rq));
- bool ret;
+ u64 avruntime = avg_vruntime(cfs_rq);
+ s64 vlag = entity_lag(cfs_rq, se, avruntime);
WARN_ON_ONCE(!se->on_rq);
@@ -863,10 +869,9 @@ bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
if (sched_feat(DELAY_ZERO))
vlag = min(vlag, 0);
}
- ret = (vlag == se->vlag);
se->vlag = vlag;
- return ret;
+ return avruntime - vlag != se->vruntime;
}
/*
next prev parent reply other threads:[~2026-04-23 9:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 16:23 [PATCH v2] sched: fair: Prevent negative lag increase during delayed dequeue Vincent Guittot
2026-04-02 13:13 ` Peter Zijlstra
2026-04-02 13:17 ` Vincent Guittot
2026-04-17 17:18 ` Vincent Guittot
2026-04-22 13:39 ` Peter Zijlstra
2026-04-22 14:06 ` Vincent Guittot
2026-04-22 14:24 ` Peter Zijlstra
2026-04-22 14:28 ` Peter Zijlstra
2026-04-22 14:46 ` Vincent Guittot
2026-04-22 22:20 ` Peter Zijlstra
2026-04-23 7:28 ` Vincent Guittot
2026-04-23 9:41 ` Peter Zijlstra [this message]
2026-04-23 10:27 ` Vincent Guittot
2026-04-23 12:12 ` Vincent Guittot
2026-04-02 13:42 ` Peter Zijlstra
2026-04-02 19:27 ` Shubhang Kaushik
2026-04-03 8:37 ` Vincent Guittot
2026-04-04 8:08 ` Shubhang Kaushik
2026-04-03 8:46 ` Vincent Guittot
2026-04-03 12:30 ` [tip: sched/core] sched/fair: " tip-bot2 for Vincent Guittot
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=20260423094107.GT3102624@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--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=rostedt@goodmis.org \
--cc=shubhang@os.amperecomputing.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