From: Fernand Sieber <sieberf@amazon.com>
To: <peterz@infradead.org>
Cc: <bsegall@google.com>, <dietmar.eggemann@arm.com>,
<dwmw@amazon.co.uk>, <graf@amazon.com>, <jschoenh@amazon.de>,
<juri.lelli@redhat.com>, <linux-kernel@vger.kernel.org>,
<mingo@redhat.com>, <sieberf@amazon.com>, <tanghui20@huawei.com>,
<vincent.guittot@linaro.org>, <vineethr@linux.ibm.com>,
<wangtao554@huawei.com>, <zhangqiao22@huawei.com>
Subject: [PATCH v4] sched/fair: Forfeit vruntime on yield
Date: Wed, 5 Nov 2025 11:13:52 +0200 [thread overview]
Message-ID: <20251105091355.206240-1-sieberf@amazon.com> (raw)
In-Reply-To: <20250918150528.292620-1-sieberf@amazon.com>
If a task yields, the scheduler may decide to pick it again. The task in
turn may decide to yield immediately or shortly after, leading to a tight
loop of yields.
If there's another runnable task as this point, the deadline will be
increased by the slice at each loop. This can cause the deadline to runaway
pretty quickly, and subsequent elevated run delays later on as the task
doesn't get picked again. The reason the scheduler can pick the same task
again and again despite its deadline increasing is because it may be the
only eligible task at that point.
Fix this by making the task forfeiting its remaining vruntime and pushing
the deadline one slice ahead. This implements yield behavior more
authentically.
We limit the forfeiting to eligible tasks. This is because core scheduling
prefers running ineligible tasks rather than force idling. As such, without
the condition, we can end up on a yield loop which makes the vruntime
increase rapidly, leading to anomalous run delays later down the line.
Fixes: 147f3efaa241 ("sched/fair: Implement an EEVDF-like scheduling policy")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250401123622.584018-1-sieberf@amazon.com
Link: https://lore.kernel.org/r/20250911095113.203439-1-sieberf@amazon.com
Link: https://lore.kernel.org/r/20250916140228.452231-1-sieberf@amazon.com
Signed-off-by: Fernand Sieber <sieberf@amazon.com>
Changes in v2:
- Implement vruntime forfeiting approach suggested by Peter Zijlstra
- Updated commit name
- Previous Reviewed-by tags removed due to algorithm change
Changes in v3:
- Only increase vruntime for eligible tasks to avoid runaway vruntime with
core scheduling
Changes in v4:
- Handle proxy tasks by dequeuing/enqueuing entities when modifying vruntime
to maintain RB-tree consistency
Link: https://lore.kernel.org/r/20250916140228.452231-1-sieberf@amazon.com
---
kernel/sched/fair.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 25970dbbb279..dd68605cb8af 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8993,9 +8993,10 @@ static void put_prev_task_fair(struct rq *rq, struct task_struct *prev, struct t
*/
static void yield_task_fair(struct rq *rq)
{
- struct task_struct *curr = rq->curr;
- struct cfs_rq *cfs_rq = task_cfs_rq(curr);
- struct sched_entity *se = &curr->se;
+ struct task_struct *rq_curr = rq->curr;
+ struct cfs_rq *cfs_rq = task_cfs_rq(rq_curr);
+ struct sched_entity *se = &rq_curr->se;
+ bool curr = cfs_rq->curr == se;
/*
* Are we the only task in the tree?
@@ -9017,7 +9018,23 @@ static void yield_task_fair(struct rq *rq)
*/
rq_clock_skip_update(rq);
- se->deadline += calc_delta_fair(se->slice, se);
+ /*
+ * Forfeit the remaining vruntime, only if the entity is eligible. This
+ * condition is necessary because in core scheduling we prefer to run
+ * ineligible tasks rather than force idling. If this happens we may
+ * end up in a loop where the core scheduler picks the yielding task,
+ * which yields immediately again; without the condition the vruntime
+ * ends up quickly running away.
+ */
+ if (entity_eligible(cfs_rq, se)) {
+ if (!curr)
+ __dequeue_entity(cfs_rq, se);
+ se->vruntime = se->deadline;
+ se->deadline += calc_delta_fair(se->slice, se);
+ if (!curr)
+ __enqueue_entity(cfs_rq, se);
+ update_min_vruntime(cfs_rq);
+ }
}
static bool yield_to_task_fair(struct rq *rq, struct task_struct *p)
--
2.43.0
Amazon Development Centre (South Africa) (Proprietary) Limited
29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa
Registration Number: 2004 / 034463 / 07
next prev parent reply other threads:[~2025-11-05 9:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-11 9:51 [PATCH RESEND] sched/fair: Only increment deadline once on yield Fernand Sieber
2025-09-11 11:03 ` Alexander Graf
2025-09-11 11:37 ` Peter Zijlstra
2025-09-11 13:56 ` Peter Zijlstra
2025-09-16 13:35 ` Fernand Sieber
2025-09-16 14:02 ` [PATCH v2] sched/fair: Forfeit vruntime " Fernand Sieber
2025-09-16 16:00 ` Fernand Sieber
2025-09-18 6:43 ` Peter Zijlstra
2025-09-18 10:21 ` Peter Zijlstra
2025-09-18 15:05 ` [PATCH v3] " Fernand Sieber
2025-09-24 8:25 ` kernel test robot
2025-09-26 4:56 ` kernel test robot
2025-10-16 9:33 ` [tip: sched/core] " tip-bot2 for Fernand Sieber
2025-11-05 9:13 ` Fernand Sieber [this message]
2025-09-17 19:22 ` [PATCH v2] " Fernand Sieber
2025-09-18 2:45 ` Xuewen Yan
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=20251105091355.206240-1-sieberf@amazon.com \
--to=sieberf@amazon.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=dwmw@amazon.co.uk \
--cc=graf@amazon.com \
--cc=jschoenh@amazon.de \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tanghui20@huawei.com \
--cc=vincent.guittot@linaro.org \
--cc=vineethr@linux.ibm.com \
--cc=wangtao554@huawei.com \
--cc=zhangqiao22@huawei.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