Re: [PATCH] mm/migrate: look up consecutive pages together in do_pages_stat_array()

From: Qiliang Yuan

Date: Thu Oct 01 2026 - 21:27:51 EST


On 1 Oct 2026, at 11:37, Zi Yan wrote:
> Instead of adding customized batched walk code, it might be better to use
> walk_page_range() + pmd_entry callback. See mincore_pte_range() for
> reference.

Thanks, v2 does that, with pud_entry and hugetlb_entry callbacks so the
walk doesn't split PUD or hugetlb leaves.

> BTW, DO_PAGES_STAT_CHUNK_NR is limited at 16, so the batching benefit
> comes from 16 pages instead of 512 pages in one PMD? I wonder if that
> limit could be raised and how much more benefit we will see.

Yes. With runs walked in one go, the walk setup paid every 16 pages
dominates. Per page, querying a populated 4 GiB buffer:

16 64 256 512 1024
4K pages 31.9 ns 15.0 ns 11.8 ns 11.2 ns 10.9 ns
THP 23.1 ns 6.6 ns 2.5 ns 1.8 ns 1.6 ns

v2 raises the chunk to 512 in a separate patch, which also allocates
the arrays instead of keeping 6 KiB on the stack:

https://lore.kernel.org/r/20261002-bug-mm-move-pages-stat-batch-v2-0-f73b5d20519f@xxxxxxxxx

Qiliang