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 Cc: "Huang, Ying" --- 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