Posted by Steven Moreland – Employees Software program Engineer, Sandeep Patil – Principal Software program Engineer
A web page is the granularity at which an working system manages reminiscence. Most CPUs at this time help a 4 KB web page dimension and so the Android OS and functions have traditionally been constructed and optimized to run with a 4 KB web page dimension. ARM CPUs help the bigger 16 KB web page dimension. When Android makes use of this bigger web page dimension, we observe an total efficiency enhance of 5-10% whereas utilizing ~9% further reminiscence.
To be able to enhance the working system efficiency total and to offer system producers an choice to make this trade-off, Android 15 can run with 4 KB or 16 KB web page sizes.
The very first 16 KB enabled Android system shall be made accessible on choose gadgets as a developer possibility. That is so you need to use the developer possibility to check and repair (if wanted) your functions to arrange for Android gadgets with 16 KB web page sizes within the close to future.
Particulars
In most CPUs, devoted {hardware} referred to as reminiscence administration models (MMUs) translate addresses from what a program is utilizing to a bodily location in reminiscence. This translation is finished on a page-size foundation. Each time a program wants extra reminiscence, the working system must become involved and fill out a “web page desk” entry, assigning that piece of reminiscence to a course of. When the web page dimension is 4 occasions bigger, there’s 4 occasions much less bookkeeping. So, the system can spend extra time ensuring your movies look nice, video games play nicely, and functions run easily, and fewer time filling out low-level working system paperwork.
In contrast to 32-bit/64-bit mode, a web page dimension shouldn’t be an Software Binary Interface (ABI). In different phrases, as soon as an software is mounted to be web page dimension agnostic, the identical software binary can run on each 4 KB and 16 KB gadgets.
In Android 15, we’ve refactored Android from the bottom as much as help working at completely different web page sizes, thus making it page-size agnostic.
Main OS Modifications
On new Android 15 based mostly gadgets:
- All OS binaries are 16 KB aligned (-Wl,-z,max-page-size=16384). third occasion functions / libraries will not be 16 KB aligned.
- All OS binaries are constructed with separate loadable segments (-Wl,-z,separate-loadable-segments) to make sure all reminiscence areas mapped right into a course of are readable, which some functions rely upon.
Lots of our different OS elements have been rewritten to keep away from assuming the web page dimension and to optimize for bigger web page dimension when accessible.
Filesystems
For performant operation, file system block dimension should match the web page dimension. EROFS and F2FS file programs have been made 16 KB suitable, as has the UFS storage layer.
On 4 KB programs, ELF executable file dimension will increase attributable to further padding added for 16 KB alignment (-Wl,-z,max-page-size=16384 possibility), however a number of optimizations assist us keep away from this value.
- Sparse read-only file programs be certain that zero pages created for added padding for 16 KB alignment are usually not written to disk. For instance, EROFS is aware of a sure vary of a file is zero stuffed, and it’ll not have to do any IO if this a part of the file is accessed.
- Learn-writeable file programs deal with zero pages on a case-by-case foundation. For instance, In Android 15, for recordsdata put in as a part of functions PackageManager reclaims this area.
Reminiscence Administration
- The Linux web page cache has been modified to not learn forward for these additional padding areas, thereby saving pointless reminiscence load.
- These pages are clean padding, and packages by no means learn this. It’s the area in-between usable components of this system, purely for alignment causes.
Linux Kernel
The Linux kernel is deeply tied to a particular web page dimension, so we should select which web page dimension to make use of when constructing the kernel, whereas the remainder of the working system stays the identical.
Android Functions
All functions with native code or dependencies must be recompiled for compatibility with 16 KB web page dimension gadgets.
Since most native code inside Android functions and SDKs have been constructed with 4 KB web page dimension in thoughts, they must be re-aligned to 16 KB so the binaries are suitable with each 4 KB and 16 KB gadgets. For many functions and SDKs, it is a 2 step course of:
- Rebuild the native code with 16 KB alignment.
- Take a look at and repair on a 16 KB system/emulator in case there are hardcode assumptions about web page dimension.
Please see our developer documentation for extra data.
NOTE: If you’re an SDK or instruments developer, it is best to add 16 KB help as quickly as attainable in order that functions can work on 16 KB utilizing your SDK or instruments.
Creating for 16 KB gadgets
There aren’t any manufacturing Android gadgets accessible at this time or anticipated for the Android 15 launch that help a 16 KB web page dimension. To be able to repair this downside, we’re taking steps to work with our companions to make a developer possibility accessible on current gadgets. This developer possibility is supposed for software improvement and testing. We’re additionally making a 16 KB emulator goal accessible for builders in Android Studio.
16 KB Developer possibility on system
In Android 15, we applied a developer possibility that lets customers swap between 16 KB and 4 KB web page dimension on the system with a purpose to take a look at their software with both of the web page sizes. This selection is out there on Pixel 8 and Pixel 8 Professional beginning within the Android 15 QPR1 Beta, and we’re collaborating intently with SoC and OEM companions to allow the choice on further gadgets quickly.
When constructed for 16 KB pages, the identical binary will work with 4 KB and 16 KB gadgets, nevertheless the Linux kernel needs to be separate. To be able to resolve this downside, we’ve added a option to embrace an additional kernel you may swap to as a developer possibility. Incrementally compressed, with one copy for every web page dimension and takes ~12-16 MB of area on disk.
Utilizing the 16 KB developer possibility would require wiping the system as soon as and an unlocked bootloader. Following flashing, builders will be capable to swap between a 4 KB and 16 KB mode by toggling the developer possibility over a reboot.
If you’re a tool producer or SoC developer, see our directions on tips on how to allow and use this.
16 KB on x86_64 desktops
Whereas 16 KB pages are an ARM-only function, we acknowledge that many builders are utilizing emulators on x86_64 {hardware}. To be able to bridge this hole for builders, we’ve added help to emulate 16 KB web page dimension for functions on x86_64 emulators. On this mode, the Kernel runs in 4 KB mode, however all addresses uncovered to functions are aligned to 16 KB, and arguments to operate calls akin to mmap(…MAP_FIXED…) are verified to be 16 KB aligned.
To get began, you may obtain and run the 16 KB pages emulator contained in the Android Studio SDK supervisor. This fashion, even in case you don’t have entry to ARM {hardware}, you may nonetheless guarantee your functions will work with 16 KB web page dimension.
Future
On this submit, we’ve mentioned the technical particulars of how we’re restructuring reminiscence in Android to get quicker, extra performant gadgets. Android 15 and AOSP work with 16 KB pages, and gadgets can now implement 16 KB pages as a improvement possibility. This required modifications from the underside to the highest of the working system, in our improvement tooling, and all through the Android ecosystem.
We’re trying ahead to software and SDK builders now to benefit from these choices and put together for extra performant and environment friendly Android gadgets in close to future.