《七章节存储器管理.ppt》由会员分享,可在线阅读,更多相关《七章节存储器管理.ppt(28页珍藏版)》请在三一办公上搜索。
1、第七讲 存储器管理,中国科学技术大学计算机系 陈香兰2013Fall,内容提要,存储器的层次结构程序执行的基础知识、程序的装入和链接连续分配存储管理方式分页存储管理方式分段存储管理段页式存储管理,存储器的层次结构,存储器是计算机系统的重要组成部分容量、价格和速度之间的矛盾内存、外存;易失性和永久性内存,是稀缺资源在现代计算机系统中,存储通常采用层次结构来组织多级存储器结构主存与寄存器高速缓存和磁盘缓存,多级存储器结构,Storage systems in a computer system can be organized in a hierarchySpeed,access timeCost
2、 per bitVolatility,主存 vs.寄存器,Same:Access directly for CPURegister nameMemory addressDifferent:access speedRegister,one cycle of the CPU clockMemory,Many cycles(2 or more)Disadvantage:CPU needs to stall frequently&this is intolerableRemedyCache,高级缓冲技术caching,CachingCopying information into faster sto
3、rage systemWhen accessing,first check in the cache,ifIn:use it directlyNot in:get from upper storage system,and leave a copy in the cacheUsing of cachingRegisters provide a high-speed cache for main memoryInstruction cache&data cacheMain memory can be viewed as a fast cache for secondary storage,Mag
4、netic disks 磁盘,Transfer time 传输时间TT data size*Transfer rateTransfer rate(n M/s)-1(n Byte/us)-1 1/n us/BytePositioning time 定位时间Seek time 寻道TsRotational latency 旋转延迟TRTP Ts+TR m msTT VS.TPPlease Store data closely,内容提要,存储器的层次结构程序执行的基础知识、程序的装入和链接连续分配存储管理方式分页存储管理方式分段存储管理段页式存储管理,程序执行的基础知识,Von Neumann ar
5、chitecture 冯诺依曼体系结构(图)Program must be brought into memoryMain memory is usually too smallProcessProgram must be placed within a process for it to be executed作业池User programsWhere to place the programseveral steps(图),地址的类型,Absolute address 绝对地址Address seen by the memory unitPhysical address 物理地址Relat
6、ive address 相对地址Linear address 线性地址Logical address 逻辑地址Generated by the CPUVirtual address 虚拟地址When can the absolute address can be decided?,Address binding 地址的绑定,Address binding 地址绑定,the binding of instructions and data to memory,可以在三种时刻进行Compile timeIf memory location known a priori,absolute code
7、can be generated;must recompile code if starting location changes.Load timeMust generate relocatable code if memory location is not known at compile time.Execution timeBinding delayed until run time if the process can be moved during its execution from one memory segment to another.Need hardware sup
8、port for address maps(e.g.,base and limit registers),逻辑地址空间和物理地址空间,Logical address space 逻辑地址空间The set of all logical addresses generated by a programPhysical address space 物理地址空间The set of all physical addresses corresponding to theses logical addresses Logical=physical compile-time&load-time addre
9、ss-bindinglogical(virtual)!=physical addresses execution-time address-bindingMMU(hardware device),Memory-Management Unit(MMU),Hardware device,逻辑地址 物理地址Relocation register 重定位寄存器Added to every address generated by a user process at the time it is sent to memoryE.g.MS-DOS on 80 x86User program deals w
10、ith logical addresses,it NEVER sees the real physical addresses.,是否需要将进程的所有代码和数据一次性装入?,Shall we put the entire program&data of a process in physical memory before the process can be executed?For better memory space utilizationDynamic loadingDynamic linkingOverlaysSwapping,程序的装入,绝对装入方式可重定位装入方式动态运行时装入
11、方式,绝对装入方式,编译时,产生absolute code,即使用绝对地址的代码装入时,必须装入到指定的地址无需对程序和数据的地址进行修改适用于单道系统,可重定位装入方式,大多数情况下,不能预知装入地址,只能在装入时确定编译时,产生可重定位代码,即使用相对地址的代码装入时,必须重定位通常把在装入时对目标程序中指令和数据的修改过程称为重定位。由于地址变换是在装入时一次性完成的,以后不再改变,故称为静态重定位可用于多道系统,动态运行时重定位,有时候,程序会在内存中移动位置例如对换需要能支持在运行过程中动态改变程序在内存中的位置方法:推迟重定位时机即从相对地址到绝对地址的转换推迟到程序真正执行时才进
12、行因此,装入内存中的代码和数据的地址仍然是相对地址需要重定位寄存器的支持,动态运行时装入方式,根据程序运行的局部性,让程序及其数据在需要时才被装入Better memory-space utilization;unused routine is never loaded.Useful when large amounts of code are needed to handle infrequently occurring casesError routine No special support from OS is required implemented through program
13、designDue to the users,Overlays 覆盖技术,Keep in memory only those are needed at any given time.Needed when process is larger than amount of memory allocated to it.Implemented by user,no special support needed from OS,programming design of overlay structure is complex,程序的链接,多个源程序编译多个目标模块;库。需要链接成可装入模块根据链
14、接时间的不同静态链接方式:装入前很早就链接装入时动态链接:边装入,边链接运行时动态链接:运行时才链接,静态链接方式,静态链接方式:在程序运行之前,先将各目标模块以及它们所需要的库函数,链接成一个完整的装配模块,以后不再拆开。各目标模块内:相对地址存在目标模块之间的调用关系外部调用符号要解决的问题:修改相对地址:多个相对地址空间一个统一的相对地址空间变换外部调用符号,装入时动态链接,在装入时,根据外部模块调用事件,使用装入程序去寻找相应的外部目标模块,并装入,在装入时,修改相对地址优点:便于修改和更新便于实现对目标模块的共享,运行时动态链接,程序的每次运行,可能要执行的目标模块集是不同的全部装入?按需装入?运行时动态链接将对某些模块的链接推迟到程序执行时才进行需要操作系统配合优点:程序运行前的装入速度加快;省空间,作业:,从一个源程序到一个在内存中可执行的程序,一般需要哪几个步骤?有哪几种地址类型?有哪几种程序装入方式和链接方式?,