From: Andrea Righi <arighi@nvidia.com>
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Tejun Heo <tj@kernel.org>, Vladimir Vdovin <deliran@verdict.gg>,
Gregory Price <gourry@gourry.net>,
David Dai <david.dai@linux.dev>,
Balbir Singh <balbirs@nvidia.com>,
Lee Trager <ltrager@nvidia.com>,
linux-mm@kvack.org, sched-ext@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] sched/numa: Only pick a fair task as a swap partner
Date: Tue, 24 Nov 2026 07:59:09 +0100 [thread overview]
Message-ID: <20261124070011.2498455-4-arighi@nvidia.com> (raw)
In-Reply-To: <20261124070011.2498455-1-arighi@nvidia.com>
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@infradead.org>
Reported-by: Vladimir Vdovin <deliran@verdict.gg>
Link: https://lore.kernel.org/r/20261002124559.10367-1-deliran@verdict.gg
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
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
next prev parent reply other threads:[~2026-11-24 7:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 6:59 [PATCH 0/3] sched/numa: Don't act on stale NUMA placement state Andrea Righi
2026-11-24 6:59 ` [PATCH 1/3] sched/numa: Ignore stale task " Andrea Righi
2026-11-24 6:59 ` [PATCH 2/3] sched/numa: Don't migrate memory on stale " Andrea Righi
2026-11-24 6:59 ` Andrea Righi [this message]
2026-11-25 3:10 ` [PATCH 3/3] sched/numa: Only pick a fair task as a swap partner Balbir Singh
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=20261124070011.2498455-4-arighi@nvidia.com \
--to=arighi@nvidia.com \
--cc=balbirs@nvidia.com \
--cc=bsegall@google.com \
--cc=david.dai@linux.dev \
--cc=deliran@verdict.gg \
--cc=dietmar.eggemann@arm.com \
--cc=gourry@gourry.net \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ltrager@nvidia.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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.