在 ARMv7 的上下文中,当 mmu 必须进行页表转换时,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

查看:25
本文介绍了在 ARMv7 的上下文中,当 mmu 必须进行页表转换时,Linux 内核一对一映射内存的优势是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux 内核虚拟地址一对一映射.因此,通过将 PAGE_OFFSET 减去虚拟地址,我们将获得物理地址.这就是 virt_to_physphys_to_virt 在memory.h.

Linux kernel virtual address are one-to-one mapped. So by subtracting a PAGE_OFFSET to virtual address we will get the physical address. That is how virt_to_phys and phys_to_virt are implemented in memory.h.

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

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?

是一对一映射的唯一优势,S/W 可以通过减去 PAGE_OFFSET 直接获取各个虚拟地址的物理地址,或者在 ARMV7 MMU 页面转换上也有其他一些优势?

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 映射内存比 mmu 页表转换没有优势,那么为什么我们需要 1:1 映射内存的页表.我的意思是 mmu 可以以类似于 virt_to_phys 的方式进行操作,而不是遍历所有页表.

If there is no advantage of 1:1 mapped memory over mmu page table translation then why we need page tables for 1:1 mapped memory. I mean mmu can do the operation in similar way of virt_to_phys instead walking all the page tables.

推荐答案

我的问题是这些一对一映射的优势是什么armv7 mmu,当mmu要做页表转换的时候是否存在 TLB 未命中?

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 内核必须始终保持映射状态,因为它有中断、页面错误和其他可能随时调用的关键代码.

Your answer is partially in the question. The 1:1 mappings are implemented with 1MB sections so the TLB entry is smaller. Ie, a 4k page needs a level 1 and level 2 TLB entry and it only encompasses 4k of memory. The ARM kernel must always remain mapped as it has interrupt, page fault and other critical code which maybe called at any time.

对于用户空间代码,每个 4k 代码块都由一个 inode 支持,并且可能会在内存压力期间从内存中驱逐.用户空间代码通常只有几个热进程/例程,因此它们的 TLB 条目并不重要.TLB 通常次要于 L1/L2 缓存.

For user space code, each 4k chunk of code is backed by an inode and maybe evicted from memory during times of memory pressure. The user space code is usually only a few hot processes/routines, so the TLB entries for them are not as critical. The TLB is often secondary to L1/L2 caches.

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

As well, device drivers typically need to know physical addresses as they are outside of the CPU and do not know virtual addresses. The simplicity of subtracting PAGE_OFFSET makes for efficient code.

一对一映射的唯一优势是让 S/W 只需减去 PAGE_OFFSET 就可以直接获取各个虚拟地址的物理地址,还是在 ARMV7 MMU 页面转换方面也有其他优势?

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/核心内存以 1MB 为增量.它也非常有效.还有其他可能性,但这些可能是这个选择的胜利.

The 1:1 mapping allows for larger ranges to be mapped a one time. Typical SDRAM/core memory comes in 1MB increments. It is also very efficient. There are other possibilities, but these are probably wins for this choice.

是一对一映射的唯一优势,这样S/W就可以直接仅通过获取相应虚拟地址的物理地址减去 PAGE_OFFSET 或者在 ARMV7 MMU 上有其他一些优势页面翻译也是?

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

The MMU must be on to use the data cache and for memory protection between user space process; each other as well as user/kernel separation. Examining the kernels use of 1:1 mappings by itself is not the full story. Other parts of the kernel need the MMU. Without the MMU, the 1:1 mapping would be the identity. Ie. PAGE_OFFSET==0. The only reason to have a fixed offset is to allow memory at any physical address to be mapped to a common virtual address. Not all platforms have the same PAGE_OFFSET value.

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

Another benefit of the virt_to_phys relation; the kernel is written to execute at a fixed virtual address. This means the kernel code doesn't need to be PC-relative and yet can run on platforms with different physical addresses of the core memory. Care is taken in the arm/boot assembler code to be PC-relative as the boot loader is to hand control with the MMU off. This arm/boot code sets up up an initial mapping.

另见:查找物理地址向量表virt_to_phys映射的一个例外.
内核数据可交换吗?
内核如何管理小于1gb的?
ARM Linux 启动的一些细节?
linux 内核中的页表 - 早期启动和 MMU.

See also: Find the physical address of the vector table, an exception to the virt_to_phys mapping.
                Kernel data swappable?
                How does the kernel manage less than 1gb?
                Some details on ARM Linux boot?
                Page table in linux kernel - early boot and MMU.

这篇关于在 ARMv7 的上下文中,当 mmu 必须进行页表转换时,Linux 内核一对一映射内存的优势是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