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 3/8] sched/numa: Extend accessed-bit sampling to DAX mappings
Date: Sun, 06 Dec 2026 06:38:40 -0500	[thread overview]
Message-ID: <20261206-feat-numab-series-v1-3-2af21ad24718@linux.dev> (raw)
In-Reply-To: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev>

DAX mappings point straight at persistent memory or other device memory.
Their pages are not on the LRU and are never migrated, and
vma_migratable() makes task_numa_work() skip such VMAs.

Where that memory sits still matters to the task using it. A task
working on a DAX file whose device is attached to one node gets no
placement signal from it and may run on the other package for good.

Treat DAX VMAs like hugetlb ones: sample every folio in the range rather
than only pinned ones, and account the pages found accessed as faults on
the node of the device memory, without changing the protection.

A task copying within a 3 GiB file on ext4 mounted with dax=always on
emulated pmem (memmap=4G!8G) of node 0 in 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 4, 3 rounds of 2 runs of 40 s
alternating with the kernel without this patch; time of the last copy.
With the patch every run settled on node 0, within 1.4 to 1.8 s:

                                 before          after  change
  runs settled on node 0             0/6            6/6
  runs ending off package            6/6            0/6
  slowest run (ms)                   362            189    -48%
  median run (ms)          298 (292-362)  186 (183-189)    -38%

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 include/linux/mm.h  |  3 ++-
 kernel/sched/fair.c | 11 ++++++++---
 mm/mempolicy.c      | 16 ++++++++++++----
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index d887d74d54975..df33d4519fae0 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -5030,7 +5030,8 @@ void vma_set_file(struct vm_area_struct *vma, struct file *file);
 unsigned long change_prot_numa(struct vm_area_struct *vma,
 			unsigned long start, unsigned long end);
 unsigned long numa_sample_range(struct vm_area_struct *vma, unsigned long start,
-				unsigned long end, unsigned long *node_pages);
+				unsigned long end, unsigned long *node_pages,
+				bool all);
 #endif
 
 struct vm_area_struct *find_extend_vma_locked(struct mm_struct *,
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index eaf8b77ecb6ac..520728ada00fb 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4378,8 +4378,12 @@ static void task_numa_work(struct callback_head *work)
 	}
 
 	for (; vma; vma = vma_next(&vmi)) {
-		/* Hugetlb pages are not migrated but their accesses are sampled. */
-		sample_only = node_pages && vma_is_hugetlb(vma);
+		/*
+		 * Hugetlb and DAX pages are not migrated but their accesses are
+		 * sampled.
+		 */
+		sample_only = node_pages &&
+			      (vma_is_hugetlb(vma) || vma_is_dax(vma));
 		if (!sample_only &&
 		    (!vma_migratable(vma) || !vma_policy_mof(vma) ||
 		     vma_is_hugetlb(vma) || !vma_is_mm_managed(vma))) {
@@ -4485,7 +4489,8 @@ static void task_numa_work(struct callback_head *work)
 			if (sample_only || (node_pages &&
 					    mm_flags_test(MMF_HAS_PINNED, mm)))
 				nr_sampled = numa_sample_range(vma, start, end,
-							       node_pages);
+							       node_pages,
+							       sample_only);
 			if (nr_sampled)
 				vma_set_access_pid_bit(vma);
 
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index fcdcf69f8e6c7..e69a4b38b136e 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -935,8 +935,14 @@ unsigned long change_prot_numa(struct vm_area_struct *vma,
 struct numa_sample_walk {
 	unsigned long *node_pages;
 	unsigned long nr_young;
+	bool all;
 };
 
+static bool numa_sample_folio(struct numa_sample_walk *sw, struct folio *folio)
+{
+	return folio && (sw->all || folio_maybe_dma_pinned(folio));
+}
+
 static int numa_sample_pud_entry(pud_t *pud, unsigned long addr,
 				 unsigned long next, struct mm_walk *walk)
 {
@@ -962,7 +968,7 @@ static int numa_sample_pmd_entry(pmd_t *pmd, unsigned long addr,
 
 		folio = pmd_present(pmdval) ?
 			vm_normal_folio_pmd(vma, addr, pmdval) : NULL;
-		if (folio && folio_maybe_dma_pinned(folio) &&
+		if (numa_sample_folio(sw, folio) &&
 		    pmdp_test_and_clear_young(vma, addr, pmd)) {
 			sw->node_pages[folio_nid(folio)] += HPAGE_PMD_NR;
 			sw->nr_young += HPAGE_PMD_NR;
@@ -982,7 +988,7 @@ static int numa_sample_pmd_entry(pmd_t *pmd, unsigned long addr,
 			continue;
 
 		folio = vm_normal_folio(vma, addr, ptent);
-		if (!folio || !folio_maybe_dma_pinned(folio))
+		if (!numa_sample_folio(sw, folio))
 			continue;
 
 		if (ptep_test_and_clear_young(vma, addr, pte)) {
@@ -1038,6 +1044,7 @@ static const struct mm_walk_ops numa_sample_ops = {
  * @start: Start of the range.
  * @end: End of the range.
  * @node_pages: Per-node counters, indexed by node id.
+ * @all: Sample every folio instead of pinned folios only.
  *
  * 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.
@@ -1045,9 +1052,10 @@ static const struct mm_walk_ops numa_sample_ops = {
  * Return: The number of pages found accessed.
  */
 unsigned long numa_sample_range(struct vm_area_struct *vma, unsigned long start,
-				unsigned long end, unsigned long *node_pages)
+				unsigned long end, unsigned long *node_pages,
+				bool all)
 {
-	struct numa_sample_walk sw = { .node_pages = node_pages };
+	struct numa_sample_walk sw = { .node_pages = node_pages, .all = all };
 
 	/*
 	 * Like the MGLRU page table walk, clear the accessed bits without flushing

-- 
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 ` Qiliang Yuan [this message]
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-3-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®