多级页表的逻辑地址是如何划分的
Hi,
In order to use large size page table hierarichal paging is done .
In case of two level page table scheme . for :
logical address space - 32bit - 2^32
page size - 4kb i.e 2^12
In one level :
page number - 20bit calculated as (32 - 12)
page offset - 12 bit
Now, In two level :
again, page number - 20bit is split into pagenumber(second level) and page offset .also
the address space is (2^20)
considering again page size of 4kb - (2^12)
so page number(second level ) should be calculated as : (20 - 12 ) - 8bits
and page offset : 12 bits.
But, It is mentioned that page number is divided evenly :
i.e page number p1 - 10 bits
page number p2 - 10 bits
page offset d - 12bits.
Why is the second level pagenumber divided evenly ? Is it that this division done
arbitarily according the requirement ? Is there no specific method for dividing as in case of single-level page table ?
任何帮助都将是有价值的。 谢谢, 塔齐姆
Hi,
In order to use large size page table hierarichal paging is done .
In case of two level page table scheme . for :
logical address space - 32bit - 2^32
page size - 4kb i.e 2^12
In one level :
page number - 20bit calculated as (32 - 12)
page offset - 12 bit
Now, In two level :
again, page number - 20bit is split into pagenumber(second level) and page offset .also
the address space is (2^20)
considering again page size of 4kb - (2^12)
so page number(second level ) should be calculated as : (20 - 12 ) - 8bits
and page offset : 12 bits.
But, It is mentioned that page number is divided evenly :
i.e page number p1 - 10 bits
page number p2 - 10 bits
page offset d - 12bits.
Why is the second level pagenumber divided evenly ? Is it that this division done
arbitarily according the requirement ? Is there no specific method for dividing as in case of single-level page table ?
Any help will be valuable .
Thanks,
Tazim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 4 KB 页面,最后 12 位是页面的偏移量。这样就剩下 20 位作为 32 位地址。这 20 位用作页表的索引,而不是偏移量。通过将它们均匀地分布在两个级别之间,表的大小相同。第一个表指定第二个表的地址,第二个表指定页的物理地址。每个索引 10 位意味着每个表中有 1024 个条目。这非常方便,因为这意味着使用 32 位条目时每个表恰好是 1 页。
示例:取地址0x00FF1234。该地址的二进制表示为 00000000111111110001001000110100。通过将其拆分,我们得到 0000000011 1111110001 001000110100,或 0x3 0x3F1 0x234。因此,第一级表中的第3项给出了第二级表的地址,第二级表中的第0x3F1项给出了所使用的页面的地址,该地址是该页面的0x234字节。
With 4 KB pages, the last 12 bits are the offset into the page. That leaves 20 bits for a 32 bit address. These 20 bits are used as an index into the page tables, not an offset. By splitting them evenly between the 2 levels, the tables are both the same size. The first table specifies the address of the second table, and the second table specifies the physical address of the page. 10 bits for each index means 1024 entries in each table. This is very convenient because it means each table is exactly 1 page when using 32 bit entries.
Example: Take the address 0x00FF1234. The binary representation of this address is 00000000111111110001001000110100. By splitting this up, we get 0000000011 1111110001 001000110100, or 0x3 0x3F1 0x234. So item 3 in the first level table gives the address of the second level table, item 0x3F1 in the second table gives the address of the page used, and the address is 0x234 bytes into that page.
这个博客系列有一组非常深入的示例,介绍页表如何工作、如何转换虚拟<->物理地址等。
这是摘录;
This blog series has a very indepth set of examples for how the page table works, how to convert virtual<->physical addresses and such.
Here's an exerpt;
很明显,偏移量需要12位。
当每个条目的大小为 4 字节时,您得到的结果是外页表 10 位,内表表 10 位。计算如下:
(2^20 个条目 × 4 字节/条目)/4k 字节 = 2^10 -->外页表应有 10 位
(页表占用的空间)/帧(或页)大小=数量。内部页表数量
4k 字节/4 字节 = 2^10 -->内页表应有 10 位
(页表中页面的大小)/条目大小=数量。帧
那它如何获得 10 位和均匀的 10 位。对于不同的情况,不一定要均匀分布。
It is obvious that the offset takes 12 bits.
When the size of each entry is 4bytes, you get result that 10 bits for outer page table and 10 bits for inner table table. The calculation is as following:
(2^20 entries × 4 bytes/entry)/4k bytes = 2^10 --> outer page table should have 10 bits
(space taken by page table)/frame(or page)size = no. of inner page tables
4k bytes/4 bytes = 2^10 --> inner page table should have 10 bits
(size of pages in page table)/size of entries = no. frames
That how it gets 10 bits and 10 bits evenly. For different situation, it is not necessary to have even distribution.