[RFC PATCH 0/4] mm/vmalloc: Reduce memory usage and speed up huge vmalloc
Wen Jiang
jiangwenxiaomi at gmail.com
Wed Dec 2 18:36:05 PST 2026
On Wed, 2 Dec 2026 at 20:10, Dev Jain <dev.jain at arm.com> wrote:
>
>
>
> On 02/12/26 2:42 pm, Wen Jiang wrote:
> > From: Wen Jiang <jiangwen6 at xiaomi.com>
> >
> > Huge vmalloc (VM_ALLOW_HUGE_VMAP, used by kvmalloc() and vmalloc_huge())
> > has two problems:
> >
> > 1. The size is rounded up to the mapping size. On arm64 a 2.1MB
> > kvmalloc() backs 4MB, and an 8.1MB one backs 10MB. Besides the wasted
> > memory, every extra page has to be zeroed on allocation (with
> > init_on_alloc or __GFP_ZERO) and freed again by vfree(), so
> > allocation and vfree() are also slower.
> >
> > 2. If a huge page allocation fails halfway, e.g. the first 2MB block
> > succeeds but the second does not, everything obtained so far is
> > freed and the whole area is allocated again with base pages. The
> > time spent on the first block is wasted, and smaller block sizes
> > such as arm64 CONT_PTE are never tried.
> >
> > This series allocates and maps an area level by level, e.g.
> > PMD -> CONT_PTE -> PAGE on arm64, keeping what was already obtained,
> > and stops rounding the size up, so an area can mix block sizes:
> >
> > 2.1MB area on arm64 (not to scale):
> >
> > baseline, 2MB blocks available: 4MB used, 2 TLB entries
> > +--------------------------+--------------------------+
> > | 2MB PMD | 2MB PMD, 1.9MB unused |
> > +--------------------------+--------------------------+
> >
> > baseline, 2MB blocks not available: 537 TLB entries
> > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> > | | | | | | | | | | | | | | | | | | | | | | | | | | |
> > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
> > 537 x 4KB PTE
> >
> > this series: 2.1MB used, 11 TLB entries
> > +--------------------------+------+-+-+-+-+-+-+-+-+-+
> > | 2MB PMD | 64KB | | | | | | | | | |
> > +--------------------------+------+-+-+-+-+-+-+-+-+-+
> > CONT_PTE 9 x 4KB PTE
> >
> > Patch 1 extracts the mapping into vmalloc_area_map_range(), so that
> > an area can be mapped in several runs.
> >
> > Patch 2 adds an internal VM_HAS_HUGE_VMAP flag. A mixed area has a
> > page_order of 0, so vrealloc() and is_vm_area_hugepages() use the flag
> > to tell whether the area has any block mappings.
> >
> > Patch 3 falls back level by level. Each level takes as many whole
> > blocks as fit the remainder, and since the level only goes down, every
> > run stays aligned for its shift. It builds on the vmalloc batched
> > mapping series [1].
> >
> > Patch 4 stops rounding the size up, except for VM_REQUIRE_HUGE_VMAP.
>
> Just for your note, I had tried this, but with a different motivation:
>
> https://lore.kernel.org/all/20251112110807.69958-2-dev.jain@arm.com/
>
Thanks for your pointer, I wasn't aware of it. I'll add a link to your
patch in the next version.
> Now that you are doing this, and with some vmalloc-vfree optimizations
> done in the past months, we may actually revisit "vmalloc-huge by default".
>
That would be good. When an order-9 allocation fails, this series keeps
the PMD and CONT_PTE mappings it already got, and the size is no longer
rounded up, so enabling it by default should be less risky than before.
Thanks,
Wen
More information about the linux-arm-kernel
mailing list