[tip: sched/urgent] sched/fair: Adhere to place_entity() constraints

tip-bot2 for Peter Zijlstra posted 1 patch 12 months ago
There is a newer version of this series
kernel/sched/fair.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[tip: sched/urgent] sched/fair: Adhere to place_entity() constraints
Posted by tip-bot2 for Peter Zijlstra 12 months ago
The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     55294004b122c997591d9de8446f5a4c60402805
Gitweb:        https://git.kernel.org/tip/55294004b122c997591d9de8446f5a4c60402805
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Tue, 28 Jan 2025 15:39:49 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Sat, 08 Feb 2025 15:43:12 +01:00

sched/fair: Adhere to place_entity() constraints

Mike reports that commit 6d71a9c61604 ("sched/fair: Fix EEVDF entity
placement bug causing scheduling lag") relies on commit 4423af84b297
("sched/fair: optimize the PLACE_LAG when se->vlag is zero") to not
trip a WARN in place_entity().

What happens is that the lag of the very last entity is 0 per
definition -- the average of one element matches the value of that
element. Therefore place_entity() will match the condition skipping
the lag adjustment:

  if (sched_feat(PLACE_LAG) && cfs_rq->nr_queued && se->vlag) {

Without the 'se->vlag' condition -- it will attempt to adjust the zero
lag even though we're inserting into an empty tree.

Notably, we should have failed the 'cfs_rq->nr_queued' condition, but
don't because they didn't get updated.

Additionally, move update_load_add() after placement() as is
consistent with other place_entity() users -- this change is
non-functional, place_entity() does not use cfs_rq->load.

Fixes: 6d71a9c61604 ("sched/fair: Fix EEVDF entity placement bug causing scheduling lag")
Reported-by: Mike Galbraith <efault@gmx.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20250128143949.GD7145@noisy.programming.kicks-ass.net
---
 kernel/sched/fair.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index f4e4d3e..d0b10e1 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3782,6 +3782,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 		update_entity_lag(cfs_rq, se);
 		se->deadline -= se->vruntime;
 		se->rel_deadline = 1;
+		cfs_rq->nr_queued--;
 		if (!curr)
 			__dequeue_entity(cfs_rq, se);
 		update_load_sub(&cfs_rq->load, se->load.weight);
@@ -3808,10 +3809,11 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 
 	enqueue_load_avg(cfs_rq, se);
 	if (se->on_rq) {
-		update_load_add(&cfs_rq->load, se->load.weight);
 		place_entity(cfs_rq, se, 0);
+		update_load_add(&cfs_rq->load, se->load.weight);
 		if (!curr)
 			__enqueue_entity(cfs_rq, se);
+		cfs_rq->nr_queued++;
 
 		/*
 		 * The entity's vruntime has been adjusted, so let's check
Re: [PATCH 6.12 000/122] 6.12.11-rc1 review
Posted by Mushahid Hussain 8 months, 2 weeks ago
> The following commit has been merged into the sched/urgent branch of tip:
> 
> Commit-ID:     55294004b122c997591d9de8446f5a4c60402805
> Gitweb:        https://git.kernel.org/tip/55294004b122c997591d9de8446f5a4c60402805
> Author:        Peter Zijlstra <peterz@infradead.org>
> AuthorDate:    Tue, 28 Jan 2025 15:39:49 +01:00
> Committer:     Peter Zijlstra <peterz@infradead.org>
> CommitterDate: Sat, 08 Feb 2025 15:43:12 +01:00

Was this merged to sched/urgent or any other branches/RCs? Given gitweb link
sends me to "Bad commit reference". I don't see this commit in sched/urgent:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=sched%2Furgent
Re: [PATCH 6.12 000/122] 6.12.11-rc1 review
Posted by David Woodhouse 8 months, 2 weeks ago
On Fri, 2025-05-23 at 16:01 +0000, Mushahid Hussain wrote:
> > The following commit has been merged into the sched/urgent branch of tip:
> > 
> > Commit-ID:     55294004b122c997591d9de8446f5a4c60402805
> > Gitweb:        https://git.kernel.org/tip/55294004b122c997591d9de8446f5a4c60402805
> > Author:        Peter Zijlstra <peterz@infradead.org>
> > AuthorDate:    Tue, 28 Jan 2025 15:39:49 +01:00
> > Committer:     Peter Zijlstra <peterz@infradead.org>
> > CommitterDate: Sat, 08 Feb 2025 15:43:12 +01:00
> 
> Was this merged to sched/urgent or any other branches/RCs? Given gitweb link
> sends me to "Bad commit reference". I don't see this commit in sched/urgent:
> https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/log/?h=sched%2Furgent

I think something weird has just happened to the tip tree. All the
tip/x86/* branches also seem to have been reset to Linux 6.15-rc6.