[RFC PATCH 8/8] mm/vmalloc: Stop scanning for compound pages after encountering small pages in vmap

From: Barry Song (Xiaomi)

Date: Tue Apr 07 2026 - 22:52:49 EST


Users typically allocate memory in descending orders, e.g.
8 → 4 → 0. Once an order-0 page is encountered, subsequent
pages are likely to also be order-0, so we stop scanning
for compound pages at that point.

Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
---
mm/vmalloc.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 3c3b7217693a..242f4bc1379c 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3577,6 +3577,12 @@ static int vmap_contig_pages_range(unsigned long addr, unsigned long end,
map_addr = addr;
idx = i;
}
+ /*
+ * Once small pages are encountered, the remaining pages
+ * are likely small as well
+ */
+ if (shift == PAGE_SHIFT)
+ break;

addr += 1UL << shift;
i += 1U << (shift - PAGE_SHIFT);
--
2.39.3 (Apple Git-146)