20. Advanced Page Tables

Paging: Smaller Tables

这章解决page带来的第二个问题:page table太大,会占用太多内存。

1. Simple Solution: Bigger Pages

一种非常简单的方法就是虚拟地址位数不变的情况下,增大page的大小,这样page的数量就会减少,相应的page table就会变小。但是这引入了一个问题,就是page太大的话,未使用的地址空间就会增多,简而言之就是地址空间浪费了,这就是内部碎片化(internal fragmentation)的原因。这没有很好的解决我们的问题。

2. Hybrid Approach: Paging and Segments

第二种想法就是结合segmentation和page以减小page table的开销。
举个例子。16KB地址空间和1KBpage大小:
在这里插入图片描述
page table如下
在这里插入图片描述
根据上图有:
(VPN = 0) --> (PFN = 10)
(VPN = 4) --> (PFN = 23)
(VPN = 14) --> (PFN = 28)
(VPN = 15) --> (PFN = 4)

其中阴影部分都是代表未使用(浪费)的空间!!!!!!

因此,为了减少浪费,我们不对整个地址空间使用page table,而是在每个逻辑段(code、heap、stack)中使用一个page table,所以应该有三个page table。

对于segmentation,有一对base/bounds register。在我们的这种混合方式中,base register指向对应逻辑段page table的物理地址的起始位置,bounds register指向末尾。

举个例子更容易理解。假定一个具有4KBpage的32位虚拟地址空间,并将一个地址空间分成四个段,我们仅仅使用三个段,code、heap和stack。

为了确定地址所指的逻辑段,我们使用前2位表示逻辑段,则32位虚拟地址如下:

在这里插入图片描述
当TLB Miss时,硬件使用前2位(SN)来确定选取哪个逻辑段及其基准和边界。
然后通过VPN选取对应的PFN,最后结合offset确定目的地址。
代码如下:
在这里插入图片描述
通过这种混合方法,节省了大量内存并且逻辑段之间未分配的page不再占有page table中的空间(只是将其标记为无效)
但是这种方法仍然存在问题,segmentation不灵活,如果有一个很大但很稀疏的heap,会导致外部碎片再次出现。

3. Multi-level Page Tables

多级页表的基本思想很简单。首先,将页面表切成页面大小的单位;那么,如果整页的页表条目(PTE)无效,则根本不要分配该页表中的该页。若要跟踪页表的页是否有效(如果有效,则在内存中的位置),请使用称为页目录(page directory)的新结构。因此,页面目录可以用来告诉您页面表的页面在哪里,或者页面表的整个页面不包含有效页面。
在这里插入图片描述
增加了page directory后,我们可以先查看page directory看请求的内存是否有效,如果有效再给其分配page table,这样减少了空间浪费。
但是这也引入了一些问题,首先是加载开销增加了。TLB Miss后,硬件需要首先进行page directory的地址转换,然后再进行page table的地址转换。第二个问题就是复杂性,地址转换两次(或更多)变得更复杂了。

A Detailed Multi-Level Example

话不多说,上例。
假设有一个16KB大小的虚拟地址空间,page大小为64字节。故虚拟地址空间14位,其中8位用于VPN(page table有28个entry),6位用于offset。如下所示:

在这里插入图片描述
由于有256(28)个entry,假设每个entry为4个字节,因此,page table的大小为256 X 4 = 1KB。
由于page大小为64字节,则1KB可以分为16个64字节的page,每个page可以容纳16个PTE(page table entry)。
我们首先需要对page directory进行索引,由于有16个page,故用4位进行page索引。用VPN的前四位,如下所示
在这里插入图片描述
通过PDI(page directory index)查找对应的PDE。如果PDE(page directory entry)无效,那么我们知道该访问无效,因此引发异常;如果PDE有效,那么从PDE指向的page table的page中获得PTE,该PTE就是用VPN余下的位数确定。

如下所示
在这里插入图片描述
虚拟地址0x3F80,对应二进制表示如下:
在这里插入图片描述
我们结合下表看一下。第一步,PDI = 15(二进制1111),看左边的Page Directory, PFN从上至下序号依次为0到15,则PDI = 15选择PFN = 101,由于valid = 1有效,可以选取。则跳转到最右边的@PFN:101
第二步为PTI = 14(二进制1110),我们可以看到PFN = 101的page的第14个PFN = 55,由于valid = 1有效,可以选取。
最后通过将物理地址55(0x37)与offset = 0结合就得到了最后的实际物理地址。
在这里插入图片描述

More Than Two Levels

其实page directory就和计算机磁盘目录类似。当上述情况(分两级)也无法满足的情况发生时,就可以给目录再创建一个目录,还不满足就一直套娃下去。

分析下图

在这里插入图片描述
PD Index 0是为了索引PD Index 1,PD index 1然后再索引Page Table Index。

The Translation Process: Remember the TLB

