怎么做代理ip网站,欧美网站风格,网店装修的意义,dw免费网站模板下载虚拟内存的作用#xff1a;1.扩展实际有限的物理内存#xff0c;当然这种扩展是虚拟的#xff0c;比如物理内存512M#xff0c;对于一个需要1G空间的进程来说#xff0c;照样可以运行。这增加了操作系统是应用范围。2.使得进程中的数据空间增大#xff0c;增大到多少与硬…虚拟内存的作用1.扩展实际有限的物理内存当然这种扩展是虚拟的比如物理内存512M对于一个需要1G空间的进程来说照样可以运行。这增加了操作系统是应用范围。2.使得进程中的数据空间增大增大到多少与硬件有关对于一个32位的芯片进程中的数据空间可以为4G[2^32]对于64位的芯片则支持2^64大小的空间。这一点使得进程自身可操作的空间大大增加。通俗来讲虚拟内存的管理的核心是解决如何在小的物理内存中运行更大程序的问题。在Linux中解决这个问题的关键是一个叫做pagetable[PT页面转换表]的结构。Linux把物理内存分为了固定统一大小的块称为page[页]一般为4KB并且每个页都有一个编号[page framenumber]。这样一个512M大小的内存将包括128K个页。这种方式称为paging使得操作系统对内存的管理更方便。pagetable的作用就是将进程操作的地址[虚拟地址]转换成物理地址。其原理很简单如下用一个32位芯片的系统为例[64位同理]运行的每个进程的可操作数据空间为2^32即2^20个页设其物理内存为512M则物理页有2^17个现在就说明如何将2^20个页放入2^17个页中运行。我们把进程操作的地址分为两部分第一部分为地址的高20位第二部分为后12位这样很容易将第一部分理解为虚拟页标号第二部分理解为在页中的offset。那么现在我们只需将虚拟页标号对应到物理页号即可这个对应就是pagetable的工作在这个例子中pagetable包括了2^20个记录每个记录有两部分组成20位的虚拟标号和17位的物理标号这样CPU用进程地址的第一部分作为索引找到对应的17位物理标号与地址的第二部分一起便组成一个29位的地址这个地址就是要找的物理地址。因为物理页少于虚拟页所以pagetable中的有些记录的后17位是空的或无效的。利用这个方法使得运行的进程无需知道自己操作的地址是虚拟的和运行在一个真实的大物理内存中效果是一样的。可以看出在进程的运行过程中page table必须一直保存在内存中在上面的例子中我们把虚拟地址分了2层pagetable有2^20个记录需要1M左右的空间为了节省空间我们可以将地址分为3层第一层10位需要1K左右的空间第二层10位需要1K左右的空间第三层12位这样在一段时间内只需要2K的空间保存pagetable。实际上Alpha的芯片采用的就是这种3层的分法Intel的芯片采用的2层的分法。Figure: Three Level Page TablesLinux assumes that there are three levels of page tables.Each Page Table contains the page frame number of the next level of Page Table. TheFigure above shows how a virtual address canbe broken into a number of fields; each field providing an offset into aparticular Page Table.To translate a virtual address into a physical one, the processor must take thecontents of each level field, convert it into an offset into the physicalpage containing the Page Table and read the page frame number of the next level of PageTable.This is repeated three times until the page frame number of the physical pagecontaining the virtual address is found.Now the final field in the virtual address, the byte offset, is used tofind the data inside the page.Each platform that Linux runs on must provide translation macros that allowthe kernel to traverse the page tables for a particular process.This way, the kernel does not need to know the format of the page table entries orhow they are arranged.This is so successful that Linux uses the same page table manipulation code forthe Alpha processor, which has three levels of page tables, and for Intel x86 processors,which have two levels of page tables.