[PATCH v3 11/19] arm64/mm: Align vmemmap to maximal folio size

James Houghton jthoughton at google.com
Tue Nov 24 09:25:31 PST 2026


On Sun, Nov 22, 2026 at 10:22 PM Muchun Song <muchun.song at linux.dev> wrote:
> > #include <asm/boot.h>
> > @@ -92,11 +93,22 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit;
> >  * in the virtual address space.
> >  */
> > #if ARM64_MEMSTART_SHIFT < SECTION_SIZE_BITS
> > -#define ARM64_MEMSTART_ALIGN (1UL << SECTION_SIZE_BITS)
> > +#define ARM64_MEMSTART_BASE_ALIGN    (1UL << SECTION_SIZE_BITS)
> > #else
> > -#define ARM64_MEMSTART_ALIGN (1UL << ARM64_MEMSTART_SHIFT)
> > +#define ARM64_MEMSTART_BASE_ALIGN    (1UL << ARM64_MEMSTART_SHIFT)
> > #endif
> >
> > +/*
> > + * With CONFIG_VMEMMAP_OPTIMIZATION, compound_head() masks the address of a
> > + * tail page to find its head, so the head struct page of every folio must be
> > + * naturally aligned to the folio's vmemmap size. The vmemmap is offset by
> > + * memstart_addr, so memstart_addr must be aligned to the largest folio size.
> > + */
> > +#define ARM64_VMEMMAP_OPT_ALIGN                                              \
> > +     PFN_PHYS(MAX_FOLIO_VMEMMAP_ALIGN / sizeof(struct page))
> > +#define ARM64_MEMSTART_ALIGN                                         \
> > +     max_t(phys_addr_t, ARM64_MEMSTART_BASE_ALIGN, ARM64_VMEMMAP_OPT_ALIGN)
> > +
> > static void __init arch_reserve_crashkernel(void)
> > {
> >       unsigned long long crash_base, crash_size, cma_size = 0;
> > @@ -218,6 +230,8 @@ void __init arm64_memblock_init(void)
> >       /*
> >        * Select a suitable value for the base of physical memory.
> >        */
> > +     BUILD_BUG_ON(MAX_FOLIO_VMEMMAP_ALIGN &&
> > +                  !IS_ALIGNED(VMEMMAP_START, MAX_FOLIO_VMEMMAP_ALIGN));
>
> We already have a sanity check in spares_init(). Doesn't it work? If we really
> need a check here, I think we should use compound_info_has_mask() for the guard
> instead of MAX_FOLIO_VMEMMAP_ALIGN.

The check in sparse_init() is only a VM_WARN_ON_ONCE(), which only
fires if CONFIG_DEBUG_VM=y. And hitting it doesn't prevent folios from
being vmemmap-optimized.

So I think we might as well have a BUILD_BUG_ON here, in case the
vmemmap base address changes in the future for some reason, for any
config.

I've switched MAX_FOLIO_VMEMMAP_ALIGN to compound_info_has_mask() in v4, thanks!



More information about the linux-arm-kernel mailing list