简体   繁体   English

Tanenbaum的现代操作系统中的页表大小练习

[英]Page table size exercise from Tanenbaum's Modern Operating Systems

I decided to test my knowledge of internals of operating systems by solving problems from A. Tanenbaum's 'Modern Operating Systems'. 我决定通过解决A. Tanenbaum的“现代操作系统”中的问题来测试我对操作系统内部的知识。 And encountered the following problem: 并遇到以下问题:

Suppose that a machine has 48-bit virtual addresses and 32-bit physical addresses. 假设一台计算机具有48位虚拟地址和32位物理地址。 If pages are 4 KB, how many entries are in the page table if it has only a single level? 如果页面为4 KB,那么如果页面只有一个级别,那么页面表中有多少个条目?

As always since we have 48 bit virtual address space, we need to be able to map every memory address to physical one. 与往常一样,由于我们具有48位虚拟地址空间,因此我们需要能够将每个内存地址映射到物理地址。 So we have 2^48 addresses and each page is 4KB=2^12, so we need 2^36=2^(48-12) entries in a page table. 因此,我们有2 ^ 48个地址,每个页面为4KB = 2 ^ 12,因此我们在页面表中需要2 ^ 36 = 2 ^(48-12)个条目。 So when we get 48 bit address we use higher 36 bits as an index to page table to find the number of page frame and then use lower 12 bits as an offset in a page frame. 因此,当我们获得48位地址时,我们使用较高的36位作为页表的索引来查找页帧的数目,然后使用较低的12位作为页帧中的偏移量。

Then I looked up in the solutions manual for the correct answer: 然后,我在解决方案手册中查找了正确的答案:

We need one entry for each page, or 2^24 = 16 × 1024 × 1024 entries, since there are 36 = 48 − 12 bits in the page number field. 每页需要一个条目,或者2 ^ 24 = 16×1024×1024个条目,因为页码字段中有36 = 48 − 12位。

I can not understand the reasoning behind the correct answer, is it indeed correct or am I missing something ? 我不明白正确答案背后的原因,这确实是正确的,还是我遗漏了一些东西?

You are absolutely right. 你是绝对正确的。 If you have 48-bit virtual address and 4KB pages, you need at least 12 bits to choose the right byte in the page. 如果您具有48位虚拟地址和4KB页面,则至少需要12位才能在页面中选择正确的字节。 So you have 2^48-2^12 = 2^36 entries in your page table to translate virtual address to physical. 因此,您的页表中有2 ^ 48-2 ^ 12 = 2 ^ 36个条目,可以将虚拟地址转换为物理地址。 (Some of them would be on your disk). (其中一些会在您的磁盘上)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM