Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Android 11 ARM64 native heap allocator issues

Discussion in 'Android' started by Tomas1856, Jan 28, 2021.

  1. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,675
    Hi,

    In Android 11 release notes, there was a change to native heap alloactor https://developer.android.com/about/versions/11/behavior-changes-all#scudo.
    Native heap allocator was changed from jemalloc to scudo. The change affected Unity's native heap allocator, causing Unity based applications to crash on Android 11 when running on ARM 64.

    The error usually manifests itself with "Using memoryadresses from more than 16GB of memory" message in the logcat, followed by crash containing a stacktrace into UnityDefaultAllocator.
    Since UnityDefaultAllocator is/was used by all Unity versions, the problem affects all Unity versions.

    The issue was fixed, by switching UnityDefaultAllocator to DynamicHeapAllocator (an internal Unity native allocator), which works correctly with Scudo allocator:
    • 2018.4.30
    • 2019.4.15
    • 2020.1.14
    • 2020.2.0b12

    Additional notes:
    • As far as we know, there's no way to switch back to jemalloc allocator.
    • The fix won't be backported to Unity versions 2017 or lower, since the support for those versions has ended.
    • To switch back to UnityDefaultAllocator, you need to pass -systemallocator as command line argument
    • If you use adb shell dumpsys meminfo or Android Studio profiler, you'll notice that after switching to DynamicHeapAllocator "Native Heap" memory usage decreased, "Private Other" memory usage increased. That's expected.
    • Some people reported, that after switching their game to Unity version where the issue was supposedly fixed, they were still seeing "Using memoryadresses from more than 16GB of memory" in their crash logs. The underlying issue was with Unity Cloud Diagnostics:
    • When Unity Cloud Diagnostics sends a crash report, it specifies sender app's unity version, in other words the following scenario occurred:
    - Game made with Unity version 2019.4.14 crashes with "Using memoryadresses from more than 16GB of memory", the crash report is not sent immediately, but is saved on the phone
    - Game is updated to 2019.4.15
    - When game is launched, Unity Cloud Diagnostics runtime checks if there are any reports saved on the phone, founds it and sends it to the server, but instead of specifying 2019.4.14 version, it specifies 2019.4.15, so it may look like the crash was still occuring with 2019.4.15, but in reality, it was old report being sent with wrong Unity version.
    The issue was reported to Unity Cloud Diagnostics team.
    - Please check Google's Android Vitals instead, assuming you've uploaded native symbols, you shouldn't see crashes with UnityDefaultAllocator in stacktraces, since the allocator was switched to DynamicHeapAllocator.
     
  2. unwshd_elend

    unwshd_elend

    Joined:
    Mar 21, 2019
    Posts:
    18
    Thanks , can you explain how can I switch from UnityDefaultAllocator to DynamicHeapAllocator?
     
  3. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,675
    If you're using the Unity versions specified above, they already use DynamicHeapAllocator, in earlier Unity versions it's impossible to switch to Dynamic Heap Allocator.
     
    unwshd_elend likes this.
  4. unwshd_elend

    unwshd_elend

    Joined:
    Mar 21, 2019
    Posts:
    18
    my unity version is 2020.1.2f1 , and we building with target api 29 with ll2cpp and arm64

    I understand the versions you mentioned are using DynamicHeapAllocator but we are still not sure why its happening to us in this unity version , is it using default allocator?
     
  5. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    2,675
    Yes 2020.1.2f1 is using default allocator, so you would need to switch to 2020.1.14f or higher.

    Also, note: 2020.1.* is no longer supported, so no bug fixes will be done in that version. I would really recommend you to switch to 2020 LTS version, which will be supported until year 2022 + few months.
     
    unwshd_elend likes this.
unityunity