khugepaged: optimize collapse_pte_mapped_thp() by PTE batching
authorDev Jain <dev.jain@arm.com>
Thu, 24 Jul 2025 05:23:01 +0000 (10:53 +0530)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 2 Aug 2025 19:06:10 +0000 (12:06 -0700)
commit22d0229093b92db2fe6ca6ba946bad1f246024e8
tree66859b9b46ec267ca74e9e9e17bb1326e8bb6aba
parent4ea3594a47412f9dd20fbda0dc70b0cbec9cba43
khugepaged: optimize collapse_pte_mapped_thp() by PTE batching

Use PTE batching to batch process PTEs mapping the same large folio. An
improvement is expected due to batching mapcount manipulation on the
folios, and for arm64 which supports contig mappings, the number of
TLB flushes is also reduced.

Note that we do not need to make a change to the check
"if (folio_page(folio, i) != page)"; if i'th page of the folio is equal
to the first page of our batch, then i + 1, .... i + nr_batch_ptes - 1
pages of the folio will be equal to the corresponding pages of our
batch mapping consecutive pages.

Link: https://lkml.kernel.org/r/20250724052301.23844-4-dev.jain@arm.com
Signed-off-by: Dev Jain <dev.jain@arm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/khugepaged.c