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 2/3] sched/numa: Don't migrate memory on stale placement state
Date: Tue, 24 Nov 2026 07:59:08 +0100 [thread overview]
Message-ID: <20261124070011.2498455-3-arighi@nvidia.com> (raw)
In-Reply-To: <20261124070011.2498455-1-arighi@nvidia.com>
When NUMA balancing is disabled or NUMA_BALANCING_NORMAL is cleared at
runtime, the memory side of NUMA balancing doesn't stop right away:
- PTEs and PMDs armed for hinting faults before the change can fault
much later, and should_numa_migrate_memory() then migrates the folio
based on the last cpupid, the numa_group statistics and
p->numa_preferred_nid, as if NUMA_BALANCING_NORMAL was still set.
- A task_numa_work() queued before NUMA balancing is disabled still
runs a full scan pass, arming the folios on the slower memory tiers
for hinting faults.
In should_numa_migrate_memory(), keep the promotion of folios from the
slower tiers, which only depends on the memory tiering mode and the
fault latency, and only migrate the other folios with
NUMA_BALANCING_NORMAL set, so that a leftover hinting fault just
restores the mapping. This covers a disabled NUMA balancing as well,
since the mode is 0 then.
Skip the scan in task_numa_work() when sched_numa_balancing is disabled,
after re-arming the work, so it can be queued again when NUMA balancing
is re-enabled. The memory tiering mode alone still needs the scan to
promote folios, so it is not affected.
Signed-off-by: Andrea Righi <arighi@nvidia.com>
---
kernel/sched/fair.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 46d3c927b8b58..5f420141c3026 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2910,6 +2910,15 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
return !numa_promotion_rate_limit(pgdat, rate_limit, nr);
}
+ /*
+ * Past this point the folio is migrated based on the task placement
+ * state, which only NUMA_BALANCING_NORMAL does. If it was cleared,
+ * or NUMA balancing disabled, since this hinting fault was armed, just
+ * restore the mapping.
+ */
+ if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL))
+ return false;
+
this_cpupid = cpu_pid_to_cpupid(dst_cpu, current->pid);
last_cpupid = folio_xchg_last_cpupid(folio, this_cpupid);
@@ -4313,6 +4322,13 @@ static void task_numa_work(struct callback_head *work)
if (p->flags & PF_EXITING)
return;
+ /*
+ * NUMA balancing may have been disabled after this work was queued,
+ * don't arm new hinting faults.
+ */
+ if (!static_branch_likely(&sched_numa_balancing))
+ return;
+
/*
* Memory is pinned to only one NUMA node via cpuset.mems, naturally
* no page can be migrated.
--
2.56.1
next prev parent reply other threads:[~2026-11-24 7:00 UTC|newest]
Thread overview: 4+ 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 " Andrea Righi
2026-11-24 6:59 ` [PATCH 1/3] sched/numa: Ignore stale task " Andrea Righi
2026-11-24 6:59 ` Andrea Righi [this message]
2026-11-24 6:59 ` [PATCH 3/3] sched/numa: Only pick a fair task as a swap partner Andrea Righi
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-3-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 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®