Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1953210
  • 博文数量: 77
  • 博客积分: 2175
  • 博客等级: 大尉
  • 技术积分: 2491
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-20 20:49
个人简介

欢迎光临我的博客

文章分类

全部博文(77)

文章存档

2023年(1)

2018年(4)

2017年(1)

2016年(2)

2015年(2)

2013年(5)

2012年(29)

2010年(33)

分类: LINUX

2010-06-24 19:11:02

Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

3.1 

在没有虚存机制的计算机中,程序指令所访问的内存地址就是物理内存地址。而在有虚存机制并且该机制打开的情况下,程序指令所访问的内存地址都是虚拟内存地址。某个虚拟内存地址可以通过设置被映射到任何物理内存地址,如图3-1所示。
Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

3-1  虚拟内存可被映射到任意物理地址

程序运行时,虚存地址到物理地址的转换工作是由专门的硬件完成的,它叫做内存管理单元(Memory Management UnitMMU)。转换过程如图3-2所示。



Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

3-2  虚拟地址转换成物理地址的过程

从图3-2中可以看出,当CPU访问某虚存地址时,不管是读指令或读写数据,该地址首先会被发送给内存管理单元进行转换。在获得转换后的物理地址后,CPU再对该物理地址进行读写操作。

为什么要单独增加一个MMU硬件来处理虚拟地址向物理地址的转换呢?...

Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

 

3.2  虚拟内存的

3.2.1  安全性

虚拟内存是保证系统安全的一个重要机制。
Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

3.2.2  提高空间利用率

利用虚存机制还可以充分利用物理内存空间
Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}


3.2.3  多进程的支持


Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

3.3  PDP11/40虚拟内存机制

PDP 11/40的内存管理单元把物理内存等分成很多大小为64字节的连续块(block),并从0开始顺序编号,如图3-7所示:

尽管PDP 11/40的操作模式都是16位模式,但它的CPU和总线都支持18位地址模式,所以其最大地址空间实际可达256K4096个物理块。

PDP 11/40的内存管理单元为用户模式和内核模式分别提供了8组、每组两个内存映射寄存器:

816位页地址寄存器PARPage Address Register):PAR07

816位页描述寄存器 PDRPage Descriptor Register):PDR07

这样,实际上系统中一共有8×2×2=32个内存映射寄存器。每对PAR/PDR可称为一个

32位的APR(活动页寄存器——Active Page Register),APR在物理上并不存在,它是为了理解和叙述上的方便而引入的。活动页寄存器示意图如图3-8所示
Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

内存管理单元对虚拟内存按页管理,它把虚拟内存分成很多活动页,每一个活动页最大不超过8K,由一个32位的活动页寄存器来描述它映射到物理内存的情况。因此64K的虚拟内存需要8个活动页寄存器才能完成映射。虚拟内存与活动页寄存器对应的情况如图3-9   所示。


Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

3-9  虚拟内存与活动页寄存器对应图

3.3.1  页地址寄存器(PAR



Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

页地址寄存器是32位活动页寄存器的第一个字(word),其位11012位是页地址字段PAFPage Address Field),用于指定物理内存的块号,并以该块地址作为本虚拟页的起始地址。例如:PAF = 100,则本虚拟页从100号物理块开始,起始物理地址是100 × 64 = 6400=0x1900

Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

1512保留未使用。

3.3.2  页描述寄存器(PDR


Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

页描述寄存器是32位活动页寄存器的第二个字,它用来描述本页的一些属性,比如访问权限和大小等。

1)位21:访问控制字段(Access Control Field),用于设定页的访问权限。

Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

   

   

00

不存在

任何形式的访问都会导致异常退出

01

只读

只允许读操作,写操作会导致异常退出

10

未使用

任何形式的访问都会导致异常退出

11

读写

读写操作都允许

如果程序指令对页实行非该字段允许的操作,则会导致产生自陷而退出(abort)。

2)位3:方向延续字段(Expansion Direction),该字段指定页内存空间的延续方向。

ED=0:空间向上延续(upwards)。页地址寄存器中的PAF字段指定的物理块是该页的最低地址块,并且地址空间向高地址延续。

ED=1:空间向下延续(downwards)。页地址寄存器中的PAF字段指定的物理块并不是该页的最低地址块,而是它的一个基线,地址空间从PAF+128处向低地址延续。

36:修改标志位(Written Info)。表示该页是否被修改过。这和现代虚拟内存页中的脏页标志(dirty flag)非常相似。主要用于指导在进程换出操作时,该页是否需要被换出。如果该位被置(W=1),表明该页在程序运行期间被修改过,则需要换出(写入磁盘)以防数据丢失,否则该页不需要换出。但UNIX系统在进行换出操作时,并没有判断该位,即不管该页是否被修改都换出。


...      ...

上一章    UNIX综述                                            目录                                   下一章    启动过程


本书在全国各大书店及网城均有销售:
                         
                       








阅读(2804) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~