mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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: Thu, 19 Nov 2026 16:53:02 +0000	[thread overview]
Message-ID: <av8WflarlESqUPM2@techsingularity.net> (raw)
In-Reply-To: <20261119150812.GT2668200@noisy.programming.kicks-ass.net>

On Thu, Nov 19, 2026 at 04:08:12PM +0100, Peter Zijlstra wrote:
> > set_cpus_allowed_common only sets cpus_ptr for SCA_MIGRATE_ENABLE|SCA_MIGRATE_DISABLE
> > and **nr_cpus_allowed is not changed** which is the assumption the
> > straight-forward patch relies on.
> > 
> > I do not recall looking too closely at migrate_disable or forgot why it's
> > like this so I kept looking to see where SCA_MIGRATE_ENABLE originated
> > (presumably Set Cpus Allowed (SCA) instead of a typo of Ska) leading to
> > af449901b84c ("sched: Add migrate_disable()") which was no help explaining
> > the why. It's there with a tonne of warnings about locking violations
> > but does not explicitly state why. Best is this bit
> > 
> > -       if (p->nr_cpus_allowed > 1)
> > +       if (p->nr_cpus_allowed > 1 && !is_migration_disabled(p))
> > 
> > That sortof suggests the patch relied on the behaviour to distinguish
> > between nr_cpus_allowed == 1 and nr_cpus_allowed is equivalent to 1
> > because if migrate_disabled even though p->migration_enabled existed. I was
> > under time pressure at this point so had to draw the line and stop. It's
> > not particularly clear why set_cpus_allowed_common() is like this but
> > get_push_task() still checks
> > 
> > 	if (p->nr_cpus_allowed == 1)
> > 		return NULL;
> > 
> >         if (p->migration_disabled)
> >                 return NULL;
> > 
> > It's not clear at all to me why both are needed. I expect if I kept digging
> > that I would find something clever but the obvious fix does not work,
> > or at least if it does work, it's not very obvious why it's ok and has
> > no side-effects.
> 
> Bah, and I cannot remember either. Let me have a poke, see if something
> bubbles up.

I'm assuming that the patch I sent is not completely wrong and that
the RT_PUSH_IPI check is somewhat reasonable. There might be a better
potential fix somewhere.

After a break it occured to me that this could originally have been about
locking and it's sortof plausible.  migrate_enable/migrate_disable can
only be called from the task, not just because of the API, or because
it would be an odd thing to try remotely as it's completely irrational.
__migrate_enable protects the p->migration_disabled only with a barrier and
the code itself assumes a task only updates its own p->migration_disabled
and races on memory ordering are harmless. The actual push only happens
in stopper and appears to use MDF_PUSH as a deferral mechanism (reading
a7c81556ec4d ("sched: Fix migrate_disable() vs rt/dl balancing")).
I'm guessing it was deferred because an immediate move is expensive, and
actively interfering with a potentially higher priority task is a definite
cost with uncertain benefit.

I think I could probably pick it apart given enough time but I stopped
looking at it again because -- it might be like this just because it's cheap
- migrate_disable/migrate_enable has to be cheap and deferral to stopper
is relatively cheap and while I didn't check for races, the consequences
of the race I could think of are all harmless.

The cost front is also on the other side, using cpus_ptr in set_cpus_allowed_common()
instead of a full change avoids

        cpumask_copy(&p->cpus_mask, ctx->new_mask);
        p->nr_cpus_allowed = cpumask_weight(ctx->new_mask);
        mm_update_cpus_allowed(p->mm, ctx->new_mask);

There probably still is something hiding in there, it's odd that
get_push_task checks both but I'm getting confused trying to disguish what
was intended, what is really there, and the consequences for changing it. It
is more expensive to update the cpumask properly and p->migration_disabled
is not protected other than the task only changes its own field but the
original motivation could simply be -- it's cheap.

I think it's probable the "simple" fix could replace the RT_PUSH_IPI check
but I'm less convinced that doing the work necessary for that patch to
work would be still safe or fast for migrate enable/disable.

-- 
Mel Gorman
SUSE Labs

  parent reply	other threads:[~2026-11-19 16:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 16:06 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
2026-11-19 12:06       ` Mel Gorman
2026-11-19 15:08         ` Peter Zijlstra
2026-11-19 15:17           ` Peter Zijlstra
2026-11-19 15:28             ` Peter Zijlstra
2026-11-19 16:40               ` Peter Zijlstra
2026-11-19 16:53           ` 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=av8WflarlESqUPM2@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 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®