存储器管理.ppt
《存储器管理.ppt》由会员分享,可在线阅读,更多相关《存储器管理.ppt(173页珍藏版)》请在三一文库上搜索。
1、第四章 存储器管理,教学目的及要求,掌握存储器管理的功能 掌握动态分区管理原理 掌握对换技术的概念 熟练掌握先进先出页面置换算法和最近最久未使用页面置换算法。 掌握请求页式管理、段式、段页式地址变换及其越界保护,重点和难点,分页存储管理的基本方法、地址变换机构和页表机制; 分段存储管理的基本原理, 分页与分段的主要区别; 先进先出页面置换算法和最近最久未使用页面置换算法,主要外语词汇,Virtual memory Logical Address Physical Address fixed partition variable partition (dynamic partition) Swa
2、pping FIFO Least recently used,补充:存储体系,存储组织是指在存储技术和CPU寻址技术许可的范围内组织合理的存储结构。 其依据是访问速度匹配关系、容量要求和价格。 寄存器-内存-外存 寄存器-缓存-内存-外存 微机中的存储层次组织: 访问速度越慢,容量越大,价格越便宜; 最佳状态应是各层次的存储器都处于均衡的繁忙状态,存储层次结构,快速缓存: Data Cache TLB(Translation Lookaside Buffer)转换后援缓冲器 内存:DRAM, SDRAM,DDR2,DDR3等; 外存:软盘、硬盘、光盘、磁带等;,存储器容量计算方法,存储容量:是
3、该存储设备上可以存储数据的最大数量,通常使用千字节(kb kilobyte)、兆字节(MB megabyte)、吉字节(GB, gigabyte)、太字节(TB ,terabyte))等来衡量。下面括号中的数字为2的指数(即多少次方) 1KB=2(10)B=1024B; 1MB=2(20)B=1024KB; 1GB=2(30)B=1024MB。 1TB=2(40)B =1024GB,计算机数制,二进制(Binary system) 八进制(Octal system) 十进制(Decimal system) 十六进制(Hexadecimal system) 十六进制转二进制: (ACEF)H=1
4、010 1100 1110 1111B,补充:内存工作原理,1、存储单元:若干个二进制位(4,8,16位等) 2、单元地址:所有的存储单元按顺序排列,每个单元都有一个编号。地址编号也用二进制数绝对地址/物理地址,补充:内存工作原理,3、寻址:通过地址编号寻找在存储器中的数据单元。存储器地址的范围多少决定了二进制数的位数. 例:如果存储器有1024个(1KB)单元,地址编码为01023,对应的二进制数是00000000001111111111,需要用10位二进制来表示,也就是需要10根地址线,或者说,10位地址码可寻址1KB的存储空间。 4、存储容量:存储器中所有存储单元的总和,存储容量的单位是
5、KB、MB与GB。,0000H 0001H 0002H FFFFH,存储单元 (字节),例 CPU 从内存读取地址为44H中的数据54,R,44H,54,例 CPU 将数据35放入内存地址为 48H中,W,48H,35,第四章 存储器管理,4.1 存储器管理的功能,4.2 连续分配方式,4.3 基本分页存储管理方式,4.5 虚拟存储器的基本概念,4.4 基本分段存储管理方式,4.7 页面置换算法,4.8 请求分段存储管理方式,4.6 请求分页存储管理方式,存储器管理的目的,Program must be brought into memory and placed within a proce
6、ss for it to be run. 存储器管理实质:对内存空间的用户区进行管理。 内存分为系统区和用户区两部分:系统区仅提供给OS使用,通常位于内存的低址部分;用户区供用户使用。 存储器管理目的:尽可能地方便用户使用存储器和提高内存空间的利用率。,存储器管理的功能,地址转换 虚拟存储器(内存空间的扩充) 内外存数据传输的控制 内存的分配与回收 内存信息的共享与保护,4.1 存储管理的功能,4.1.1 地址转换 4.1.2 虚拟存储器(内存空间的扩充) 4.1.3 内外存数据传输的控制 4.1.4 内存的分配与回收 4.1.5 内存信息的共享与保护 4.1.6 存储器管理方式,4.1.1地
7、址转换,Addresses may be represented in different ways during these steps. Addresses in the source program are generally symbolic (such as count). A compiler will typically bind these symbolic addresses to relocatable addresses (such as “14 bytes from the beginning of this module“). The linkage editor o
8、r loader will in turn bind these relocatable addresses to absolute addresses (such as 74014). Each binding is a mapping from one address space to another.,Binding of Instructions and Data to Memory,Address binding of instructions and data to memory addresses canhappen at three different stages. Comp
9、ile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes. Load time: Must generate relocatable code if memory location is not known at compile time. Execution time: Binding delayed until run time if the process can be moved during
10、its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers).,Multistep Processing of a User Program,程序的链接和装入过程,程序的链接和装入过程:将一个用户源程序转变为一个可在内存中执行的程序,需要经过: 编译:由编译程序将用户源代码编译成若干个目标模块。 链接:由链接程序将编译后形成的目标模块以及它们所需要的库函数链接在一起,形成一个完整的装入模块。 装入:由装入程序将装入
11、模块装入内存。,用户程序的链接和装入过程,地址转换(地址重定位或地址映射),内存空间是内存地址的集合,是一维线性空间。 地址转换:建立相对地址(逻辑地址)与内存绝对地址(物理地址)的关系。,逻辑地址空间和物理地址空间 Logical vs. Physical Address Space,An address generated by the CPU is commonly referred to as a logical address, whereas an address seen by the memory unit-that is, the one loaded into the me
12、mory-address register of the memory-is commonly referred to as a physical address. The compile-time and load-time address-binding methods generate identical logical and physical addresses. However, the execution-time address-binding scheme results in differing logical and physica1 addresses. In this
13、 case, we usually refer to the logical address as a virtual address.,We use logical address and virtual address interchangeably in this text. Logical-address space: The set of all logical addresses generated by a program; physical-address space: the set of all physical addresses corresponding to the
14、se logical addresses. Thus, in the execution-time address-binding scheme, the logical- and physical-address spaces differ.,Logical vs. Physical Address Space,The concept of a logical address space that is bound to a separate physical address space is central to proper memory management. Logical addr
15、ess generated by the CPU; also referred to as virtual address. Physical address address seen by the memory unit.,Logical vs. Physical Address,实现地址重定位或地址映射的方法,static linking:system language libraries are treated like any other object module and are combined by the loader into the binary program image
16、. dynamic linking:Linking postponed until execution time. This feature is usually used with system libraries, such as language subroutine libraries. Without this facility all programs on a system need to have a copy of their language library (or at least the routines referenced by the program) inclu
17、ded in the executable image. This requirement wastes both disk space and main memory.,实现地址重定位或地址映射的方法,静态地址重定位(可重定位装入方式):由装入内存时一次完成地址变换,以后不再改变。 动态地址重定位(动态运行时装入方式):程序执行过程中,在CPU访问内存之前,将要访问的程序或数据相对地址转换成内存绝对地址。需要硬件(重定位寄存器)支持。,4.1.2 虚拟存储器,虚拟存储器: 把辅助存储器作为对主存储器的扩充, 向用户提供一个比实际主存大得多的地址空间。 虚拟存储的基本原理 程序装入时,只需将当
18、前需要执行的部分页或段读入到内存,就可让程序开始执行。 内存中只存放经常被访问的程序和数据段,待到进程执行过程中需要放在辅助存储器中的信息时,再从外存中自动调入内存。,4.1.3 内外存数据传输的控制,控制内存和外存之间的数据流动的方式: (1)户程序自己控制:用户程序自己控制内外存之间的数据对换的例子(覆盖) (2)操作系统控制: 对换(swapping):把在内存中处于等待状态的进程换出内存,而把等待事件已经发生、处于就绪态的进程换入内存。 请求调入(on demand)和预调入(on prefetch): 请求调入方式是在程序执行时,如果所要访问的程序段或数据段不在内存中,则操作系统自动
19、地从外存将有关的程序段和数据段调入内存。 预调入是由操作系统预测在不远的将来会访问到的那些程序段和数据段部分,并在它们被访问之前系统选择适当的时机将它们调入内存。,Swapping,A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution. Backing store fast disk large enough to accommodate copies of all memory images
20、 for all users; must provide direct access to these memory images. Roll out, roll in swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed. Modified versions of swapping are found on many systems, i
21、.e., UNIX, Linux, and Windows.,Figure Swapping of two processes using a disk as a backing store.,4.1.4 内存的分配与回收,设计内存的分配和回收方法时须考虑的策略和数据结构: 分配结构:登记内存使用情况和供分配程序使用的表格与链表。 放置策略:确定调入内存的程序和数据在内存中的放置位置。是一种选择内存空闲区的策略。 对换策略:在需要将某个程序段和数据调入内存时,如果内存中没有足够的空闲区,对换策略被用来确定把内存中的哪些程序段和数据段调出内存,以便腾出足够的空间。 调入策略:外存中的程序段和数据
22、段什么时间按什么样的控制方式进入内存。调入策略与内外存数据流动控制方式有关。 回收策略:包括回收的时机,以及对所回收的内存空闲区和已存在的内存空闲区的调整。,4.1.5 内存信息的共享与保护,内存信息共享:在多道程序设计环境下,内存中的许多用户或系统程序和数据段可供不同的用户进程共享。提高内存的利用率。 内存信息保护: 被允许共享的部分之外,各进程不能对别的进程的程序和数据段产生干扰和破坏。 常用的内存信息保护方法:越界检查、存取控制检查和环保护机构三种。,4.1.6 存储器管理方式,按照逻辑连续分得物理空间是否连续分为两类: 1 连续分配方式(逻辑空间连续分得的物理空间连续): 固定分区 可
23、变(动态)分区方式 2 离散分配方式(逻辑连续分得物理空间不连续): 分页存储管理方式 分段存储管理方式 段页式存储管理方式,4.2 连续分配方式,4.2.1 单一连续分配,4.2.2 固定分区分配,4.2.3 动态分区分配,4.2.5 对换,4.2.4 可重定位分区分配,4.2.1 单一连续分配,Main memory usually into two partitions: Resident operating system usually held in low memory with interrupt vector. User processes held in high memor
24、y 单一连续分配Single-partition allocation:只适用于单用户、单任务的操作系统。 内存用户区仅能存放一道作业。 优点:管理简单、开销小。 缺点:资源利用率低,4.2.2 固定分区分配,固定分区管理Multiple-partition allocation:Hole block of available memory; holes of various size are scattered throughout memory. When a process arrives, it is allocated memory from a hole large enough
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 存储器 管理
链接地址:https://www.31doc.com/p-2076500.html