Skip to content

Android support for devices with 16k pages

Marek Habersack edited this page Aug 23, 2024 · 17 revisions

DotNet issue tracking this: https://github.com/dotnet/runtime/issues/103360

.NET Android PR: https://github.com/dotnet/android/pull/9020

Google blog announcing the feature: https://android-developers.googleblog.com/2024/08/adding-16-kb-page-size-to-android.html

At this point, bot the runtime and .NET for Android fully support the 16k alignment.

Please add all the relevant information here, in addition to the issue above. Having it here makes it easier to read than to read through the discussion in the GH issue.

Summary

Android is moving towards supporting devices with 16k memory page size, for the x64 and arm64 architectures. This affects all the native components of the application. In our case it means the MonoVM runtime, the BCL support libraries and .NET for Android native runtime and libraries.

Google plan to make support for 16k devices a requirement for Google Play application submissions next year.

A lot of work needs to be done.

Google have an article with more technical details.

How it affects our ecosystem

  • All the native 64-bit libraries must be rebuilt with flags enabling 16k alignment of data and code. This has to be done in addition to producing said libraries aligned to 4k. We need to keep the 4k-aligned libraries in order to support developers with older devices and emulators (especially x86_64 ones which don't natively support the 16k page size), as well as those developers who don't deploy their applications to Google Play Store (e.g. manufacturers of IoT devices or other embedded solutions running Android)
  • Code review of native (and maybe some managed?) code needs to be done in order to make sure we don't assume 4k page size anywhere. This includes MonoVM runtime/JIT/interpreter code.
  • APK/AAB archives we build must be aligned to 16k, instead of the current 4k
  • We need to start using Cuttlefish virtual Android devices on our CI
    • It requires a Linux VM with KVM enabled
    • It can run on Docker. This should enable using Cuttlefish on macOS and Windows VMs
  • It looks like Google provides VanillaIceCream emulators that support 16K files now.
    • image
  • We should probably switch to the ⬆️ system image on our CI once it's released.

Required changes

  • Visual Studio must create/update emulators it manages to use 16k system images (Cuttlefish via WSL?)
  • Android SDK build-tools v35.0.0-rc4 or newer are required. They contain an update zipalign utility which adds the -P parameter, indicating target page size of the APK being aligned:
-P <pagesize_kb>: Align uncompressed .so files to the specified
                    page size. Valid values for <pagesize_kb> are 4, 16
                    and 64. '-P' cannot be used in combination with '-p'.

Various notes

Detecting device's page size

The ro.product.cpu.pagesize.max system property can be used to learn what's the device's maximum supported page size:

$ adb shell getprop ro.product.cpu.pagesize.max
16384

Another way to get the system page size is with the following command:

$ adb shell getconf PAGE_SIZE
4096

They both will return 4096 for the 4k devices and 16384 for the 16k ones (including the "traditional", not Cuttlefish, emulator if the correct system image is installed)

Related resources

Clone this wiki locally