[PATCH 3/3] sched/numa: Only pick a fair task as a swap partner
From: Andrea Righi
Date: Tue Nov 24 2026 - 02:01:02 EST
When NUMA balancing migrates a fair task, task_numa_compare() considers
the task currently running on the destination CPU as a swap partner and,
if it picks it, migrate_swap() moves that task to the source CPU.
The task running on the destination CPU may belong to a different
scheduling class: an RT or deadline task, or, with sched_ext in partial
mode, a task owned by a BPF scheduler. Moving such a task is wrong for
two reasons:
- its placement is driven by its own class (push/pull for RT and
deadline, the BPF scheduler for sched_ext), which fair would override;
- the swap is weighed on task_h_load(cur), but the load average of a
task outside the fair class isn't updated, so the decision is based on
whatever load the task had when it left fair.
Treat a task outside the fair class like a kthread: never swap it, but
still allow the migrating task to move to the destination CPU alone.
Fixes: fb13c7ee0ed3 ("sched/numa: Use a system-wide search to find swap/migration candidates")
Suggested-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Reported-by: Vladimir Vdovin <deliran@xxxxxxxxxx>
Link: https://lore.kernel.org/r/20261002124559.10367-1-deliran@xxxxxxxxxx
Signed-off-by: Andrea Righi <arighi@xxxxxxxxxx>
---
kernel/sched/fair.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 5f420141c3026..fa0cfd48a133f 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3223,8 +3223,14 @@ static bool task_numa_compare(struct task_numa_env *env,
rcu_read_lock();
cur = rcu_dereference_all(dst_rq->curr);
+ /*
+ * Only swap with a fair task: the placement of a task in any other
+ * class is driven by that class, and its load, which the swap is
+ * weighed on, isn't tracked by fair. Moving the task alone to the
+ * destination is still allowed.
+ */
if (cur && ((cur->flags & (PF_EXITING | PF_KTHREAD)) ||
- !cur->mm))
+ !cur->mm || cur->sched_class != &fair_sched_class))
cur = NULL;
/*
--
2.56.1