Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANDROID: x86_64: Set default max-page-size to 16kB #87413

Merged
merged 5 commits into from
Apr 12, 2024

Conversation

Kalesh-Singh
Copy link
Contributor

@Kalesh-Singh Kalesh-Singh commented Apr 2, 2024

Android now supports both 4kB and 16kB page sizes. The vast majority of android apps are developed on x86_64 machines. In order to provide emulators that support larger page sizes, Android emulates the page-size in x86_64 to support testing apps for large page size support.

For this reason, update Android x86_64 ELFs default max-page-size to 16384 to support both 4kB and 16kB page-size devices.

Increase max-page-size raises concerns of increased disk space and extra VMA slab memory.

In Android, RO partitions use sparse images, so that the holes on ELFs don't allocate blocks on disk; and PackageManager ensures to punch holes in ELF-paddings on the /data partition when apps are installed.

Extra VMA slab memory is addressed by the bionic loader, which extends segment VMAs to cover the gaps between consecutive segment mappings, to avoid the extra VMAs needed for the gap PROT_NONE mappings (---p). This optimization is done in the crt_pad_segment note [1] is present in the ELF.

[1] https://cs.android.com/android/platform/superproject/main/+/189e480390ef13199d59e1fb54078e8b78ea6f79:bionic/libc/arch-common/bionic/crt_pad_segment.S

Android now supports both 4kB and 16kB page sizes. The vast majority
of android apps developed on x86_64 machines. In order to provide
emulators that support larger page sizes, Android emulates the page-size
in x86_64 to support testing apps for large page size support.

For this reason, update Android x86_64 ELFs default max-page-size to
16384 to support both 4kB and 16kB page-size devices.

It raises the concern of increased disk space and extra VMA slab memory.

In Android, RO partitions use sparse images, so that the holes on ELFs
don't allocate blocks on disk; and PackageManger ensures to punch
holes in ELF-paddings on the /data partition when an app is installed.

Extra VMA slab memory is addressed by the bionic loader, which extends
segment VMAs to cover the gaps between consecutive segment mappings, to
avoid the extra VMAs needed for the gap PROT_NONE mappings (---p). This
optimization is done in the crt_pad_segment note [1] is present in the ELF.

[1] https://cs.android.com/android/platform/superproject/main/+/189e480390ef13199d59e1fb54078e8b78ea6f79:bionic/libc/arch-common/bionic/crt_pad_segment.S

Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
@pirama-arumuga-nainar
Copy link
Collaborator

Can you add a test similar to #70251?

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Apr 11, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 11, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Kalesh Singh (Kalesh-Singh)

Changes

Android now supports both 4kB and 16kB page sizes. The vast majority of android apps are developed on x86_64 machines. In order to provide emulators that support larger page sizes, Android emulates the page-size in x86_64 to support testing apps for large page size support.

For this reason, update Android x86_64 ELFs default max-page-size to 16384 to support both 4kB and 16kB page-size devices.

Increase max-page-size raises concerns of increased disk space and extra VMA slab memory.

In Android, RO partitions use sparse images, so that the holes on ELFs don't allocate blocks on disk; and PackageManager ensures to punch holes in ELF-paddings on the /data partition when apps are installed.

Extra VMA slab memory is addressed by the bionic loader, which extends segment VMAs to cover the gaps between consecutive segment mappings, to avoid the extra VMAs needed for the gap PROT_NONE mappings (---p). This optimization is done in the crt_pad_segment note [1] is present in the ELF.

[1] https://cs.android.com/android/platform/superproject/main/+/189e480390ef13199d59e1fb54078e8b78ea6f79:bionic/libc/arch-common/bionic/crt_pad_segment.S


Full diff: https://github.com/llvm/llvm-project/pull/87413.diff

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Linux.cpp (+2-1)
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 6c2f23e57bce05..fb65881061effc 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -244,8 +244,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
       // Android ARM uses max-page-size=4096 to reduce VMA usage.
       ExtraOpts.push_back("-z");
       ExtraOpts.push_back("max-page-size=4096");
-    } else if (Triple.isAArch64()) {
+    } else if (Triple.isAArch64() || Triple.getArch() == llvm::Triple::x86_64) {
       // Android AArch64 uses max-page-size=16384 to support 4k/16k page sizes.
+      // Android emulates a 16k page size for app testing on x86_64 machines.
       ExtraOpts.push_back("-z");
       ExtraOpts.push_back("max-page-size=16384");
     }

@Kalesh-Singh
Copy link
Contributor Author

Can you add a test similar to #70251?

Added tests for x86[_64], thanks

Remove ^//$ lines and use --target= instead of -target which has been
deprecated.

Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
@pirama-arumuga-nainar pirama-arumuga-nainar merged commit 2620ccc into llvm:main Apr 12, 2024
4 checks passed
bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
Android now supports both 4kB and 16kB page sizes. The vast majority of
android apps are developed on x86_64 machines. In order to provide
emulators that support larger page sizes, Android emulates the page-size
in x86_64 to support testing apps for large page size support.

For this reason, update Android x86_64 ELFs default max-page-size to
16384 to support both 4kB and 16kB page-size devices.

Increase max-page-size raises concerns of increased disk space and extra
VMA slab memory.

In Android, RO partitions use sparse images, so that the holes on ELFs
don't allocate blocks on disk; and PackageManager ensures to punch holes
in ELF-paddings on the /data partition when apps are installed.

Extra VMA slab memory is addressed by the bionic loader, which extends
segment VMAs to cover the gaps between consecutive segment mappings, to
avoid the extra VMAs needed for the gap PROT_NONE mappings (---p). This
optimization is done in the crt_pad_segment note [1] is present in the
ELF.

[1]
https://cs.android.com/android/platform/superproject/main/+/189e480390ef13199d59e1fb54078e8b78ea6f79:bionic/libc/arch-common/bionic/crt_pad_segment.S

---------

Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
Co-authored-by: Kalesh Singh <kaleshsingh@google.com>
Kalesh-Singh pushed a commit to Kalesh-Singh/libgdx that referenced this pull request Apr 30, 2024
Starting from V, android introduces support for 16kB page sizes.
The NDK [1] and toolchain [2][3] have been updated to support the
larger page size.

Update GDX build rules for android to use a 16kB max page size.

[1] https://github.com/android/ndk/wiki/Changelog-r27#announcements
[2] llvm/llvm-project#70251
[3] llvm/llvm-project#87413

Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants