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.