From: Juri Lelli <juri.lelli@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
Qais Yousef <qyousef@google.com>,
Clark Williams <williams@redhat.com>,
Gabriele Monaco <gmonaco@redhat.com>,
Tommaso Cucinotta <tommaso.cucinotta@santannapisa.it>,
Luca Abeni <luca.abeni@santannapisa.it>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH RFC 1/4] sched/deadline: Implement reclaim/soft mode through SCHED_OTHER demotion
Date: Mon, 23 Feb 2026 08:12:01 +0100 [thread overview]
Message-ID: <aZv9wQKrayi85wRm@jlelli-thinkpadt14gen4.remote.csb> (raw)
In-Reply-To: <20260220194702.GO1282955@noisy.programming.kicks-ass.net>
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
next prev parent reply other threads:[~2026-02-23 7:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 13:37 [PATCH RFC 0/4] sched/deadline: Add soft/reclaim mode via " Juri Lelli
2026-02-19 13:37 ` [PATCH RFC 1/4] sched/deadline: Implement reclaim/soft mode through " Juri Lelli
2026-02-20 19:47 ` Peter Zijlstra
2026-02-23 7:12 ` Juri Lelli [this message]
2026-02-19 13:37 ` [PATCH RFC 2/4] sched/doc: Document SCHED_DEADLINE demotion feature Juri Lelli
2026-02-19 13:37 ` [PATCH RFC 3/4] DEBUG selftests/sched: Add tests for " Juri Lelli
2026-02-19 13:37 ` [PATCH RFC 4/4] DEBUG selftests/sched: Add simple demonstration of SCHED_DEADLINE demotion Juri Lelli
2026-04-19 20:58 ` [PATCH RFC 0/4] sched/deadline: Add soft/reclaim mode via SCHED_OTHER demotion Qais Yousef
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=aZv9wQKrayi85wRm@jlelli-thinkpadt14gen4.remote.csb \
--to=juri.lelli@redhat.com \
--cc=bsegall@google.com \
--cc=corbet@lwn.net \
--cc=dietmar.eggemann@arm.com \
--cc=gmonaco@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.abeni@santannapisa.it \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=qyousef@google.com \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=tommaso.cucinotta@santannapisa.it \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=williams@redhat.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
all inboxes | Powered by JetHome®