memory-management - 页表: Page fault

标签 memory-management virtual-memory

我有一些关于页表的问题,特别是当发生页面错误时。

据我了解,当 CPU 需要一个页面,但该页面不存在于 RAM 中,并且必须从交换空间中获取时,就会发生页面错误。页表使用虚拟地址的高阶位进行索引,并且还包含一个无效位来指示该页是否在内存中。

这是我不明白的地方。页表是否包含那些也设置了无效位的页的物理地址?我的意思是,它们不存在于物理内存中。所以,我的理解是,那些设置了无效位的页面,相应的物理地址应该是空白的。我错过了什么吗?

另一个问题是为什么我们不能只为内存中存在的那些页面提供条目。这样,页表的大小就可以变小。

还有一个问题是,当操作系统将页面错误后的页面换入RAM时,该页面所分配到的帧的物理地址是否会转换为虚拟地址以更新页表?

有人可以澄清这些疑问吗?谢谢!

最佳答案

I understand that a page fault occurs when the CPU demands a page, but it is not present in the RAM, and has to be fetched from the swap space.

页面错误的触发通常是一个或两个步骤的过程。该故障是由页表状态触发的。

The page table uses the higher order bits of the virtual address for indexing, and also contains an invalid bit that indicates if the page is in the memory.

位位置和使用完全取决于系统。无效有两个级别。 (1)页面可能没有映射到逻辑地址空间; (2)该页可能被映射,但没有到物理页框的对应映射(调出)。这两项检查可以在页表中指示,或者与操作系统维护的映射数据一起指示。

Does the page table contain the physical addresses for those pages also for whom the invalid bit is set?

如果页表项指示存在逻辑页到物理页框的有效映射,则页表项包含该映射。

I mean, they are not present in the physical memory. So, my understanding is that those pages for whom the invalid bit is set, the corresponding physical addresses should be blank.

一般情况并非如此。如果页表项通过其控制位指示不存在到物理页帧的映射,则处理器通常忽略实际映射位。这允许操作系统使用这些位来识别页面在磁盘上的存储位置。

Another question is why can't we have entries only for those pages that are present in the memory. This way, the size of the page table can be made smaller.

您正在描述一个倒排页表。有些系统以这种方式实现页表。但是,大多数系统不这样做,并且它们会给操作系统带来额外的开销。

Yet another question is that when the operating system swaps-in a page after a page fault into the RAM, is the physical address of the frame to which the page is assigned converted to virtual address for updating the page table?

页面错误处理程序需要(1)分配一个物理页框; (2)将次要故事的数据加载到页面框架中; (3)更新页表以指示逻辑页到物理页框的映射; (4)重新启动引起故障的指令。

关于memory-management - 页表: Page fault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40705152/

相关文章:

安卓开发 : Bitmaps on surfaceview leak Memory or too big?

c - 什么是命名内存块

c - 如何从C中的内存地址获取值?

Linux:禁用交换时 mmap() 的行为

C、数组,如何使用strlen

c++ - 为什么我不能在同一个分配中保留两个连续的内存区域而不用一次调用保留它们?

cpu-architecture - 拥有比有效地址大的虚拟地址有什么意义?

assembly - 为什么在64位中,虚拟地址比物理地址(52位长)短4位(长48位)?

linux - 整个进程的虚拟地址空间是否分为页面

c# - 确定对象是否已在 C# 中被销毁(即不再在任何地方找到)