18c2ecf20Sopenharmony_ciChinese translated version of Documentation/arm64/memory.rst 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ciIf you have any comment or update to the content, please contact the 48c2ecf20Sopenharmony_cioriginal document maintainer directly. However, if you have a problem 58c2ecf20Sopenharmony_cicommunicating in English you can also ask the Chinese maintainer for 68c2ecf20Sopenharmony_cihelp. Contact the Chinese maintainer if this translation is outdated 78c2ecf20Sopenharmony_cior if there is a problem with the translation. 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciMaintainer: Catalin Marinas <catalin.marinas@arm.com> 108c2ecf20Sopenharmony_ciChinese maintainer: Fu Wei <wefu@redhat.com> 118c2ecf20Sopenharmony_ci--------------------------------------------------------------------- 128c2ecf20Sopenharmony_ciDocumentation/arm64/memory.rst 的中文翻译 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文 158c2ecf20Sopenharmony_ci交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻 168c2ecf20Sopenharmony_ci译存在问题,请联系中文版维护者。 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci本文翻译提交时的 Git 检出点为: bc465aa9d045feb0e13b4a8f32cc33c1943f62d6 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci英文版维护者: Catalin Marinas <catalin.marinas@arm.com> 218c2ecf20Sopenharmony_ci中文版维护者: 傅炜 Fu Wei <wefu@redhat.com> 228c2ecf20Sopenharmony_ci中文版翻译者: 傅炜 Fu Wei <wefu@redhat.com> 238c2ecf20Sopenharmony_ci中文版校译者: 傅炜 Fu Wei <wefu@redhat.com> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci以下为正文 268c2ecf20Sopenharmony_ci--------------------------------------------------------------------- 278c2ecf20Sopenharmony_ci Linux 在 AArch64 中的内存布局 288c2ecf20Sopenharmony_ci =========================== 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci作者: Catalin Marinas <catalin.marinas@arm.com> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci本文档描述 AArch64 Linux 内核所使用的虚拟内存布局。此构架可以实现 338c2ecf20Sopenharmony_ci页大小为 4KB 的 4 级转换表和页大小为 64KB 的 3 级转换表。 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciAArch64 Linux 使用 3 级或 4 级转换表,其页大小配置为 4KB,对于用户和内核 368c2ecf20Sopenharmony_ci分别都有 39-bit (512GB) 或 48-bit (256TB) 的虚拟地址空间。 378c2ecf20Sopenharmony_ci对于页大小为 64KB的配置,仅使用 2 级转换表,有 42-bit (4TB) 的虚拟地址空间,但内存布局相同。 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci用户地址空间的 63:48 位为 0,而内核地址空间的相应位为 1。TTBRx 的 408c2ecf20Sopenharmony_ci选择由虚拟地址的 63 位给出。swapper_pg_dir 仅包含内核(全局)映射, 418c2ecf20Sopenharmony_ci而用户 pgd 仅包含用户(非全局)映射。swapper_pg_dir 地址被写入 428c2ecf20Sopenharmony_ciTTBR1 中,且从不写入 TTBR0。 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ciAArch64 Linux 在页大小为 4KB,并使用 3 级转换表时的内存布局: 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci起始地址 结束地址 大小 用途 488c2ecf20Sopenharmony_ci----------------------------------------------------------------------- 498c2ecf20Sopenharmony_ci0000000000000000 0000007fffffffff 512GB 用户空间 508c2ecf20Sopenharmony_ciffffff8000000000 ffffffffffffffff 512GB 内核空间 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ciAArch64 Linux 在页大小为 4KB,并使用 4 级转换表时的内存布局: 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci起始地址 结束地址 大小 用途 568c2ecf20Sopenharmony_ci----------------------------------------------------------------------- 578c2ecf20Sopenharmony_ci0000000000000000 0000ffffffffffff 256TB 用户空间 588c2ecf20Sopenharmony_ciffff000000000000 ffffffffffffffff 256TB 内核空间 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciAArch64 Linux 在页大小为 64KB,并使用 2 级转换表时的内存布局: 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci起始地址 结束地址 大小 用途 648c2ecf20Sopenharmony_ci----------------------------------------------------------------------- 658c2ecf20Sopenharmony_ci0000000000000000 000003ffffffffff 4TB 用户空间 668c2ecf20Sopenharmony_cifffffc0000000000 ffffffffffffffff 4TB 内核空间 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciAArch64 Linux 在页大小为 64KB,并使用 3 级转换表时的内存布局: 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci起始地址 结束地址 大小 用途 728c2ecf20Sopenharmony_ci----------------------------------------------------------------------- 738c2ecf20Sopenharmony_ci0000000000000000 0000ffffffffffff 256TB 用户空间 748c2ecf20Sopenharmony_ciffff000000000000 ffffffffffffffff 256TB 内核空间 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci更详细的内核虚拟内存布局,请参阅内核启动信息。 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci4KB 页大小的转换表查找: 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci+--------+--------+--------+--------+--------+--------+--------+--------+ 838c2ecf20Sopenharmony_ci|63 56|55 48|47 40|39 32|31 24|23 16|15 8|7 0| 848c2ecf20Sopenharmony_ci+--------+--------+--------+--------+--------+--------+--------+--------+ 858c2ecf20Sopenharmony_ci | | | | | | 868c2ecf20Sopenharmony_ci | | | | | v 878c2ecf20Sopenharmony_ci | | | | | [11:0] 页内偏移 888c2ecf20Sopenharmony_ci | | | | +-> [20:12] L3 索引 898c2ecf20Sopenharmony_ci | | | +-----------> [29:21] L2 索引 908c2ecf20Sopenharmony_ci | | +---------------------> [38:30] L1 索引 918c2ecf20Sopenharmony_ci | +-------------------------------> [47:39] L0 索引 928c2ecf20Sopenharmony_ci +-------------------------------------------------> [63] TTBR0/1 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci64KB 页大小的转换表查找: 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci+--------+--------+--------+--------+--------+--------+--------+--------+ 988c2ecf20Sopenharmony_ci|63 56|55 48|47 40|39 32|31 24|23 16|15 8|7 0| 998c2ecf20Sopenharmony_ci+--------+--------+--------+--------+--------+--------+--------+--------+ 1008c2ecf20Sopenharmony_ci | | | | | 1018c2ecf20Sopenharmony_ci | | | | v 1028c2ecf20Sopenharmony_ci | | | | [15:0] 页内偏移 1038c2ecf20Sopenharmony_ci | | | +----------> [28:16] L3 索引 1048c2ecf20Sopenharmony_ci | | +--------------------------> [41:29] L2 索引 1058c2ecf20Sopenharmony_ci | +-------------------------------> [47:42] L1 索引 1068c2ecf20Sopenharmony_ci +-------------------------------------------------> [63] TTBR0/1 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci当使用 KVM 时, 管理程序(hypervisor)在 EL2 中通过相对内核虚拟地址的 1108c2ecf20Sopenharmony_ci一个固定偏移来映射内核页(内核虚拟地址的高 24 位设为零): 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci起始地址 结束地址 大小 用途 1138c2ecf20Sopenharmony_ci----------------------------------------------------------------------- 1148c2ecf20Sopenharmony_ci0000004000000000 0000007fffffffff 256GB 在 HYP 中映射的内核对象 115