From: Mel Gorman <mgorman@techsingularity.net>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Steven Rostedt <rostedt@goodmis.org>,
Seiji Nishikawa <snishika@redhat.com>,
Mian Yousaf Kaukab <ykaukab@suse.de>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] sched/rt: Do not account migrate-disabled tasks as pushable
Date: Wed, 18 Nov 2026 10:05:21 +0000 [thread overview]
Message-ID: <av1q-2D_tdi9oNEj@techsingularity.net> (raw)
In-Reply-To: <20261117152414.GG1922751@noisy.programming.kicks-ass.net>
On Tue, Nov 17, 2026 at 04:24:14PM +0100, Peter Zijlstra wrote:
> On Tue, Nov 17, 2026 at 04:20:26PM +0100, Peter Zijlstra wrote:
> > On Fri, Nov 13, 2026 at 04:06:55PM +0000, Mel Gorman wrote:
> >
> > > As above, the runqueue is still marked overloaded by enqueue_task_rt()
> > > and put_prev_task_rt() even if the task is migrate-disabled. A
> > > migrate-disabled task reaches the pushable list through enqueue_task_rt()
> > > or put_prev_task_rt() when it is preempted, or when it wakes while
> > > still migrate-disabled. Either path calls enqueue_pushable_task() to set
> > > rq->rt.overloaded and rto_mask if unset. Once set, every pull from another
> > > CPU that fires an IPI may only find migrate-disabled tasks rendering the IPI
> > > useless for a condition that was detectable when placed on the pushable list.
> > >
> > > Stop adding migrate-disabled tasks to the pushable list if RT_PUSH_IPI is
> > > enabled. This is not a heuristic as migrate-disabled tasks cannot move. Even
> > > when migration is enabled, the rq still has no pushable candidates until the
> > > task schedules. The !RT_PUSH_IPI behaviour is preserved and migrate-disabled
> > > tasks are added to the pushable list. Without IPI, the alternative path in
> > > pull_rt_task() must find runqueues with off-CPU migrate-disabled tasks. It
> > > can then push the running task away allowing the migrate-disabled task
> > > to run.
> >
> > Last time I either didn't notice, or I've gone dumb from staring at perf
> > issues all day, but I'm not entirely sure I understand how we get here.
> >
> > Suppose:
> >
> > migrate_disable();
> > ...
> > schedule()
> > migrate_disable_switch()
> > // switches p->cpus_ptr and p->nr_cpus_allowed
> > pick_next_task()
> > p = class->pick_task();
> > put_prev_set_next_task(rq, rq->donor, p);
> > return p;
> >
> > So any task that ends up in put_prev_task_rt() wlll have passed through
> > migrate_disable_switch(), which have updated nr_cpus_allowed.
> >
I did not check in this direction but that does not mean I think you're
right but I also am struggling to prove it.
An earlier version of the patch was like what you suggested (check both
conditionally in rt.c and copy to deadline.c), hen I thought "deadline had
no RTO IPI" and the copy felt like cargo culting which definitely would get
a kicking and I'd be asked "Why did you copy that" and my answer would be
"Uhhh.. cargo cult?" and then feel like a right idiot.
Without the push IPI, deadline.c needed an explanation why the same check
is necessary so looked closer at the !PUSH_IPI handling. The !IPI path
in both assumes that such tasks can be visible so "why look up?"
In rt.c
--8<--
static void pull_rt_task(struct rq *this_rq)
....
#ifdef HAVE_RT_PUSH_IPI
if (sched_feat(RT_PUSH_IPI)) {
tell_cpu_to_push(this_rq);
return;
}
#endif
(!RT_PUSH_IPI path, default in !PREEMPT_RT or sched_debug toggle)
for_each_cpu(cpu, this_rq->rd->rto_mask) {
...
/*****
****
**** This bit
****
****
/*
* Do we have an RT task that preempts
* the to-be-scheduled task?
*/
if (p && (p->prio < this_rq->rt.highest_prio.curr)) {
...
if (is_migration_disabled(p)) {
push_task = get_push_task(src_rq);
} else {
move_queued_task_locked(src_rq, this_rq, p);
resched = true;
}
...
}
}
--8<--
The !IPI path assumes that a migrate_disabled(p) can exist on the rto_mask
and it's been like that for a while. Compounding the problem that kept me
looking down was that PREEMPT_RT tree used to have a patch e18de5e2e3e9
("sched/rt: Don't try push tasks if there are none.") that tangentially
affected the bug (the PREEMPT_RT patch was visible in the distro kernel
the bug was reported against). The PREEMPT_RT patch was removed around 6.7
because "it's much better now" and while it was not stated why, I assumed
it was due to 612f769edd06 ("sched/rt: Make rt_rq->pushable_tasks updates
drive rto_mask")
I'm not saying this is right, I am saying that blocks of code in both
rt.c and deadline.c assume this condition can occur.
> > Or so my current thinking goes. You seeing this patch make a difference,
> > seems to suggest I'm missing something, but I couldn't spot it in that
> > wall of text.
>
It is definitely the case, and I've measured it, that the patch removes
spurious IPIs and it's verified on a mainline kernel. Spurious IPI in
this case is that a CPU that has no task that can migrate is considered
pushable and receives a *lot* of IPIs per second that never move a task
because there is no task that *can* move. I didn't try quantifing it much
beyond that because reducing thousands of IPIs/sec seemed like suffficient
justification to me.
> Ah, is the sched_change pattern the clue? I'm thinking that RT might hit
> that more than usual due to the PI path.
>
You give me too much credit, I started with a cargo cult copy of rt.c to
deadline.c but couldn't put an obviously correct comment or changelog
on it so a short paragraph of a changelog turned into a "wall of text"
while I talked to myself for longer than is considered healthy even by
the rubber duck.
> In that case we do indeed end up in put_prev_task() / set_next_task()
> without going through schedule(). In that case the task would be on the
> pushable list during the change, HOWEVER we should hold rq->lock (which
> implies have IRQs disabled) over the entire thing, so again, I'm not
> sure how this is then observable.
>
> > Anyway, I'm still not sure why we can't just write:
> >
> > > diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> > > index 1535046a23ff..bb640278d30e 100644
> > > --- a/kernel/sched/rt.c
> > > +++ b/kernel/sched/rt.c
> > > @@ -396,6 +396,13 @@ static inline void rt_queue_pull_task(struct rq *rq)
> > >
> > > static void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
> > > {
> > > + if (p->nr_cpus_allowed <= 1)
> > > + return;
> > > +#ifdef HAVE_RT_PUSH_IPI
> > > + if (sched_feat(RT_PUSH_IPI) && is_migration_disabled(p))
> > > + return;
> > > +#endif
> > > +
> >
> > if (p->nr_cpus_allowed <= 1 || is_migration_disabled(p))
> > return;
> >
Yeah, I had that and couldn't copy it to deadline.c because the bug is
about IPIs, IPIs of the same type don't exist in deadline.c, so the copy
is "obviously bogus" and on rt.c the same check makes a bunch of
long-lived code unreachable. That is obviously shit logic to use for
justifying a kernel change.
I have to look closer at why you think it's not reachable and Steven
thinks it's plausible. All I've got so far is that
o migrate_disable_switch checks does nothing if
"p->cpus_ptr != &p->cpus_mask"
and so do_set_cpus_allowed is not guaranteed to be called and
therefore the statement "migrate_disable_switch(), which have updated
nr_cpus_allowed" might have a counter-example.
o pick_next_pushable_task() has BUG_ON(p->nr_cpus_allowed <= 1) and this
thing certainly seems to believe that migrate_disabled tasks can reach
it
if (unlikely(is_migration_disabled(task) ||
!cpumask_test_cpu(lowest_rq->cpu, &task->cpus_mask) ||
task != pick_next_pushable_task(rq))
which means nothing at all yet, other than it's an example that is
very difficult to reconcile with your version (which matches my old
version) and state "this is ok".
> > But perhaps I'm missing something; the above seems to suggest that is a
> > theme today.
Not sure yet, all I know is that I cannot find so far a way of writing
a comment or changelog on that version that shows it's safe and doesn't
degrade rt.c, deadline.c at minimum or break it at worst.
--
Mel Gorman
SUSE Labs
next prev parent reply other threads:[~2026-11-18 10:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 16:06 [PATCH v3] sched/rt: Do not account migrate-disabled tasks as pushable Mel Gorman
2026-11-17 14:27 ` Mel Gorman
2026-11-17 15:10 ` Peter Zijlstra
2026-11-17 15:20 ` Peter Zijlstra
2026-11-17 15:24 ` Peter Zijlstra
2026-11-18 10:05 ` Mel Gorman [this message]
2026-11-17 15:25 ` Steven Rostedt
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=av1q-2D_tdi9oNEj@techsingularity.net \
--to=mgorman@techsingularity.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=snishika@redhat.com \
--cc=vincent.guittot@linaro.org \
--cc=ykaukab@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.