freenode
Kernel & Low-Level

RFC proposes choosing arm64 page size at boot, not build time

Eric Curtin carries Ryan Roberts's series so one kernel can serve 4K, 16K and 64K instead of three distribution builds.

Eric Curtin has posted a second RFC that would let a single arm64 kernel pick its base page size at boot, rather than baking 4K, 16K or 64K into the binary. Distributions that want more than one size currently ship several kernels. With the new option, arm64.pagesize=4k|16k|64k selects the size, and a Kconfig default covers the case where the command line does not.

The work continues a series Ryan Roberts started at Arm. Curtin, of Docker, rebased it onto v7.4-rc5, folded review comments and Roberts's work-in-progress fixes, and split the posting the way Roberts had proposed. This series is the core: compile-time bounds for the smallest and largest page size, the memory-management and kernel changes those bounds force, and the arm64 implementation. Conversions of filesystems, networking, sound, graphics, block and other drivers are meant to follow as separate series to the relevant maintainers.

The reason the change is large is that PAGE_SIZE, and the page-table geometry derived from it, stop being compile-time constants. Code that truly needs a constant, static arrays, structure layouts, build-time assertions, case labels, uses the min and max bounds instead. For a kernel built with a fixed page size those bounds collapse back to the old constants, and the generated code is meant to be unchanged. Data that must be page-aligned at link time is aligned to the largest supported page, so it stays correctly aligned whichever size is chosen later.

A few core assumptions break once the size is not known until boot. Kernel stacks on arm64 need 16K, but a virtually mapped stack must be a multiple of the page size, so a 64K page forces a 64K stack. Sizing every stack for that case would waste 48K per kernel thread on 4K or 16K pages, so stack size becomes a runtime value, with a compile-time maximum used only where a constant is unavoidable. The number of page-table levels can also change with the page size, so the decision about whether a mid-level table is folded, and therefore whether it can have its own lock, moves from compile time to boot. The vDSO is still built against the configured page shift, so the kernel has to lay out and map its data pages to match what that code expects, not the runtime page size.

Curtin also reports bugs found in an independent review of the whole series: KVM stage-2 mapping size on demotion, flattened device tree mapping state, hibernate image buffers, and the ordering of module constructors against module parameters. Constructors are used to initialise globals whose starting value depends on page size, and they now run earlier, including before a module's parameters are parsed, so parameters can still override those defaults. Enabling the option also turns undefined preprocessor uses of PAGE_SIZE into errors. A conditional written as if PAGE_SIZE were a constant would otherwise treat the runtime variable as zero and fail silently.

The Kconfig option and its documentation are added last, so every earlier patch still builds with a fixed page size. Curtin asked Roberts to say if he would rather post the series himself.