在这里插入图片描述
不论怎样,进行地址转换的时候,硬件首先都会检查TLB,如果TLB Miss,才会检查page table。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
30天打造更亲和力网站,英文语言。 怎么打造自己的网站更有亲和力?看看这本书也许能给你一点提示。 Table of Contents Dive Into Accessibility...............1 Introduction.............2 Day 1: Jackie...........3 Day 2: Michael.........4 Day 3: Bill................5 Day 4: Lillian...........6 Day 5: Marcus.........7 Day 6: Choosing a DOCTYPE.....8 Who benefits?...................8 How to do it...8 Further reading.................9 Day 7: Identifying your language.......................10 Who benefits?.................10 How to do it.10 Further reading...............11 Day 8: Constructing meaningful page titles.....12 Who benefits?.................12 How to do it.12 Further reading...............13 Day 9: Providing additional navigation aids.....14 Who benefits?.................14 How to do it.14 Further reading...............15 Day 10: Presenting your main content first......16 Who benefits?.................16 How to do it.16 Further reading...............17 Day 11: Skipping over navigation links.............18 Who benefits?.................18 How to do it.18 Day 12: Using color safely.......20 Who benefits?.................20 How to do it.20 Further reading...............21 Dive Into Accessibility i Table of Contents Day 13: Using real links...........22 Who benefits?.................22 How to do it.22 Further reading...............23 Postscript....23 Day 14: Adding titles to links...24 Who benefits?.................24 How to do it.24 Further reading...............25 Day 15: Defining keyboard shortcuts................26 Who benefits?.................26 How to do it: home page link.....................26 How to do it: skip navigation link................27 How to do it: feedback link.........................27 Further reading...............27 Day 16: Not opening new windows....................28 Who benefits?.................28 How to do it.28 Further reading...............29 Day 17: Defining acronyms.....30 Who benefits?.................30 How to do it.30 How to do it: cascading style sheets..........30 Further reading...............31 Postscript....31 Day 18: Giving your calendar a real caption.....32 Who benefits?.................32 How to do it.32 Further reading...............33 Day 19: Using real table headers.......................34 Who benefits?.................34 How to do it.34 Very important note about layout tables....36 Further reading...............36 Day 20: Providing a summary for tables...........37 Who benefits?.................37 How to do it: calendar.....37 How to do it: layout tables38 Day 21: Ignoring spacer images........................39 Who benefits?.................39 How to do it.39 Things not to do..............40 Dive Into Accessibility ii Table of Contents Day 21: Ignoring spacer images Further reading...............40 Day 22: Using real lists (or faking them properly)............41 Who benefits?.................41 How to do it.41 How to do it: advanced....42 Postscript: un−bulleted lists.......................42 Further reading...............43 Day 23: Providing text equivalents for images.44 Who benefits?.................44 How to do it.44 Examples of bad alt text..45 Examples of good alt text45 Further reading...............45 Day 24: Providing text equivalents for image maps........47 Who benefits?.................47 How to do it.48 Things not to do..............49 Further reading...............49 Day 25: Using real horizontal rules (or faking them properly)..................50 Who benefits?.................50 How to do it.50 How to do it: advanced....50 Further reading...............51 Day 26: Using relative font sizes........................52 Who benefits?.................52 How to do it: Radio.........53 How to do it: Movable Type.......................54 How to do it: detailed explanation..............55 Further reading...............57 Day 27: Using real headers......58 Who benefits?.................58 How to do it: Movable Type.......................58 How to do it: Radio.........59 Further reading...............60 Day 28: Labeling form elements........................61 Who benefits?.................61 How to do it: Movable Type.......................61 How to do it: Greymatter..62 Further reading...............63 Dive Into Accessibility iii Table of Contents Day 29: Making everything searchable.............64 Who benefits?.................64 How to do it.64 Further reading...............65 Day 30: Creating an accessibility statement.....66 Who benefits?.................66 How to do it.66 Further reading...............67 Conclusion............68 Further reading: books that I recommend..68 Accessibility statement............69 Access keys69 Standards compliance....69 Navigation aids...............69 Links...........70 Images........70 Visual design..................70 Accessibility references...70 Accessibility software......70 Accessibility services......70 Related resources...........71 Accessibility books I recommend...............71 Terms of use.........72 GNU Free Documentation License....................73 0. PREAMBLE................73 1. APPLICABILITY AND DEFINITIONS....73 2. VERBATIM COPYING.74 3. COPYING IN QUANTITY......................74 4. MODIFICATIONS.......75 5. COMBINING DOCUMENTS..................76 6. COLLECTIONS OF DOCUMENTS.......76 7. AGGREGATION WITH INDEPENDENT WORKS76 8. TRANSLATION...........77 9. TERMINATION...........77 10. FUTURE REVISIONS OF THIS LICENSE..........77 How to use this License for your documents.............77 Translations..........79 Chinese.......79 Estonian......79 Finnish........79 French.........79 German.......79 Italian..........79 Norwegian...79 Dive Into Accessibility iv Table of Contents Translations Polish..........79 Romanian...80 Spanish.......80 Swedish......80

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值