Skip to content

Commit 955dbdf

Browse files
htejunpaulmck
authored andcommitted
sched: Allow migrating kthreads into online but inactive CPUs
Per-cpu workqueues have been tripping CPU affinity sanity checks while a CPU is being offlined. A per-cpu kworker ends up running on a CPU which isn't its target CPU while the CPU is online but inactive. While the scheduler allows kthreads to wake up on an online but inactive CPU, it doesn't allow a running kthread to be migrated to such a CPU, which leads to an odd situation where setting affinity on a sleeping and running kthread leads to different results. Each mem-reclaim workqueue has one rescuer which guarantees forward progress and the rescuer needs to bind itself to the CPU which needs help in making forward progress; however, due to the above issue, while set_cpus_allowed_ptr() succeeds, the rescuer doesn't end up on the correct CPU if the CPU is in the process of going offline, tripping the sanity check and executing the work item on the wrong CPU. This patch updates __migrate_task() so that kthreads can be migrated into an inactive but online CPU. Signed-off-by: Tejun Heo <[email protected]> Reported-by: "Paul E. McKenney" <[email protected]> Reported-by: Steven Rostedt <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 4e32747 commit 955dbdf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kernel/sched/core.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,13 @@ struct migration_arg {
951951
static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf,
952952
struct task_struct *p, int dest_cpu)
953953
{
954-
if (unlikely(!cpu_active(dest_cpu)))
955-
return rq;
954+
if (p->flags & PF_KTHREAD) {
955+
if (unlikely(!cpu_online(dest_cpu)))
956+
return rq;
957+
} else {
958+
if (unlikely(!cpu_active(dest_cpu)))
959+
return rq;
960+
}
956961

957962
/* Affinity changed (again). */
958963
if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed))

0 commit comments

Comments
 (0)