Android App虚拟内存空间布局问题

问题描述 投票:0回答:2

我有一个 64 位应用程序在 Docker 容器中的 Android 8.1 上运行,系统信息:

system: Linux 5.4.40-gd8a93235f #2 SMP PREEMPT Tue Sep 8 08:26:34 CST 2020 aarch64 GNU/Linux
cpu: arm64

当应用程序启动时,虚拟内存空间布局如下所示:

12c00000-12dc0000 rw-p 00000000 00:01 1196722750                         /dev/ashmem/dalvik-main space (region space) (deleted)
12dc0000-12f80000 ---p 001c0000 00:01 1196722750                         /dev/ashmem/dalvik-main space (region space) (deleted)
12f80000-12fc0000 rw-p 00380000 00:01 1196722750                         /dev/ashmem/dalvik-main space (region space) (deleted)
12fc0000-13100000 ---p 003c0000 00:01 1196722750                         /dev/ashmem/dalvik-main space (region space) (deleted)
13100000-13140000 rw-p 00500000 00:01 1196722750                         /dev/ashmem/dalvik-main space (region space) (deleted)
13140000-131c0000 ---p 00540000 00:01 1196722750                         /dev/ashmem/dalvik-main space (region space) (deleted)
131c0000-52c00000 rw-p 005c0000 00:01 1196722750                         /dev/ashmem/dalvik-main space (region space) (deleted)
70000000-70239000 rw-p 00000000 08:07 49207963                           /system/framework/arm64/boot.art
70239000-702fe000 rw-p 00000000 08:07 49207964                           /system/framework/arm64/boot-core-libart.art
702fe000-70348000 rw-p 00000000 08:07 49207965                           /system/framework/arm64/boot-conscrypt.art
70348000-70374000 rw-p 00000000 08:07 49207966                           /system/framework/arm64/boot-okhttp.art
70374000-703a5000 rw-p 00000000 08:07 49207967                           /system/framework/arm64/boot-bouncycastle.art
703a5000-703b5000 rw-p 00000000 08:07 49207968                           /system/framework/arm64/boot-apache-xml.art
703b5000-703ba000 rw-p 00000000 08:07 49207969                           /system/framework/arm64/boot-legacy-test.art
703ba000-703e5000 rw-p 00000000 08:07 49207970                           /system/framework/arm64/boot-ext.art
703e5000-709d9000 rw-p 00000000 08:07 49207971                           /system/framework/arm64/boot-framework.art
709d9000-70a1b000 rw-p 00000000 08:07 49207976                           /system/framework/arm64/boot-telephony-common.art
70a1b000-70a26000 rw-p 00000000 08:07 49207977                           /system/framework/arm64/boot-voip-common.art
70a26000-70a30000 rw-p 00000000 08:07 49207980                           /system/framework/arm64/boot-ims-common.art
70a30000-70a56000 rw-p 00000000 08:07 49207981                           /system/framework/arm64/boot-org.apache.http.legacy.boot.art
70a56000-70a58000 rw-p 00000000 08:07 49207982                           /system/framework/arm64/boot-android.hidl.base-V1.0-java.art
70a58000-70a5b000 rw-p 00000000 08:07 49207983                           /system/framework/arm64/boot-android.hidl.manager-V1.0-java.art
70a5b000-70c35000 r--p 00000000 08:07 24249386                           /system/framework/arm64/boot.oat
70c35000-7126f000 r-xp 001da000 08:07 24249386                           /system/framework/arm64/boot.oat
7126f000-71271000 rw-p 00000000 00:00 0 
71271000-71272000 r--p 00814000 08:07 24249386                           /system/framework/arm64/boot.oat
71272000-71273000 rw-p 00815000 08:07 24249386                           /system/framework/arm64/boot.oat
71273000-71348000 r--p 00000000 08:07 24249359                           /system/framework/arm64/boot-core-libart.oat
71348000-715c5000 r-xp 000d5000 08:07 24249359                           /system/framework/arm64/boot-core-libart.oat
715c5000-715c7000 rw-p 00000000 00:00 0 
715c7000-715c8000 r--p 00352000 08:07 24249359                           /system/framework/arm64/boot-core-libart.oat
715c8000-715c9000 rw-p 00353000 08:07 24249359                           /system/framework/arm64/boot-core-libart.oat
715c9000-715e7000 r--p 00000000 08:07 24249356                           /system/framework/arm64/boot-conscrypt.oat
715e7000-7163d000 r-xp 0001e000 08:07 24249356                           /system/framework/arm64/boot-conscrypt.oat
7163d000-7163e000 rw-p 00000000 00:00 0 
7163e000-7163f000 r--p 00074000 08:07 24249356                           /system/framework/arm64/boot-conscrypt.oat
7163f000-71640000 rw-p 00075000 08:07 24249356                           /system/framework/arm64/boot-conscrypt.oat
71640000-71666000 r--p 00000000 08:07 24249374                           /system/framework/arm64/boot-okhttp.oat
71666000-716d5000 r-xp 00026000 08:07 24249374                           /system/framework/arm64/boot-okhttp.oat
716d5000-716d6000 rw-p 00000000 00:00 0 
716d6000-716d7000 r--p 00095000 08:07 24249374                           /system/framework/arm64/boot-okhttp.oat
716d7000-716d8000 rw-p 00096000 08:07 24249374                           /system/framework/arm64/boot-okhttp.oat
716d8000-716f5000 r--p 00000000 08:07 24249353                           /system/framework/arm64/boot-bouncycastle.oat
716f5000-7174c000 r-xp 0001d000 08:07 24249353                           /system/framework/arm64/boot-bouncycastle.oat
7174c000-7174d000 rw-p 00000000 00:00 0 
7174d000-7174e000 r--p 00074000 08:07 24249353                           /system/framework/arm64/boot-bouncycastle.oat
7174e000-7174f000 rw-p 00075000 08:07 24249353                           /system/framework/arm64/boot-bouncycastle.oat
7174f000-71755000 r--p 00000000 08:07 24249350                           /system/framework/arm64/boot-apache-xml.oat
71755000-71756000 r-xp 00006000 08:07 24249350                           /system/framework/arm64/boot-apache-xml.oat
71756000-71757000 r--p 00007000 08:07 24249350                           /system/framework/arm64/boot-apache-xml.oat
71757000-71758000 rw-p 00008000 08:07 24249350                           /system/framework/arm64/boot-apache-xml.oat
71758000-7175b000 r--p 00000000 08:07 24249371                           /system/framework/arm64/boot-legacy-test.oat
7175b000-7175e000 r-xp 00003000 08:07 24249371                           /system/framework/arm64/boot-legacy-test.oat
7175e000-7175f000 rw-p 00000000 00:00 0 
7175f000-71760000 r--p 00006000 08:07 24249371                           /system/framework/arm64/boot-legacy-test.oat
71760000-71761000 rw-p 00007000 08:07 24249371                           /system/framework/arm64/boot-legacy-test.oat
71761000-71774000 r--p 00000000 08:07 24249362                           /system/framework/arm64/boot-ext.oat
71774000-717a2000 r-xp 00013000 08:07 24249362                           /system/framework/arm64/boot-ext.oat
717a2000-717a3000 rw-p 00000000 00:00 0 
717a3000-717a4000 r--p 00041000 08:07 24249362                           /system/framework/arm64/boot-ext.oat
717a4000-717a5000 rw-p 00042000 08:07 24249362                           /system/framework/arm64/boot-ext.oat
717a5000-71dba000 r--p 00000000 08:07 24249365                           /system/framework/arm64/boot-framework.oat
71dba000-72f3f000 r-xp 00615000 08:07 24249365                           /system/framework/arm64/boot-framework.oat
72f3f000-72f49000 rw-p 00000000 00:00 0 
72f49000-72f4a000 r--p 0179a000 08:07 24249365                           /system/framework/arm64/boot-framework.oat
72f4a000-72f4b000 rw-p 0179b000 08:07 24249365                           /system/framework/arm64/boot-framework.oat
72f4b000-73004000 r--p 00000000 08:07 24249380                           /system/framework/arm64/boot-telephony-common.oat
73004000-7322c000 r-xp 000b9000 08:07 24249380                           /system/framework/arm64/boot-telephony-common.oat
7322c000-7322f000 rw-p 00000000 00:00 0 
7322f000-73230000 r--p 002e1000 08:07 24249380                           /system/framework/arm64/boot-telephony-common.oat
73230000-73231000 rw-p 002e2000 08:07 24249380                           /system/framework/arm64/boot-telephony-common.oat
73231000-73238000 r--p 00000000 08:07 24249383                           /system/framework/arm64/boot-voip-common.oat
73238000-73245000 r-xp 00007000 08:07 24249383                           /system/framework/arm64/boot-voip-common.oat
73245000-73246000 rw-p 00000000 00:00 0 
73246000-73247000 r--p 00014000 08:07 24249383                           /system/framework/arm64/boot-voip-common.oat
73247000-73248000 rw-p 00015000 08:07 24249383                           /system/framework/arm64/boot-voip-common.oat
73248000-73250000 r--p 00000000 08:07 24249368                           /system/framework/arm64/boot-ims-common.oat
73250000-73261000 r-xp 00008000 08:07 24249368                           /system/framework/arm64/boot-ims-common.oat
73261000-73262000 rw-p 00000000 00:00 0 
73262000-73263000 r--p 00019000 08:07 24249368                           /system/framework/arm64/boot-ims-common.oat
73263000-73264000 rw-p 0001a000 08:07 24249368                           /system/framework/arm64/boot-ims-common.oat
73264000-7328b000 r--p 00000000 08:07 24249377                           /system/framework/arm64/boot-org.apache.http.legacy.boot.oat
7328b000-732fd000 r-xp 00027000 08:07 24249377                           /system/framework/arm64/boot-org.apache.http.legacy.boot.oat
732fd000-732fe000 rw-p 00000000 00:00 0 
732fe000-732ff000 r--p 00099000 08:07 24249377                           /system/framework/arm64/boot-org.apache.http.legacy.boot.oat
732ff000-73300000 rw-p 0009a000 08:07 24249377                           /system/framework/arm64/boot-org.apache.http.legacy.boot.oat
73300000-73303000 r--p 00000000 08:07 24249344                           /system/framework/arm64/boot-android.hidl.base-V1.0-java.oat
73303000-73304000 r-xp 00003000 08:07 24249344                           /system/framework/arm64/boot-android.hidl.base-V1.0-java.oat
73304000-73305000 r--p 00004000 08:07 24249344                           /system/framework/arm64/boot-android.hidl.base-V1.0-java.oat
73305000-73306000 rw-p 00005000 08:07 24249344                           /system/framework/arm64/boot-android.hidl.base-V1.0-java.oat
73306000-7330a000 r--p 00000000 08:07 24249347                           /system/framework/arm64/boot-android.hidl.manager-V1.0-java.oat
7330a000-7330e000 r-xp 00004000 08:07 24249347                           /system/framework/arm64/boot-android.hidl.manager-V1.0-java.oat
7330e000-7330f000 rw-p 00000000 00:00 0 
7330f000-73310000 r--p 00008000 08:07 24249347                           /system/framework/arm64/boot-android.hidl.manager-V1.0-java.oat
73310000-73311000 rw-p 00009000 08:07 24249347                           /system/framework/arm64/boot-android.hidl.manager-V1.0-java.oat
73311000-73391000 rw-p 00000000 00:01 1196722747                         /dev/ashmem/dalvik-zygote space (deleted)
73391000-73392000 rw-p 00000000 00:01 1196723032                         /dev/ashmem/dalvik-non moving space (deleted)
73392000-7339c000 rw-p 00001000 00:01 1196723032                         /dev/ashmem/dalvik-non moving space (deleted)
7339c000-76312000 ---p 0000b000 00:01 1196723032                         /dev/ashmem/dalvik-non moving space (deleted)
76312000-77311000 rw-p 02f81000 00:01 1196723032                         /dev/ashmem/dalvik-non moving space (deleted)
77311000-97311000 rw-p 00000000 00:01 1196722752                         /dev/ashmem/dalvik-free list large object space (deleted)
97311000-99311000 rw-p 00000000 00:01 1196778296                         /dev/ashmem/dalvik-data-code-cache (deleted)
99311000-9b311000 r-xp 00000000 00:01 1196778297                         /dev/ashmem/dalvik-jit-code-cache (deleted)
ebad6000-ebad7000 ---p 00000000 00:01 1196724876                         /dev/ashmem/dalvik-Sentinel fault page (deleted)
31e153e7f000-31e153e9f000 rw-p 00000000 00:00 0 
bbaa5c8aa000-bbaa5c8af000 r-xp 00000000 08:07 49209508                   /system/bin/app_process64
bbaa5c8af000-bbaa5c8b0000 r--p 00004000 08:07 49209508                   /system/bin/app_process64
bbaa5c8b0000-bbaa5c8b1000 rw-p 00005000 08:07 49209508                   /system/bin/app_process64

