Re: [RANT][PATCH] sched_ext: Fix stale fair load weight after renice under SCX

From: Tejun Heo

Date: Fri Dec 04 2026 - 10:44:28 EST


On Fri, Dec 04, 2026 at 04:40:23PM +0100, Andrea Righi wrote:
> Hi Steven,
>
> On Fri, Dec 04, 2026 at 09:35:07AM -0500, Steven Rostedt wrote:
> > From: Steven Rostedt (LLM) <rostedt@xxxxxxxxxxx>
> >
> > While working on my scheduler governors using Claude, it discovered a bug
> > with the sched_ext reweight_task_scx() function. It wrote up the change
> > log and created a patch. The change log is below which is mostly from
> > Claude, but I did tweak it a little.
> >
> > set_load_weight() hands a changed weight to the class's ->reweight_task
> > and only writes p->se.load itself when the class has no such hook:
> >
> > if (update_load && p->sched_class->reweight_task)
> > p->sched_class->reweight_task(task_rq(p), p, &lw);
> > else
> > p->se.load = lw;
> >
> > reweight_task_fair() updates se.load as part of reweighting, but
> > reweight_task_scx() only updates p->scx.weight. So a task whose nice
> > value changes while it is in the ext class keeps the fair load weight it
> > had before, and nothing refreshes it when the task goes back to fair:
> > neither switched_from_scx() nor scx_disable_task() does, and fair never
> > recomputes a task's weight when it switches in. Forks copy the stale
> > se.load too.
>
> We already discussed this with Zicheng and Peter [1]. The approach we
> settled on was to rebuild the load weight in switching_to_fair(), so
> fair prepares its own state before enqueue, rather than having sched_ext
> maintain fair's inactive state.

Oh, I missed that. Lemme back out the patch.

Thanks.

--
tejun