Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/migrate: snapshot the source nid before the misplaced migration
@ 2026-10-23  2:32 Yafang Shao
  2026-10-23  3:28 ` Matthew Wilcox
  0 siblings, 1 reply; 6+ messages in thread
From: Yafang Shao @ 2026-10-23  2:32 UTC (permalink / raw)
  To: akpm, david, ziy, matthew.brost, joshua.hahnjy, byungchul, gourry,
	ying.huang, apopple
  Cc: linux-mm, Yafang Shao, Huang, Ying

A successful migration frees the source folio, so the folio_nid() read
in the promotion counter update can pick up a reallocated page's nid.
Snapshot the nid before the migration, next to the memcg snapshot the
function already takes.

Fixes: e39bb6be9f2b ("NUMA Balancing: add page promotion counter")
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
---
 mm/migrate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

---

This was found while implementing the BPF-NUMAB series. No real issues occurred.

diff --git a/mm/migrate.c b/mm/migrate.c
index 15b45832bcfa..91ba064e1bf4 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2757,6 +2757,7 @@ int migrate_misplaced_folio(struct folio *folio, int node)
 	pg_data_t *pgdat = NODE_DATA(node);
 	int nr_remaining;
 	unsigned int nr_succeeded;
+	int src_node = folio_nid(folio);
 	LIST_HEAD(migratepages);
 	struct mem_cgroup *memcg = get_mem_cgroup_from_folio(folio);
 	struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat);
@@ -2771,7 +2772,7 @@ int migrate_misplaced_folio(struct folio *folio, int node)
 		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
 		count_memcg_events(memcg, NUMA_PAGE_MIGRATE, nr_succeeded);
 		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
-		    && !node_is_toptier(folio_nid(folio))
+		    && !node_is_toptier(src_node)
 		    && node_is_toptier(node))
 			mod_lruvec_state(lruvec, PGPROMOTE_SUCCESS, nr_succeeded);
 	}
-- 
2.52.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-10-25 11:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23  2:32 [PATCH] mm/migrate: snapshot the source nid before the misplaced migration Yafang Shao
2026-10-23  3:28 ` Matthew Wilcox
2026-10-23  3:48   ` Yafang Shao
2026-10-23 14:11   ` Zi Yan
2026-10-25  3:51     ` Yafang Shao
2026-10-25 11:19     ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox