Re: [PATCH RFC 1/4] sched/deadline: Implement reclaim/soft mode through SCHED_OTHER demotion
From: Juri Lelli
Date: Mon Feb 23 2026 - 02:12:13 EST
On 20/02/26 20:47, Peter Zijlstra wrote:
> On Thu, Feb 19, 2026 at 02:37:34PM +0100, Juri Lelli wrote:
...
> > @@ -1419,6 +1444,84 @@ s64 dl_scaled_delta_exec(struct rq *rq, struct sched_dl_entity *dl_se, s64 delta
> > return scaled_delta_exec;
> > }
> >
> > +/*
> > + * Check if a deadline task can be demoted when it exhausts its runtime.
> > + * dl-servers and boosted tasks cannot be demoted.
> > + *
> > + * Returns true if demotion should happen, false otherwise.
> > + */
> > +static inline bool dl_task_can_demote(struct sched_dl_entity *dl_se)
> > +{
> > + if (dl_server(dl_se))
> > + return false;
> > +
> > + if (is_dl_boosted(dl_se))
> > + return false;
> > +
> > + return !!(dl_se->flags & SCHED_FLAG_DL_DEMOTION);
>
> It is already implicitly cast to bool by virtue of the return value, no
> need for that explicit !!.
Indeed.
...
> > +/*
> > + * Demote a deadline task to SCHED_OTHER when it exhausts its runtime.
> > + * The task will be promoted back to SCHED_DEADLINE at replenish.
> > + */
> > +static void dl_task_demote(struct rq *rq, struct task_struct *p)
> > +{
> > + struct sched_dl_entity *dl_se = &p->dl;
> > + int queue_flags = DEQUEUE_MOVE | DEQUEUE_NOCLOCK | DEQUEUE_CLASS;
> > +
> > + lockdep_assert_rq_held(rq);
> > +
> > + if (dl_se->dl_demotion_state != DL_NOT_DEMOTED || !dl_task_can_demote(dl_se))
> > + return;
> > +
> > + dl_se->dl_demotion_state = DL_DEMOTING;
> > +
> > + scoped_guard (sched_change, p, queue_flags) {
> > + /*
> > + * The task's static_prio is already set from the sched_nice
> > + * value in sched_attr.
> > + */
> > + p->policy = SCHED_NORMAL;
> > + p->sched_class = &fair_sched_class;
> > + p->prio = p->static_prio;
> > + p->normal_prio = p->static_prio;
> > + }
> > +
> > + dl_se->dl_demotion_state = DL_DEMOTED;
> > +
> > + __balance_callbacks(rq, NULL);
> > + resched_curr(rq);
>
> Doesn't sched_change already force resched on class degradation?
It does. Will remove.
> Anyway, I love how simple this has become ;-)
Yes! Quite handy. :)
...
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index c16b5fd71b2d5..59e5459a75492 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -9415,6 +9415,14 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
> > if (p->sched_task_hot)
> > p->sched_task_hot = 0;
> >
> > + /*
> > + * Demoted DEADLINE tasks cannot migrate. Their bandwidth reservation
> > + * is tied to the demotion CPU and will be released when the task is
> > + * promoted back to DEADLINE or explicitly switched to another policy.
> > + */
> > + if (!dl_task_can_migrate(p))
> > + return 0;
>
> I suppose this works, the alternative is doing migrate_disable() in
> demote and migrate_enable() in promote. Not quite sure which is the
> least horrible in this case :-)
Yeah, I was undecided between the two. Can switch to migrate_disable().
I actually spent some time trying to figure out how to actually allow
migration while demoted w/o breaking things, but the attempts so far
ended up with not really pretty locking and retries. So, I decided to
leave this 'for later' and check first for interest on the feature.
Thanks for taking a look!
Juri