PTE 和结构页面的详细信息

Details for PTE and struct page

据我了解,当用户空间进程访问某个虚拟地址时,MMU 会尝试为所请求的虚拟地址找到 PTE。在 PTE 中有编码的 struct page 的 PFN 和一些标志。

至此,我的问题是:如果翻译后的地址指向一个struct page,那么物理内存究竟是如何被访问的呢?我认为 struct page 只是页面描述符,而不是一个空的物理内存区域。

when an userspace process accesses to some virtual address, the MMU tries to find the PTE for the requested virtual address

是的,这是正确的。页面 table 向下走到特定的 PTE(如果有的话)。

In the PTE there is the encoded struct page's PFN and some flags.

不是真的。 PTE 包含虚拟地址转换到的 实际物理内存页面 的 PFN(页面帧编号)。也就是说,它指向的是物理内存中的实际页,而不是对应的struct page.

if the translated address points to a struct page, how exactly is physical memory is accessed? I think struct page is just page descriptor, not a empty physical memory region.

转换地址指向struct page,它指向物理内存。实际上,struct page 只是系统用来跟踪页面性质和状态的“描述符”,并存储在其他地方。

所有struct page结构都存储在一些特定的内存区域,这取决于底层架构。您可以在 Mel Gorman 的书“了解 Linux 虚拟内存管理器”Chapter 2: Describing Physical Memory 中阅读更多相关信息。

一旦你有了 PTE (pte_t),pte_page() macro can be used to get the address of the corresponding struct page. This address is calculated using a set of macros (e.g. __pfn_to_page()) which basically end up indexing a mem_section which contains a pointer to an array of struct page (.section_mem_map). There is a global array of struct mem_section, and each PTE PFN has a section index encoded in it,它被用来 select 正确的部分。