Re: [PATCH v2 2/2] sched/fair: avoid recalculating curr status in place_entity() and requeue_delayed_entity()
From: Kayra Cizmeci
Date: Fri Sep 11 2026 - 10:14:14 EST
Hello Peter :>,
>> In enqueue_task_fair() a bool is calculated by cfs_rq->curr == se.
>> But this information gets recalculated on requeue_delayed_entity() and
>> requeue_delayed_entity() only gets called in enqueue_task_fair().
>> And on place_entity() if se == curr we call the avg_vruntime_weight()
>> twice with the same input. place_entity() only gets called in
>> enqueue_task_fair() and requeue_delayed_entity().
> I found it very hard to follow your Changelog. Could be my Friday brain.
> Sorry if I misunderstood.
It's not your Friday brain, it's my talking skills ;>.
> As I argued here:
> https://patch.msgid.link/20260813103155.GC1246887%40noisy.programming.kicks-ass.net
Oh, I remembered that patch. 1 month ago. But I didn't look into it in detail at the time.
> I suspect that case is impossible. Which AFAICT renders your whole patch
> one big no-op, no?
Well, I run some tests with WARN_ON_ONCE and that case never worked. Atleast on my tests and on my machine. I didn't done so many tests tho.
I remember doing some WARN_ON_ONCE tests on v1 too. But I don't think I did
a test about curr == se, since I thought there was no way that it does not work. Well... :P.
> That is, I think we want to do the below.
> ---
> kernel/sched/fair.c | 16 +++-------------
> 1 file changed, 3 insertions(+), 13 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 4d0b94465d19..3c7fb0684a76 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -7996,7 +7996,6 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
> struct sched_entity *se = &p->se;
> struct cfs_rq *cfs_rq = &rq->cfs;
> unsigned long weight;
> - bool curr;
>
> if (task_is_throttled(p) && enqueue_throttled_task(p))
> return;
> @@ -8025,23 +8024,14 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
> if (p->in_iowait)
> cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT);
>
> - /*
> - * XXX comment on the curr thing
> - */
> - curr = (cfs_rq->curr == se);
> - if (curr)
> - place_entity(cfs_rq, se, flags);
>
> if (se->on_rq && se->sched_delayed)
> requeue_delayed_entity(cfs_rq, se);
>
> weight = enqueue_hierarchy(p, flags);
> -
> - if (!curr) {
> - reweight_eevdf(cfs_rq, se, weight, false);
> - place_entity(cfs_rq, se, flags | ENQUEUE_QUEUED);
> - __enqueue_entity(cfs_rq, se);
> - }
> + reweight_eevdf(cfs_rq, se, weight, false);
> + place_entity(cfs_rq, se, flags | ENQUEUE_QUEUED);
> + __enqueue_entity(cfs_rq, se);
if (!rq_h_nr_queued && rq->cfs.h_nr_queued)
dl_server_start(&rq->fair_server);
So, you say remove all of this curr crap and get everything in one place since the
curr = (cfs_rq->curr == se) returns false all the time? That way we wouldn't need to
worry about the place_entity() parts neither. I'm OK. I'll send the v3 today or tommorow
latest.