[PATCH v3 5/7] mm/page_owner: record the NUMA node in the scan cursor
From: Zhen Ni
Date: Wed Oct 21 2026 - 07:28:55 EST
Compute the page's NUMA node in page_owner_next_eligible() while the
page is still valid, and store it in scan->nid.
The debugfs nid filter reads scan->nid instead of recomputing it, and a
BPF program iterating the cursor reads the node straight from scan->nid.
Resolve nid at scan time to avoid dereferencing a possibly-unmapped page.
Keep it in the transient scan cursor rather than struct page_owner, so
nid does not add per-page memory overhead.
Signed-off-by: Zhen Ni <zhen.ni@xxxxxxxxxxxx>
---
Changes in v3:
- Add @scan->nid to the comment describing what is filled.
Changes in v2:
- Removes the v1 get_nid() kfunc. The node is now stored in scan->nid.
v2: https://lore.kernel.org/linux-mm/20261013122125.843451-5-zhen.ni@xxxxxxxxxxxx/
v1: https://lore.kernel.org/linux-mm/20261009112308.240769-5-zhen.ni@xxxxxxxxxxxx/
---
mm/page_owner.c | 29 +++++++++++++++++------------
mm/page_owner.h | 1 +
mm/page_owner_iter.c | 4 +++-
3 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/mm/page_owner.c b/mm/page_owner.c
index ece3b69a2579..8bc15bcdc24e 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -711,9 +711,22 @@ void __dump_page_owner(const struct page *page)
page_ext_put(page_ext);
}
+/*
+ * NUMA node of @page, bypassing PF_POISONED_CHECK() in page_to_nid() to
+ * avoid VM_BUG_ON on poisoned pages; -1 for poisoned pages.
+ */
+static int page_owner_get_nid(struct page *page)
+{
+ memdesc_flags_t page_flags = READ_ONCE(page->flags);
+
+ if (page_flags.f == PAGE_POISON_PATTERN)
+ return -1;
+ return memdesc_nid(&page_flags);
+}
+
/*
* Advance @scan to the next page eligible for page_owner output.
- * On a hit, fill scan->pfn/po_snap and return true; the caller
+ * On a hit, fill scan->pfn/po_snap/nid and return true; the caller
* must advance scan->pfn past the hit before calling again to resume
* the scan.
*/
@@ -790,6 +803,7 @@ bool page_owner_next_eligible(struct page_owner_scan *scan)
if (!scan->po_snap.handle)
goto ext_put_continue;
+ scan->nid = page_owner_get_nid(page);
page_ext_put(page_ext);
put_online_mems();
return true;
@@ -833,17 +847,8 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
goto skip_continue;
if (state->nid_filter_enabled) {
- int nid;
- memdesc_flags_t page_flags = READ_ONCE(page->flags);
-
- /*
- * Bypass PF_POISONED_CHECK() in page_to_nid() to avoid
- * VM_BUG_ON when accessing poisoned pages.
- */
- if (page_flags.f == PAGE_POISON_PATTERN)
- goto skip_continue;
- nid = memdesc_nid(&page_flags);
- if (!node_isset(nid, state->nid_filter))
+ if (scan.nid < 0 ||
+ !node_isset(scan.nid, state->nid_filter))
goto skip_continue;
}
diff --git a/mm/page_owner.h b/mm/page_owner.h
index 4ab513f17fc9..934bc9f84d6f 100644
--- a/mm/page_owner.h
+++ b/mm/page_owner.h
@@ -38,6 +38,7 @@ struct page_owner_scan {
/* resume point */
unsigned long pfn;
struct page_owner po_snap;
+ int nid;
};
bool page_owner_next_eligible(struct page_owner_scan *scan);
diff --git a/mm/page_owner_iter.c b/mm/page_owner_iter.c
index 4b9741a2de53..b7e0ce1dfa80 100644
--- a/mm/page_owner_iter.c
+++ b/mm/page_owner_iter.c
@@ -12,10 +12,11 @@ struct bpf_iter__page_owner {
__bpf_md_ptr(struct bpf_iter_meta *, meta);
__bpf_md_ptr(struct page_owner *, po);
u64 pfn;
+ int nid;
};
DEFINE_BPF_ITER_FUNC(page_owner, struct bpf_iter_meta *meta,
- struct page_owner *po, u64 pfn)
+ struct page_owner *po, u64 pfn, int nid)
static void *page_owner_seq_start(struct seq_file *seq, loff_t *posp)
{
@@ -52,6 +53,7 @@ static int page_owner_prog_seq_show(struct bpf_prog *prog,
/* @po: hit-time snapshot, no RCU window needed. */
ctx.po = &scan->po_snap;
ctx.pfn = scan->pfn;
+ ctx.nid = scan->nid;
}
return bpf_iter_run_prog(prog, &ctx);
--
2.20.1