mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qiliang Yuan <qiliang.yuan@linux.dev>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Juri Lelli <juri.lelli@redhat.com>,
	 Vincent Guittot <vincent.guittot@linaro.org>,
	Mel Gorman <mgorman@suse.de>,
	 K Prateek Nayak <kprateek.nayak@amd.com>,
	 David Hildenbrand <david@kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>,
	 Valentin Schneider <vschneid@redhat.com>,
	Zi Yan <ziy@nvidia.com>,  Gregory Price <gourry@gourry.net>,
	 Ying Huang <ying.huang@linux.alibaba.com>,
	 Kefeng Wang <wangkefeng.wang@huawei.com>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	Qiliang Yuan <qiliang.yuan@linux.dev>
Subject: [PATCH 6/8] sched/numa: Keep tasks near memory that cannot follow them
Date: Sun, 06 Dec 2026 06:38:43 -0500	[thread overview]
Message-ID: <20261206-feat-numab-series-v1-6-2af21ad24718@linux.dev> (raw)
In-Reply-To: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev>

When task_numa_migrate() finds no room on the preferred node of a task,
it tries the other nodes in turn and may pick one on another package.
For a task whose memory follows it that only delays the convergence.

Memory that cannot migrate stays behind, though, and every access from
the other package then crosses the link between the packages.

Skip candidate nodes outside the lowest NUMA domain around the preferred
node for tasks whose memory was found to be stuck, and do not swap such
a task out of that domain to make room for another one.
task_numa_migrate() already takes its imbalance settings from that
domain, sd_numa; with the distances firmware reports for multi-die
packages it spans the package of the memory. Nodes inside it are still
used to spread such tasks, so they do not all crowd onto the node of
their memory.

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 kernel/sched/fair.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ea483c8dabcf9..7fc5845324f4f 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3197,6 +3197,26 @@ static bool load_too_imbalanced(long src_load, long dst_load,
  * into account that it might be best if task running on the dst_cpu should
  * be exchanged with the source task
  */
+/*
+ * Return true if @nid lies inside the lowest NUMA domain around @pref_nid, the
+ * one task_numa_migrate() balances in. It covers the nodes at the first remote
+ * distance of sched_domains_numa_distance[], which is the package when the
+ * SLIT puts the nodes of a package at that distance.
+ */
+static bool numa_node_nearby(int pref_nid, int nid)
+{
+	int cpu = cpumask_first(cpumask_of_node(pref_nid));
+	struct sched_domain *sd;
+
+	if (cpu >= nr_cpu_ids)
+		return true;
+
+	guard(rcu)();
+	sd = rcu_dereference_all(per_cpu(sd_numa, cpu));
+	return !sd || cpumask_intersects(sched_domain_span(sd),
+					 cpumask_of_node(nid));
+}
+
 static bool task_numa_compare(struct task_numa_env *env,
 			      long taskimp, long groupimp, bool maymove)
 {
@@ -3239,6 +3259,11 @@ static bool task_numa_compare(struct task_numa_env *env,
 	if (!cpumask_test_cpu(env->src_cpu, cur->cpus_ptr))
 		goto unlock;
 
+	/* Nor if the swap would take it away from memory that cannot follow */
+	if (cur->numa_mem_stuck && cur->numa_preferred_nid != NUMA_NO_NODE &&
+	    !numa_node_nearby(cur->numa_preferred_nid, env->src_nid))
+		goto unlock;
+
 	/*
 	 * Skip this swap candidate if it is not moving to its preferred
 	 * node and the best task is.
@@ -3514,6 +3539,11 @@ static int task_numa_migrate(struct task_struct *p)
 			if (nid == env.src_nid || nid == p->numa_preferred_nid)
 				continue;
 
+			/* Keep a task whose memory cannot move near that memory */
+			if (p->numa_mem_stuck &&
+			    !numa_node_nearby(p->numa_preferred_nid, nid))
+				continue;
+
 			dist = node_distance(env.src_nid, env.dst_nid);
 			if (sched_numa_topology_type == NUMA_BACKPLANE &&
 						dist != env.dist) {

-- 
2.43.0


  parent reply	other threads:[~2026-12-06 11:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 11:38 [PATCH 0/8] sched/numa: Placement signal for memory that NUMA balancing cannot migrate Qiliang Yuan
2026-12-06 11:38 ` [PATCH 1/8] sched/numa: Sample the accessed bits of pinned memory Qiliang Yuan
2026-12-06 11:38 ` [PATCH 2/8] sched/numa: Cover hugetlb mappings with accessed-bit sampling Qiliang Yuan
2026-12-06 11:38 ` [PATCH 3/8] sched/numa: Extend accessed-bit sampling to DAX mappings Qiliang Yuan
2026-12-06 11:38 ` [PATCH 4/8] mm/mempolicy: consult secondary MMUs when sampling accessed bits Qiliang Yuan
2026-12-06 11:38 ` [PATCH 5/8] sched/numa: Track whether the memory of a task can follow it Qiliang Yuan
2026-12-06 11:38 ` Qiliang Yuan [this message]
2026-12-06 11:38 ` [PATCH 7/8] sched/fair: Avoid pulling tasks away from memory that cannot follow them Qiliang Yuan
2026-12-06 11:38 ` [PATCH 8/8] sched/numa: Share sampled accesses between the threads of a process Qiliang Yuan

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=20261206-feat-numab-series-v1-6-2af21ad24718@linux.dev \
    --to=qiliang.yuan@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=bsegall@google.com \
    --cc=david@kernel.org \
    --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=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.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 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®