剖析内存中的程序

剖析内存中的程序

ID:42648731

大小:227.84 KB

页数:8页

时间:2019-09-19

剖析内存中的程序_第1页
剖析内存中的程序_第2页
剖析内存中的程序_第3页
剖析内存中的程序_第4页
剖析内存中的程序_第5页
资源描述:

《剖析内存中的程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、AnatomyofaPrograminMemory剖析内存中的程序Memorymanagementistheheartofoperatingsystems;itiscrucialforbothprogrammingandsystemadministration.InthenextfewpostsI'llcovermemorywithaneyetowardspracticalaspects,butwithoutshyingawayfrominternals・Whiletheconceptsaregeneric,examplesaremostlyfromLinuxandWindowson

2、32-bitx86・Thisfirstpostdescribeshowprogramsarelaidoutinmemory.内存管理系统是操作系统的心脏;尤其对程序的运行和系统的管理至关重要。作者会在接下来的几篇文章中从实际的角度来概述下内存管理相关的内容。因为概念是相同的,所以例子大部分来自32位的X86的linux和windows系统。这篇文章主要描述一^程序在内存中的布局。Eachprocessinamulti-taskingOSrunsinitsownmemorysandbox.Thissandboxisthevirtualaddressspace,whichin32-bit

3、modeisalwaysa4GBblockofmemoryaddresses・Thesevirtualaddressesaremappedtophysicalmemorybypagetables,whicharemaintainedbytheoperatingsystemkernelandconsultedbytheprocessor.Eachprocesshasitsownsetofpagetables,butthereisacatch.Oncevirtualaddressesareenabled,theyapplytoallsoftwarerunninginthemachine,

4、includingthekernelitself.Thusaportionofthevirtualaddressspacemustbereservedtothekernel:在多任务的操作系统中,每个进程都运行在自己的内存沙箱内。这个沙箱就是虚拟内存地址空间,在32位模式下总是一个4GB的内存空间。这些虚拟地址通过页表对应到实际的物理内存,它们被操作系统的内核所维护并被处理器使用。每个进程都有它们自己的页表’但是会有一些限制。一旦虚拟地址被使用,它们会被所有运行在机器上的软件所使用,包括内核自身。因此有一块虚拟地址空间必须是留给内核专用(如下图所示,通常linux的默认配置是仁3,但

5、是,这是可配的,通常一些server,如大的关系数据库或者route可能会采取别的配比模式):LinuxUser/KernelWindowsdefaultMemorySplitmemorysplitKernelSpace(1GB)Oxffffffff0XC0000000KernelSpace(2GB)0x80000000UserModeSpace(3GB)UserModeSpace(2GB)Windowsbootedwith/3GBswitchKernelSpace(1GB)UserModeSpace(3GB)OnlyappliestoEXEsflaggedaslarge-addre

6、ssaware.Thisdoesnotmeanthekernelusesthatmuchphysicalmemory,onlythatithasthatportionofaddressspaceavailabletomapwhateverphysicalmemoryitwishes.Kernelspaceisflaggedinthepagetablesasexclusivetoprivilegedcode(ring2orlower),henceapagefaultistriggeredifuser-modeprogramstrytotouchit.InLinux,kernelspac

7、eisconstantlypresentandmapsthesamephysicalmemoryinallprocesses.Kernelcodeanddataarealwaysaddressable,readytohandleinterruptsorsystemcallsatanytime.Bycontrast,themappingfortheuser-modeportionoftheaddressspacechangeswheneveraprocess

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。