如何计算页表大小? [英] How to calculate page table size?

查看:146
本文介绍了如何计算页表大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定:64 位虚拟字节地址,16 KB 页,32 位物理字节地址.

Given : 64 bit virtual byte address, 16 KB pages, 32-bit physical byte address.

这台机器上页表的总大小是多少,假设有效位、保护位、脏位和使用位共 4 位,并且所有虚拟页都在使用中.

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.

到目前为止,我知道页表条目的总数:2^64/2^14 = 2^50,但我无法理解如何找到每个条目的大小.

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.

每个条目确实包含问题中所说的 4 位,但是可以从物理字节地址中找到条目的其余部分吗?这部分我很困惑.

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.

谢谢.

推荐答案

见下面一种计算页表大小的方法:

See below one method of calculating page table size:

  1. 首先通过计算log2(以字节为单位的页面大小)获得页面偏移.在您的示例中,页面大小为 16 KB,因此 log2(16*2^10) 为 14;也就是说,页偏移量是 14 位.

  1. 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.

然后,通过从分配给物理地址的总位数中减去页面偏移量来计算物理页码 (PPN) 大小.因为在您的示例中,物理地址是 32 位,PPN = 32 - 14 或 18 位.

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.

现在您可以通过向计算出的 PPN 添加有效位、保护位等来计算页表条目 (PTE) 大小.该值将是每个页面条目所需的总位数.在我们的示例中,PTE 将是 22 位.

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.

我们需要的最后一条信息是页表中的页条目数.我们可以通过从我们拥有的虚拟页号的总位数中减去页偏移量来得到它;也就是说,64 - 14 = 50 即我们需要 2^50 个条目来表示虚拟地址的完整范围.

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.

所以总页表大小达到 2^50 * 22 位,大​​约为 2.75PB.由于要保存在内存中的内容很多,而且可能既昂贵又缓慢,现代处理器使用翻译后备缓冲区 (TLB) 作为最近使用的页面条目的缓存.

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.

希望这会有所帮助!

这篇关于如何计算页表大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