我注意到/dev/ashmem//system/bin/app_process64之间有很大的差距(ebad7000-31e153e7f000),有谁可以帮我找出原因吗?谢谢~

android linux linux-kernel virtual-memory
2个回答
0
投票

我终于说出了原因。这个问题可以分为两部分:

  1. 为什么app_process64等动态库的虚拟地址都是48位?
  2. 为什么
    /system/framework/...
    /dev/ashmem/dalvik...
    的虚拟地址是32位?

第一个问题的原因是我使用的Linux内核配置为CONFIG_ARM64_VA_BITS=48,所以进程的虚拟地址是48位。而且Linux内核对分配进程基地址有一个随机策略,当VA_BITS设置为48时,文本区域的基地址很可能默认分配在48位地址。

第二个问题的原因是Android链接器为其art(Android运行时)保留了较低的虚拟地址空间,在分配虚拟空间时,通过将mmap_hint参数传递给链接器中的mmap()。


0
投票

你知道我在哪里可以修改“在链接器中将 mmap_hint 参数传递给 mmap() ”吗?

在我们本地分布的AOSP中,Tombstone显示Android Linker的地址也被分配了48位。应用程序在这里崩溃了。我想将其更改为正确的 32 位,看看该应用程序是否工作。

© www.soinside.com 2019 - 2024. All rights reserved.