在 ARMv7 的上下文中,当 mmu 必须进行页面 table 翻译时,Linux 内核一对一映射内存的优势是什么

In context of ARMv7 what is the advantage of Linux kernel one to one mapped memory when mmu has to do a page table translation

Linux 内核虚拟地址 一对一 映射。因此,通过减去 PAGE_OFFSET 到虚拟地址,我们将得到物理地址。就是这样 virt_to_phys and phys_to_virt are implemented in memory.h.

我的问题是在 armv7 mmu 上这些一对一映射的优势是什么,当 mmu 必须在 TLB 未命中时进行页面 table 转换?

是一对一映射的唯一优势,因此S/W可以通过减去PAGE_OFFSET直接得到相应虚拟地址的物理地址或者在ARMV7 MMU页面转换上还有一些其他优势也是吗?

如果 1:1 映射内存相对于 mmu 页 table 转换没有优势,那么为什么我们需要页 table 用于 1:1 映射内存。我的意思是 mmu 可以以类似 virt_to_phys 的方式进行操作,而不是遍历整个页面 tables.

My question is what is the advantage of these one to one mapping on the armv7 mmu, when the mmu has to do the page table translation when there is a TLB miss?

您的回答部分包含在问题中。 1:1 映射是用 1MB 的部分实现的,因此 TLB 条目更小。即,一个 4k 页面需要一个 1 级和 2 级 TLB 条目,它只包含 4k 内存。 ARM 内核必须始终保持映射,因为它有中断、页面错误和其他可能随时调用的关键代码。

对于用户 space 代码,每个 4k 代码块都由一个 inode 支持,并且可能在内存压力时从内存中逐出。用户 space 代码通常只有几个热点 processes/routines,因此它们的 TLB 条目并不那么重要。 TLB 通常次于 L1/L2 缓存。

此外,设备驱动程序通常需要知道 物理 地址,因为它们在 CPU 之外并且不知道虚拟地址。减法 PAGE_OFFSET 的简单性使得代码高效。

Is the only advantage of one to one mapping so that S/W can directly gets the physical address of respective virtual address by just subtracting PAGE_OFFSET or there is some other advantage on ARMV7 MMU page translation too?

1:1 映射允许一次映射更大的范围。典型的 SDRAM/core 内存以 1MB 为增量。它也非常有效。还有其他可能性,但这些可能是这个选择的胜利。

Is the only advantage of one to one mapping so that S/W can directly gets the physical address of respective virtual address by just subtracting PAGE_OFFSET or there is some other advantage on ARMV7 MMU page translation too?

MMU 必须打开才能使用数据缓存和用户 space 进程之间的内存保护;彼此以及user/kernel分离。单独检查内核对 1:1 映射的使用并不是全部。内核的其他部分需要 MMU。如果没有 MMU,1:1 映射就是标识。 IE。 PAGE_OFFSET==0。具有固定偏移量的唯一原因是允许将任何物理地址的内存映射到公共虚拟地址。并非所有平台都具有相同的 PAGE_OFFSET 值。

virt_to_phys关系的另一个好处;内核被编写为在固定的虚拟地址执行。这意味着内核代码不需要是 PC 相关的,但可以 运行 在具有不同核心内存物理地址的平台上。注意 arm/boot 汇编代码是 PC 相关的,因为引导加载程序将在 MMU 关闭的情况下进行控制。此 arm/boot 代码设置初始映射。

另请参阅:Find the physical address of the vector tablevirt_to_phys 映射的一个例外。
Kernel data swappable?
How does the kernel manage less than 1gb?
Some details on ARM Linux boot?
Page table in linux kernel - 早期引导和 MMU。