操作系统原理操作系统原理 (41).pdf
操作系统操作系统原理原理 Operating System PrincipleOperating System Principle 8 8-4 4 分页分页 这是因为这种分配要求把作业必须安置在一连续存储区内的缘故这是因为这种分配要求把作业必须安置在一连续存储区内的缘故。如果允许物理地址空间非连续如果允许物理地址空间非连续,是否可以解决是否可以解决?分页存储管理是解决存储碎片的一种方法分页存储管理是解决存储碎片的一种方法,要避开连续性要求要避开连续性要求,允许进程的允许进程的 物理地址空间不连续物理地址空间不连续。paging 01 02 还有别的办法能解决外碎片吗?动态分区产生外碎片的原因是什么?01 02 03 physical address space of a process can be noncontiguous;process is allocated physical address space of a process can be noncontiguous;process is allocated physical memory whenever the latter is available.physical memory whenever the latter is available.(进程(进程的的物理物理地址空间地址空间可以可以是不连续的,如果有可用的物理内存,它将分给进程。)是不连续的,如果有可用的物理内存,它将分给进程。)Divide physical memory into fixedDivide physical memory into fixed-sized blocks called frames(size is sized blocks called frames(size is power of 2,between 512 bytes and 8192 bytespower of 2,between 512 bytes and 8192 bytes).).(把物理内存分成大小固定的块。)把物理内存分成大小固定的块。)Divide logical memory into blocks of same size called pages.Divide logical memory into blocks of same size called pages.(把逻辑内存也分为固定大小的块,叫做页。)(把逻辑内存也分为固定大小的块,叫做页。)paging page 0 page 1 page 2 page 3 logical memory physical memory frame number 0 page 0 1 2 page 2 3 page 1 4 5 6 page 3 7 paging 04 05 06 Keep track of all free frames.Keep track of all free frames.(保留所有空闲帧的记录。)(保留所有空闲帧的记录。)To run a program of size n pages,need to find To run a program of size n pages,need to find n n free frames and load free frames and load program.program.(运行一个有(运行一个有N N页大小的程序,需要找到页大小的程序,需要找到N N个空的页框读个空的页框读入程序。)入程序。)Set up a page table to translate logical to physical addresses.Set up a page table to translate logical to physical addresses.(建立一个页表,把逻辑地址转换为物理地址。)(建立一个页表,把逻辑地址转换为物理地址。)paging 07 Internal fragmentation.Internal fragmentation.(内碎片。)(内碎片。)Paging Example page 0 page 1 page 2 page 3 logical memory page table 1 0 4 1 3 2 7 3 physical memory frame number 0 page 0 1 2 page 2 3 page 1 4 5 6 page 3 7 Address generated by CPU is divided intoAddress generated by CPU is divided into(CPUCPU产生的地址被分为)产生的地址被分为):1.1.Page number Page number(p p)(页号)(页号)used as an index into a page table which used as an index into a page table which contains base address of each page in physical memory.contains base address of each page in physical memory.(它包含每个(它包含每个页在物理内存中的基址,用来作为页表的索引。)页在物理内存中的基址,用来作为页表的索引。)2.2.Page offset Page offset(d d)(偏移)(偏移)combined with base address to define the combined with base address to define the physical memory address that is sent to the memory unit.physical memory address that is sent to the memory unit.(同基址相结(同基址相结合,用来确定送入内存设备的物理内存地址。)合,用来确定送入内存设备的物理内存地址。)Address Translation Scheme Address Translation Scheme Address generated by CPU is divided intoAddress generated by CPU is divided into(CPUCPU产生的地址被分为)产生的地址被分为):3.3.For given logical address space For given logical address space 2 2m m and page size 2and page size 2n n page numberpage number page offsetpage offset p p d d m m-n n n n Address Translation Scheme Address Translation Scheme Address Translation Architecture CPU p d f d f p f logical address physical address page table f00000000 f11111111 physical memory 特点 特点特点1 1 没有外碎片,每个内碎片 不超过页大小。特点特点2 2 一个程序不必连续存放。特点特点3 3 程序全部装入内存。纯分页的特点