From: Wen Jiang <jiangwenxiaomi@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Uladzislau Rezki <urezki@gmail.com>,
linux-mm@kvack.org
Cc: Barry Song <baohua@kernel.org>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
David Hildenbrand <david@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Leo Yan <leo.yan@arm.com>,
Xueyuan Chen <xueyuan.chen21@gmail.com>,
Mike Rapoport <rppt@kernel.org>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Pratyush Yadav <pratyush@kernel.org>,
Alexander Graf <graf@amazon.com>,
kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Wen Jiang <jiangwen6@xiaomi.com>
Subject: [RFC PATCH 4/4] mm/vmalloc: page align huge vmalloc sizes
Date: Wed, 2 Dec 2026 17:12:12 +0800 [thread overview]
Message-ID: <20261202091212.363755-5-jiangwenxiaomi@gmail.com> (raw)
In-Reply-To: <20261202091212.363755-1-jiangwenxiaomi@gmail.com>
From: Wen Jiang <jiangwen6@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@kernel.org>
Assisted-by: LLM
Signed-off-by: Wen Jiang <jiangwen6@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
prev parent reply other threads:[~2026-12-02 9:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 9:12 [RFC PATCH 0/4] mm/vmalloc: Reduce memory usage and speed up huge vmalloc Wen Jiang
2026-12-02 9:12 ` [RFC PATCH 1/4] mm/vmalloc: extract vmalloc_area_map_range() Wen Jiang
2026-12-02 9:12 ` [RFC PATCH 2/4] mm/vmalloc: add VM_HAS_HUGE_VMAP Wen Jiang
2026-12-02 9:12 ` [RFC PATCH 3/4] mm/vmalloc: try smaller block sizes before base pages Wen Jiang
2026-12-02 9:12 ` Wen Jiang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202091212.363755-5-jiangwenxiaomi@gmail.com \
--to=jiangwenxiaomi@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=baohua@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=graf@amazon.com \
--cc=jiangwen6@xiaomi.com \
--cc=kexec@lists.infradead.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=urezki@gmail.com \
--cc=will@kernel.org \
--cc=xueyuan.chen21@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox