如何计算页表大小?
给定:64 位虚拟字节地址,16 KB 页,32 位物理字节地址。
假设有效位、保护位、脏位和使用位总共占4位,并且所有虚拟页都在使用中,则本机页表的总大小是多少。
到目前为止,我知道页表条目的总数:2^64 / 2^14 = 2^50,但我无法理解如何找到每个条目的大小。
正如问题中所述,每个条目确实包含 4 位,但是可以从物理字节地址找到条目的其余大小吗?我对这部分感到困惑。
谢谢。
Given : 64 bit virtual byte address, 16 KB pages, 32-bit physical byte address.
What is the total size of page table on this machine, assuming that the valid, protection, dirty and use bits take a total of 4 bits and all virtual pages are in use.
So far I know the total number of page table entries : 2^64 / 2^14 = 2^50, but am not able to understand how to find the size of each entry.
Each entry does contain 4 bits as said in the question, but can the size rest of the entry be found from the physical byte address? I'm confused in this part.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅下面一种计算页表大小的方法:
首先通过计算 log2(页大小以字节为单位)来获取页偏移量。在您的示例中,页面大小为 16 KB,因此 log2(16*2^10) 为 14;即页偏移量为14位。
然后,通过从分配给物理地址的总位数中减去页偏移量来计算物理页号 (PPN) 大小。由于在您的示例中,物理地址为 32 位,PPN = 32 - 14 或 18 位。
现在您可以通过在计算出的 PPN 中添加有效位、保护位等来计算页表条目 (PTE) 大小。该值将是每个页条目所需的总位数。在我们的示例中,PTE 将为 22 位。
我们需要的最后一条信息是页表中的页条目数。我们可以通过从虚拟页号的总位数中减去页偏移量来得到这个值;也就是说,64 - 14 = 50,即我们需要 2^50 个条目来表示虚拟地址的完整范围。
因此页表总大小达到2^50 * 22 位,大约为 2.75PB。由于要保存在内存中的数据量很大,并且可能既昂贵又缓慢,因此现代处理器使用翻译后备缓冲区(TLB) 作为最近使用的页面条目的缓存。
希望这有帮助!
See below one method of calculating page table size:
First get page offset by calculating log2(page size in bytes). In your example, page size is 16 KBytes, so log2(16*2^10) is 14; that is, page offset is 14 bits.
Then, calculate Physical Page Number (PPN) size by subtracting page offset from total number of bits allocated for physical address. Since in your example, physical address is 32-bit, PPN = 32 - 14, or 18 bits.
Now you can calculate Page Table Entry (PTE) size by adding valid bit, protection bit, etc. to the calculated PPN. This value will be the total number of bits required per page entry. In our example, PTE will be 22 bits.
One last piece of information we need is the number of page entries in the page table. We can get this by subtracting page offset from the total number of bits we have for the virtual page number; that is, 64 - 14 = 50 i.e. we need 2^50 entries to represent the full range of the virtual addresses.
So the total page table size comes up to 2^50 * 22 bits, which comes around to be 2.75PB. Since this is a lot to keep in memory, and will probably be expensive and slow, modern processors use Translation Lookaside Buffer (TLB) as a cache for recently used page entries.
Hope this helps!
您的页面大小为 16 KB = 2^14,因此您需要 14 位的页面偏移量。
在 64 位虚拟地址中,如果去掉这个偏移量,就会剩下 50 位。
这意味着页表中有 2^50 个条目。
此外,由于物理地址是 32 位,并且偏移量占这 32 位中的 14 位,因此剩下的 18 位必须来自页表。
在这 18 位中,4 位是您的有效位、使用位等。
无论如何,每个条目使用的位 = 18
页表的总内存(这是每个进程的,因此您必须将其乘以数字进程数(如果指定)= 2^50 * 18 位
You have a 16 KB page size = 2^14, therefore you need 14 bits for the page offset.
Out of the 64 bit virtual address, if you take out this offset, you'll be left with 50 bits.
This implies that you have 2^50 entries in your page table.
Further, since your physical address is 32 bits, and the offset makes up 14 bits out of this 32 bits, you are left with the 18 bits that has to come from the page table.
Out of these 18 bits, 4 bits are your valid, use, etc.
Anyway, the per entry, the bits used = 18
Total memory for the page table (this is per process, so you'd have to multiply it by the number of processes if that's specified) = 2^50 * 18 bits
对于那些可能想知道的人来说,有一点澄清,因为我在CSAPP中没有找到明确的定义,并且在我学习时感到困惑。 物理页号(PPN)指的是这个PA在哪个页。如果PPN = 0,则该PA在第0页表中,如果PPN=11,则该PA在第3页表中。一个技巧是偏移量的位数决定了该位置的大小。如果页面偏移为 14 位,则页面大小为该位置的 2^14 个单位(此处为每个 PTE)。如果我错了请纠正我。
A little bit of clarification for those who might wonder, since I did not find the clear definition in CSAPP and came confusing when I was studying. Physical Page Number (PPN) refers to which page this PA is in. If PPN = 0, then this PA is in the 0th page table, if PPN=11, then the PA is in the 3rd table. One trick is that number of bits of an offset determines the size of that location. If page offset is 14 bits then the size of a page is 2^14 unit of that location(here is per PTE). Correct me if I'm wrong.