Re: [PATCH] sched: Fix get_push_task() vs migrate_disable()

From: Tao Zhou
Date: Thu Aug 26 2021 - 12:24:40 EST


Hi Sebastian,

On Thu, Aug 26, 2021 at 03:37:38PM +0200, Sebastian Andrzej Siewior wrote:

> push_rt_task() attempts to move the currently running task away if the
> next runnable task has migration disabled and therefore is pinned on the
> current CPU.
>
> The current task is retrieved via get_push_task() which only checks for
> nr_cpus_allowed == 1, but does not check whether the task has migration
> disabled and therefore cannot be moved either. The consequence is a
> pointless invocation of the migration thread which correctly observes
> that the task cannot be moved.
>
> Return NULL if the task has migration disabled and cannot be moved to
> another CPU.
>
> Fixes: a7c81556ec4d3 ("sched: Fix migrate_disable() vs rt/dl balancing")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
> ---
> kernel/sched/sched.h | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index e205b63d6db07..32a4945730a9b 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -2259,6 +2259,9 @@ static inline struct task_struct *get_push_task(struct rq *rq)
> if (p->nr_cpus_allowed == 1)
> return NULL;
>
> + if (p->migration_disabled)
> + return NULL;

Not much I can restore here..

Is is_migration_disabled(p) be more correct to check migration disable.
And get_push_task() being called in pull_rt_task() has checked migration
disable first and then call get_push_task(). That means this check in
get_push_task() in patch is a second repeatly check.

> rq->push_busy = true;
> return get_task_struct(p);
> }
> --
> 2.33.0
>



Thanks,
Tao