public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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
Subject: Re: [PATCH] sched: fair: Prevent negative lag increase during delayed dequeue
Date: Mon, 30 Mar 2026 16:06:53 +0200	[thread overview]
Message-ID: <20260330140653.GO3738010@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260327180219.2879905-1-vincent.guittot@linaro.org>

On Fri, Mar 27, 2026 at 07:02:19PM +0100, Vincent Guittot wrote:
> Delayed dequeue feature aims to reduce the negative lag of a dequeued task
> while sleeping but it can happens that newly enqueued tasks will move
> backward the avg vruntime and increase its negative lag.
> When the delayed dequeued task wakes up, it has more neg lag compared to
> being dequeued immediately or to other delayed or not tasks that have been
> dequeued just before theses new enqueues.
> 
> Ensure that the negative lag of a delayed dequeued task doesn't increase
> during its delayed dequeued phase while waiting for its neg lag to
> diseappear. Similarly, we remove any positive lag that the delayed
> dequeued task could have gain during thsi period.

*groan*, indeed!


> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
>  kernel/sched/fair.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 226509231e67..efa9dfa8c583 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -5595,6 +5595,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
>  		if (sched_feat(DELAY_DEQUEUE) && delay &&
>  		    !entity_eligible(cfs_rq, se)) {
>  			update_load_avg(cfs_rq, se, 0);
> +			update_entity_lag(cfs_rq, se);
>  			set_delayed(se);
>  			return false;
>  		}
> @@ -7089,12 +7090,16 @@ requeue_delayed_entity(struct sched_entity *se)
>  	WARN_ON_ONCE(!se->on_rq);
>  
>  	if (sched_feat(DELAY_ZERO)) {
> +		s64 vlag, prev_vlag = se->vlag;
>  		update_entity_lag(cfs_rq, se);
> -		if (se->vlag > 0) {
> +		/* prev_vlag < 0 otherwise se would not be delayed */
> +		vlag = clamp(se->vlag, prev_vlag, 0);
> +
> +		if (vlag != se->vlag) {
>  			cfs_rq->nr_queued--;
>  			if (se != cfs_rq->curr)
>  				__dequeue_entity(cfs_rq, se);
> -			se->vlag = 0;
> +			se->vlag = vlag;
>  			place_entity(cfs_rq, se, 0);
>  			if (se != cfs_rq->curr)
>  				__enqueue_entity(cfs_rq, se);

So I think this should apply irrespective of DELAY_ZERO -- although
since we default to that, it is the most relevant.

Also, I'm thinking we might want a comment with this. We're bound to
forget the details at some point.

Also, there is one other site that has DLAY_ZERO/clear_delayed(), does
that want updating too?

  reply	other threads:[~2026-03-30 14:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-27 18:02 [PATCH] sched: fair: Prevent negative lag increase during delayed dequeue Vincent Guittot
2026-03-30 14:06 ` Peter Zijlstra [this message]
2026-03-30 14:46   ` Vincent Guittot
2026-03-30 21:32     ` Shubhang Kaushik
2026-03-31  8:54       ` 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=20260330140653.GO3738010@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=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