简体   繁体   English

如果 CPU 看到虚拟地址,页面错误处理程序如何用物理地址填充页表条目?

[英]How does page fault handler fill up the page table entry with a physical address if CPU sees virtual addresses?

I was reading about page faulting and from what I read, the MMU consults the page table to translate virtual addresses into physical addresses.我正在阅读有关页面错误的信息,从我阅读的内容来看,MMU 会参考页表将虚拟地址转换为物理地址。 It is the responsibility of the OS (via the page fault handler) to fill up these page table entries.填充这些页表条目是操作系统的责任(通过页面错误处理程序)。

What confuses me is how does the page fault handler obtain the physical addresses in the first place?让我困惑的是页面错误处理程序首先如何获取物理地址? In the diagrams and notes I saw, the CPU seems to use virtual addresses and the MMU transparently translates them to physical addresses.在我看到的图表和注释中,CPU 似乎使用虚拟地址,而 MMU 将它们透明地转换为物理地址。 Does the CPU specially work with physical address rather than virtual addresses for page fault handling? CPU 是否专门使用物理地址而不是虚拟地址来处理页面错误?

If there is an access to some 4K page that is not present in memory and the page fault handler successfully locates the corresponding 4K page on disk, how does it acquire a 4K page of physical memory and figure out the physical address of the 4K page of physical memory?如果访问了内存中不存在的某个 4K 页,并且缺页处理程序成功地在磁盘上定位了相应的 4K 页,它如何获取物理内存的 4K 页并找出该 4K 页的物理地址?物理内存?

Part of the OS`s responsibility is to keep track of a list of physical pages.操作系统的部分职责是跟踪物理页面列表。 You can look on OSDev to see how this is done - usually by querying BIOS/UEFI-exposed functions, which give you (usually non-contiguous) lists of free memory.您可以查看OSDev以了解这是如何完成的——通常是通过查询 BIOS/UEFI 公开的函数,这些函数为您提供(通常是非连续的)空闲内存列表。

UEFI in particular exposes GetMemoryMap at boot time to get an array of memory descriptors. UEFI 特别在启动时公开GetMemoryMap以获取内存描述符数组。


Given a maintained list of available physical pages - when the OS handles a page fault, it has access to the faulting virtual address, and it can decide what to do.给定一个可用物理页面的维护列表——当操作系统处理页面错误时,它可以访问出错的虚拟地址,并且可以决定要做什么。 If it needs to allocate a new page, then it will consults its list of free pages, and choose an available physical page to map into the virtual address space.如果它需要分配一个新页面,那么它会查询它的空闲页面列表,并选择一个可用的物理页面来映射到虚拟地址空间。 On x86 this mapping is done by modifying the page table and loading it into the cr3 register.在 x86 上,这种映射是通过修改页表并将其加载到cr3寄存器中来完成的。

Once the page is mapped, it can be written to using virtual addresses.一旦页面被映射,就可以使用虚拟地址写入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gdb 中的分段错误是否显示物理地址或虚拟地址? - Does a segmentation fault in gdb show the physical or virtual address? 理解分页虚拟内存的第一步:在初始页面错误时创建页表条目 - First Step in Understanding Paged Virtual Memory: Creating Page Table Entry upon Initial Page Fault 虚拟地址到物理地址的分段错误 - segmentation fault in virtual address to physical address 如何获取大页面的物理地址 - How to get the physical address of a huge-page 如何使用页面错误处理程序映射页面? - How to map pages using the page fault handler? 如何知道指针是在物理内存中还是会触发Page Fault? - How to know whether a pointer is in physical memory or it will trigger a Page Fault? 第一次将页面加载到物理 memory 会导致重大页面错误吗? - Does loading a page into physical memory for the first time cause a major page fault? 如何确定多个虚拟地址是否属于同一页面? - How to determine if multiple virtual addresses belong to the same page? 如何从结构页中获取关联数据的物理地址? - How to get the physical address of the associated data from a struct page? 使物理地址区中的虚拟地址连续如何提高性能? - How does making the virtual address contiguous in physical address zone improve performance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM