Enable 16kB page size

Android 15 (AOSP experimental) and higher have support for building Android with a 16kB page size. This option uses additional memory but improves system performance.

16kB pages is only supported on arm64 targets with 16kB kernels. However, there is also an option to simulate 16KB userspace on x86_64 for Cuttlefish.

To enable 16kB pages, set the following build options on a device:

  • PRODUCT_NO_BIONIC_PAGE_SIZE_MACRO := true removes the PAGE_SIZE define, and it makes components determine page size at runtime.
  • PRODUCT_MAX_PAGE_SIZE_SUPPORTED := 16384 which ensures platform ELF files are built with 16kB alignment. This larger-than-needed size is for future compatibility. With 16kB ELF alignment, the kernel can support 4kB/16kB page sizes.

Verify build flags

After selecting the lunch target, verify that the build flags are set up correctly in the environment:

$ source build/envsetup.sh
$ lunch target

$ get_build_var TARGET_MAX_PAGE_SIZE_SUPPORTED
16384
$ get_build_var TARGET_NO_BIONIC_PAGE_SIZE_MACRO
true

If the previous two commands return 16384 and true respectively, your build flags are set up correctly.

Build shared libraries with 16kB ELF alignment

To build shared libraries that are part of the android project, you only need to set these build flags in your target:

  • PRODUCT_NO_BIONIC_PAGE_SIZE_MACRO := true
  • PRODUCT_MAX_PAGE_SIZE_SUPPORTED := 16384

To build shared libraries that aren't part of android project, you need to pass this linker flag:

-Wl,-z,max-page-size=16384