Skip to content

[Android] Runtime/BCL native libs need support for devices with 16k memory pages (arm64 and x64) #103360

Closed

Description

@grendello

Wiki: https://github.com/xamarin/xamarin-android/wiki/Android-support-for-devices-with-16k-pages

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 the runtime

  • All the native libraries must be rebuilt with flags enabling 16k alignment of data and code
  • 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.

Activity

  1. dotnet-policy-service commented on Jun 12, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-meta
    See info in area-owners.md if you want to be subscribed.

  2. added this to the Future milestone on Jun 12, 2024
  3. added
    runtime-monospecific to the Mono runtime
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 12, 2024
  4. steveisok commented on Jun 12, 2024

    @steveisok
    Member
  5. janvorli commented on Jun 12, 2024

    @janvorli
    Member
    • 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

    coreclr should work on variable page sizes. macOS ARM64 uses 16kB pages, we have tested Linux arm64 with 64kB pages in the past too. I am not sure about the x64 though, there might be some stuff expecting 4kB page size for this architecture.

  6. janvorli commented on Jun 12, 2024

    @janvorli
    Member

    Ah, sorry, this issue is mono specific, right?

  7. steveisok commented on Jun 13, 2024

    @steveisok
    Member

    Ah, sorry, this issue is mono specific, right?

    Yeah, but it's also important to understand how coreclr would behave.

  8. grendello commented on Jun 13, 2024

    @grendello
    ContributorAuthor

    @janvorli CoreCLR is used to build apps that run on Android too, so as @steveisok said, it's important to make sure it works too.

  9. janvorli commented on Jun 13, 2024

    @janvorli
    Member

    Ok, I am glad the details I have added above are useful then.

  10. 8 remaining items

  11. grendello commented on Jul 2, 2024

    @grendello
    ContributorAuthor

    My main concern with just shipping the 16k-aligned binaries is embedded device developers - if we don't ship 4k-aligned binaries, they would be forced to use the larger binaries (with bigger memory consumption), which on embedded devices with little memory may have a lot of importance.

  12. jkotas commented on Jul 2, 2024

    @jkotas
    Member

    How much is the increase in memory consumption?

    I understand that there is a bit higher address space consumption (the padding takes address space). This does not matter - address space consumption that we talk about here costs close to nothing.

    I do not see why this have to cause measurable increase in physical memory consumption. ELF loader and Linux kernel should map the pages where the sections overlap to same physical memory page(s).

  13. grendello commented on Jul 2, 2024

    @grendello
    ContributorAuthor

    How much is the increase in memory consumption?

    I understand that there is a bit higher address space consumption (the padding takes address space). This does not matter - address space consumption that we talk about here costs close to nothing.

    It depends on the library. However, the consumption will be real, since what is "wasted" is the space between the end of a section and the beginning of the next one. The preceding section "spills over" into its last page, so the page is actually mapped and using real memory. The difference between the used space and the page size alignment is the wasted memory. Granted, it's not that much for most devices in most cases, but for embedded devices it may be important.

    I do not see why this have to cause measurable increase in physical memory consumption. ELF loader and Linux kernel should map the pages where the sections overlap to same physical memory page(s).

    I'm not sure they will do that, because then the alignment requirement wouldn't be satisfied for the beginning of one of the sections.

    Anyway, after some discussion with @jonpryor, I think you and @steveisok are right - we don't need to ship 4k and 16k binaries right now. If anyone needs them, they will let us know and we can cross the bridge if/when that happens.

    So for NET9 release the thing that we'd need is to build the runtime with 16k alignment. I can open a PR later this week which will implement that, unless somebody beats me to it.

  14. janvorli commented on Jul 8, 2024

    @janvorli
    Member

    the page is actually mapped and using real memory.

    Unless that extra virtual memory range is accessed, it should not increase the resident set and thus it should only consume virtual address space.

  15. grendello commented on Jul 8, 2024

    @grendello
    ContributorAuthor

    PR is up #104577

  16. locked and limited conversation to collaborators on Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions