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 2/8] sched/numa: Cover hugetlb mappings with accessed-bit sampling
Date: Sun, 06 Dec 2026 06:38:39 -0500 [thread overview]
Message-ID: <20261206-feat-numab-series-v1-2-2af21ad24718@linux.dev> (raw)
In-Reply-To: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev>
task_numa_work() skips hugetlb VMAs entirely: hugetlb pages are not
migrated by NUMA balancing, so there is no point in making them fault.
Guest memory of virtual machines is commonly backed by hugetlb pages.
As with pinned memory, skipping them leaves the scheduler blind to where
that memory lives. A vCPU or any other task working on hugetlb memory
gets no preferred node from it and can stay on the far side of the
machine indefinitely.
Sample hugetlb VMAs instead: test and clear the accessed bit of each
present huge page in the scanned range and account the accessed pages as
faults on their node, without changing the protection. Such sample-only
ranges are charged to the virtual scan budget only, like ranges where no
PTE was updated, so they do not slow down the scanning of migratable
memory.
A task copying within 4 GiB of 2 MiB hugetlb pages on node 0 of an
8-node VM (2 packages of 4 nodes, 8 vCPUs and 4 LLCs per node, SLIT
10/15/25/27, guest memory on host huge pages), started on node 1, 4 or
5, 3 runs of 40 s per start node, alternating with the kernel without
this patch; time of the last copy. A copy takes 244 to 248 ms anywhere
in the package of the memory and 394 to 520 ms on the other one. With
the patch every run settled on node 0, within 3.4 to 5.6 s:
before after change
runs settled on node 0 0/9 9/9
runs ending off package 5/9 0/9
slowest run (ms) 520 248 -52%
median run (ms) 394 (245-520) 246 (244-248) -38%
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
kernel/sched/fair.c | 20 +++++++++++++-------
mm/mempolicy.c | 34 ++++++++++++++++++++++++++++++++--
2 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 14a4a15ac2747..eaf8b77ecb6ac 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4292,6 +4292,7 @@ static void task_numa_work(struct callback_head *work)
bool vma_pids_forced = false;
unsigned long *node_pages = NULL;
unsigned long nr_sampled;
+ bool sample_only;
int nid;
WARN_ON_ONCE(p != container_of(work, struct task_struct, numa_work));
@@ -4350,9 +4351,8 @@ static void task_numa_work(struct callback_head *work)
if (!pages)
return;
- if (mm_flags_test(MMF_HAS_PINNED, mm))
- node_pages = kcalloc(nr_node_ids, sizeof(*node_pages),
- GFP_KERNEL | __GFP_NOWARN);
+ node_pages = kcalloc(nr_node_ids, sizeof(*node_pages),
+ GFP_KERNEL | __GFP_NOWARN);
if (!mmap_read_trylock(mm)) {
kfree(node_pages);
@@ -4378,8 +4378,11 @@ static void task_numa_work(struct callback_head *work)
}
for (; vma; vma = vma_next(&vmi)) {
- if (!vma_migratable(vma) || !vma_policy_mof(vma) ||
- vma_is_hugetlb(vma) || !vma_is_mm_managed(vma)) {
+ /* Hugetlb pages are not migrated but their accesses are sampled. */
+ sample_only = node_pages && vma_is_hugetlb(vma);
+ if (!sample_only &&
+ (!vma_migratable(vma) || !vma_policy_mof(vma) ||
+ vma_is_hugetlb(vma) || !vma_is_mm_managed(vma))) {
trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_UNSUITABLE);
continue;
}
@@ -4475,9 +4478,12 @@ static void task_numa_work(struct callback_head *work)
start = max(start, vma->vm_start);
end = ALIGN(start + (pages << PAGE_SHIFT), HPAGE_SIZE);
end = min(end, vma->vm_end);
- nr_pte_updates = change_prot_numa(vma, start, end);
+ nr_pte_updates = 0;
nr_sampled = 0;
- if (node_pages)
+ if (!sample_only)
+ nr_pte_updates = change_prot_numa(vma, start, end);
+ if (sample_only || (node_pages &&
+ mm_flags_test(MMF_HAS_PINNED, mm)))
nr_sampled = numa_sample_range(vma, start, end,
node_pages);
if (nr_sampled)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index d11c38828ee87..fcdcf69f8e6c7 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -996,9 +996,39 @@ static int numa_sample_pmd_entry(pmd_t *pmd, unsigned long addr,
return 0;
}
+#ifdef CONFIG_HUGETLB_PAGE
+static int numa_sample_hugetlb_entry(pte_t *pte, unsigned long hmask,
+ unsigned long addr, unsigned long end,
+ struct mm_walk *walk)
+{
+ struct hstate *h = hstate_vma(walk->vma);
+ struct numa_sample_walk *sw = walk->private;
+ unsigned long psize = huge_page_size(h);
+ spinlock_t *ptl;
+ pte_t entry;
+ int nid;
+
+ ptl = huge_pte_lock(h, walk->mm, pte);
+ entry = huge_ptep_get(walk->mm, addr, pte);
+ if (pte_present(entry) && pte_young(entry)) {
+ nid = folio_nid(pfn_folio(pte_pfn(entry)));
+ entry = huge_ptep_get_and_clear(walk->mm, addr, pte, psize);
+ set_huge_pte_at(walk->mm, addr, pte, pte_mkold(entry), psize);
+ sw->node_pages[nid] += pages_per_huge_page(h);
+ sw->nr_young += pages_per_huge_page(h);
+ }
+ spin_unlock(ptl);
+
+ return 0;
+}
+#else
+#define numa_sample_hugetlb_entry NULL
+#endif
+
static const struct mm_walk_ops numa_sample_ops = {
.pud_entry = numa_sample_pud_entry,
.pmd_entry = numa_sample_pmd_entry,
+ .hugetlb_entry = numa_sample_hugetlb_entry,
.walk_lock = PGWALK_RDLOCK,
};
@@ -1009,8 +1039,8 @@ static const struct mm_walk_ops numa_sample_ops = {
* @end: End of the range.
* @node_pages: Per-node counters, indexed by node id.
*
- * Test and clear the accessed bit of pinned folios and add the pages found
- * accessed to @node_pages for the node they reside on.
+ * Test and clear the accessed bit of hugetlb pages and of pinned folios and
+ * add the pages found accessed to @node_pages for the node they reside on.
*
* Return: The number of pages found accessed.
*/
--
2.43.0
next prev 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 ` Qiliang Yuan [this message]
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 ` [PATCH 6/8] sched/numa: Keep tasks near memory that cannot follow them Qiliang Yuan
2026-12-06 11:38 ` [PATCH 7/8] sched/fair: Avoid pulling tasks away from " 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-2-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®