[RFC PATCH 4/4] mm/vmalloc: page align huge vmalloc sizes

Wen Jiang jiangwenxiaomi at gmail.com
Wed Dec 2 01:12:12 PST 2026


From: Wen Jiang <jiangwen6 at xiaomi.com>

__get_vm_area_node() rounds the size of a huge vmalloc area up to its
mapping size, e.g. a 2.1MB kvmalloc() on arm64 reserves and backs 4MB,
wasting almost 2MB of memory. The rounding was needed because each
huge page allocation filled a whole block, so the page count had to be
a multiple of the block size.

Now that the allocation falls back level by level and each level only
asks for whole blocks that fit the remainder, the tail of an area can
be backed by smaller blocks or base pages. Round the size up to
PAGE_SIZE only. The alignment of the area is unchanged, as it is
passed separately.

Keep the rounding for VM_REQUIRE_HUGE_VMAP, which must be backed by
huge pages entirely.

Suggested-by: Barry Song <baohua at kernel.org>
Assisted-by: LLM
Signed-off-by: Wen Jiang <jiangwen6 at xiaomi.com>
---
 mm/vmalloc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 5edc6bd20969b..f5d9f61892b2a 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3313,7 +3313,10 @@ struct vm_struct *__get_vm_area_node(unsigned long size,
 	if (WARN_ON_ONCE(in_nmi() || in_hardirq() || softirq_count()))
 		return NULL;
 
-	size = ALIGN(size, 1ul << shift);
+	if (flags & VM_REQUIRE_HUGE_VMAP)
+		size = ALIGN(size, 1ul << shift);
+	else
+		size = PAGE_ALIGN(size);
 	if (unlikely(!size))
 		return NULL;
 
-- 
2.34.1




More information about the linux-arm-kernel mailing list