Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Optimize for 16 KB page size
Stay organized with collections
Save and categorize content based on your preferences.
For most programming tasks, the page size isn't relevant.
However, if you're allocating large amounts of memory, working on
highly-optimized components, interfacing directly with the kernel, or doing
large amounts of file manipulation, Android's transition to the 16 KB page
size could add considerations to your performance analysis. This document
highlights some ways page size changes the dynamics of performance.
Detect memory issues
When you allocate memory with mmap
, make sure that you always pass an argument
that is a multiple of page size. If you request 4096
bytes on a system with a
16 KB page size, then the kernel allocates 16 KB
, wasting 12 KB
of
space. Viewing /proc/maps
, /proc/smaps
(or using the Android tool showmap
which prints the wasted space nicely), or checking the strace
of your process
can help detect these.
Detect disk space issues
Devices launching on Android 15 and later have 16 KB aligned ELFs by
default, and many applications are 16 KB aligned as well. Regardless of the
system, many files have increased padding. To view the real size on disk, you
can use du <my file>
to see how many kilobytes a file takes. To view the
apparent size of a file, you can use du -b <my file>
, which shows you the size
in bytes. When the apparent size is larger than real size, this usually means
that the file is compressed or has sparse regions. When the apparent size is
smaller than the real size, the file likely has extra metadata or may be split
up on disk. Using these checks, you can analyze the real size of files on disk.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-29 UTC.
[null,null,["Last updated 2025-08-29 UTC."],[],[],null,["# Optimize for 16 KB page size\n\nFor most programming tasks, the page size isn't relevant.\nHowever, if you're allocating large amounts of memory, working on\nhighly-optimized components, interfacing directly with the kernel, or doing\nlarge amounts of file manipulation, Android's transition to the 16 KB page\nsize could add considerations to your performance analysis. This document\nhighlights some ways page size changes the dynamics of performance.\n\nDetect memory issues\n--------------------\n\nWhen you allocate memory with `mmap`, make sure that you always pass an argument\nthat is a multiple of page size. If you request `4096` bytes on a system with a\n16 KB page size, then the kernel allocates `16 KB`, wasting `12 KB` of\nspace. Viewing `/proc/maps`, `/proc/smaps` (or using the Android tool `showmap`\nwhich prints the wasted space nicely), or checking the `strace` of your process\ncan help detect these.\n\nDetect disk space issues\n------------------------\n\nDevices launching on Android 15 and later have 16 KB aligned ELFs by\ndefault, and many applications are 16 KB aligned as well. Regardless of the\nsystem, many files have increased padding. To view the real size on disk, you\ncan use `du \u003cmy file\u003e` to see how many kilobytes a file takes. To view the\napparent size of a file, you can use `du -b \u003cmy file\u003e`, which shows you the size\nin bytes. When the apparent size is larger than real size, this usually means\nthat the file is compressed or has sparse regions. When the apparent size is\nsmaller than the real size, the file likely has extra metadata or may be split\nup on disk. Using these checks, you can analyze the real size of files on disk."]]