Posted by Steven Moreland – Workers Software program Engineer, Sandeep Patil – Principal Software program Engineer
A web page is the granularity at which an working system manages reminiscence. Most CPUs in the present day assist a 4 KB web page measurement and so the Android OS and functions have traditionally been constructed and optimized to run with a 4 KB web page measurement. ARM CPUs assist the bigger 16 KB web page measurement. When Android makes use of this bigger web page measurement, we observe an total efficiency enhance of 5-10% whereas utilizing ~9% further reminiscence.
With the intention 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 will likely 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} known as reminiscence administration items (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 measurement is 4 occasions bigger, there may be 4 occasions much less bookkeeping. So, the system can spend extra time ensuring your movies look nice, video games play properly, 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 measurement will not be an Software Binary Interface (ABI). In different phrases, as soon as an software is mounted to be web page measurement 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 assist operating 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 might 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 depend upon.
Lots of our different OS parts have been rewritten to keep away from assuming the web page measurement and to optimize for bigger web page measurement when accessible.
Filesystems
For performant operation, file system block measurement should match the web page measurement. EROFS and F2FS file programs have been made 16 KB suitable, as has the UFS storage layer.
On 4 KB programs, ELF executable file measurement will increase on account of 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 sure that zero pages created for extra padding for 16 KB alignment will not be written to disk. For instance, EROFS is aware of a sure vary of a file is zero crammed, and it’ll not must 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 information put in as a part of functions PackageManager reclaims this house.
Reminiscence Administration
- The Linux web page cache has been modified to not learn forward for these further padding areas, thereby saving pointless reminiscence load.
- These pages are clean padding, and packages by no means learn this. It’s the house in-between usable components of this system, purely for alignment causes.
Linux Kernel
The Linux kernel is deeply tied to a selected web page measurement, so we should select which web page measurement 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 have to be recompiled for compatibility with 16 KB web page measurement gadgets.
Since most native code inside Android functions and SDKs have been constructed with 4 KB web page measurement in thoughts, they have to be re-aligned to 16 KB so the binaries are suitable with each 4 KB and 16 KB gadgets. For many functions and SDKs, this can be 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 measurement.
Please see our developer documentation for extra info.
NOTE: If you’re an SDK or instruments developer, you must add 16 KB assist as quickly as doable in order that functions can work on 16 KB utilizing your SDK or instruments.
Creating for 16 KB gadgets
There are not any manufacturing Android gadgets accessible in the present day or anticipated for the Android 15 launch that assist a 16 KB web page measurement. With the intention 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 carried out a developer possibility that lets customers change between 16 KB and 4 KB web page measurement on the system with a purpose to take a look at their software with both of the web page sizes. This selection is on the market on Pixel 8 and Pixel 8 Professional beginning within the Android 15 QPR1 Beta, and we’re collaborating carefully 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 must be separate. With the intention to remedy this downside, we’ve added a approach to embrace an additional kernel you’ll be able to change to as a developer possibility. Incrementally compressed, with one copy for every web page measurement and takes ~12-16 MB of house 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 of change 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 how one can allow and use this.
16 KB on x86_64 desktops
Whereas 16 KB pages are an ARM-only characteristic, we acknowledge that many builders are utilizing emulators on x86_64 {hardware}. With the intention to bridge this hole for builders, we’ve added assist to emulate 16 KB web page measurement 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 perform calls comparable to mmap(…MAP_FIXED…) are verified to be 16 KB aligned.
To get began, you’ll be able to obtain and run the 16 KB pages emulator contained in the Android Studio SDK supervisor. This manner, even if you happen to don’t have entry to ARM {hardware}, you’ll be able to nonetheless guarantee your functions will work with 16 KB web page measurement.
Future
On this put up, 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 adjustments 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 reap the benefits of these choices and put together for extra performant and environment friendly Android gadgets in close to future.