Module 9: Memory Management Background(背景) ° Logical versus Physical Address Space(逻辑与物理地址空间) ° Swapping(交换) ° Contiguous Allocation(连续分配) Paging(分页) ° Segmentation(分段) ° Segmentation with Paging(段页式) Applied Operating System Concepts 9.1 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.1 Module 9: Memory Management • Background(背景) • Logical versus Physical Address Space(逻辑与物理地址空间) • Swapping (交换) • Contiguous Allocation(连续分配) • Paging(分页) • Segmentation(分段) • Segmentation with Paging(段页式)
Background Program must be brought into memory and placed within a process for it to be executed.(程序必需放入一个进程,并且送 入内存才能被执行) e Input queue- collection of processes on the disk that are waiting to be brought into memory for execution.(输入队列 磁盘上等待进入内存并执行的进程的集合) User programs go through several steps before being executed.(用户程序在执行之前必需经历很多步骤) Applied Operating System Concepts 9.2 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.2 Background • Program must be brought into memory and placed within a process for it to be executed.(程序必需放入一个进程,并且送 入内存才能被执行) • Input queue – collection of processes on the disk that are waiting to be brought into memory for execution.(输入队列 — 磁盘上等待进入内存并执行的进程的集合) • User programs go through several steps before being executed. (用户程序在执行之前必需经历很多步骤)
Binding of Instructions and Data to Memory Address binding of instructions and data to memory addresses can happen at three different stages.(指令和数据结合到内存地址可以在三 个不同的阶段发生。) Compile 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 its execution from one memory segment to another Need hardware support for address maps (e.g, base and limit registers) .(如果进程在执行时可以在内存中移 动,则地址绑定要延迟到运行时。需要硬件对地址映射的支持,例如基 址和限长寄存器) Applied Operating System Concepts 3 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.3 Binding of Instructions and Data to Memory • Compile 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 its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers). (如果进程在执行时可以在内存中移 动,则地址绑定要延迟到运行时。需要硬件对地址映射的支持,例如基 址和限长寄存器) Address binding of instructions and data to memory addresses can happen at three different stages.(指令和数据结合到内存地址可以在三 个不同的阶段发生。)
Dynamic Loading Routine is not loaded until it is called.(例程在调用之前并不执行) Better memory-space utilization; unused routine is never loaded. 更好的内存空间利用率;没有被使用的例程不被载入。) Useful when large amounts of code are needed to handle infrequently occurring cases.(当需要大量的代码来处理不经常发生的 事情时是非常有用的。) No special support from the operating system is required implemented through program design.(不需要操作系统的特别支持, 通过程序设计实现) Applied Operating System Concepts 94 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.4 Dynamic Loading • Routine is not loaded until it is called.(例程在调用之前并不执行) • Better memory-space utilization; unused routine is never loaded.( 更好的内存空间利用率;没有被使用的例程不被载入。) • Useful when large amounts of code are needed to handle infrequently occurring cases.(当需要大量的代码来处理不经常发生的 事情时是非常有用的。) • No special support from the operating system is required implemented through program design.(不需要操作系统的特别支持, 通过程序设计实现)
Dynamic Linking Linking postponed until execution time.(链接被推迟到执行时期) Small piece of code, stub, used to locate the appropriate memory resident library routine.(小的代码片-存根,用来定位合适的保留在 内存中的库程序。) Stub replaces itself with the address of the routine, and executes the routine.(存根用例程地址来替换自己,以及执行例程。) Operating system needed to check if routine is in processes memory address.(操作系统需要检查例程是否在进程的内存空间) Applied Operating System Concepts 95 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.5 Dynamic Linking • Linking postponed until execution time.(链接被推迟到执行时期) • Small piece of code, stub, used to locate the appropriate memoryresident library routine.(小的代码片- 存根,用来定位合适的保留在 内存中的库程序。) • Stub replaces itself with the address of the routine, and executes the routine.(存根用例程地址来替换自己,以及执行例程。) • Operating system needed to check if routine is in processes’ memory address.(操作系统需要检查例程是否在进程的内存空间)
Overlays e Keep in memory only those instructions and data that are needed at any given time.(只是在内存中保留那些在特定时间 所需要的指令和数据) Needed when process is larger than amount of memory alllocated to it.(当进程比所分配的内存大时,覆盖是必需的) Implemented by user, no special support needed from operating system, programming design of overlay structure is complex.(由用户执行,不需要操作系统的特别支持,覆盖结 构的程序设计很复杂。) Applied Operating System Concepts 96 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.6 Overlays • Keep in memory only those instructions and data that 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 operating system, programming design of overlay structure is complex.(由用户执行,不需要操作系统的特别支持,覆盖结 构的程序设计很复杂。)
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 address- generated by the CPU; also referred to as virtual address.(逻辑地址一由cPU产生;也叫做虚拟空间 Physical address- address seen by the memory unit. (4 理地址一内存设备所读入的地址) Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme.(逻辑和物理地址在编译时期和装入时期的地址绑定策略是 相同的,而在执行时间的地址绑定策略是不同的。) Applied Operating System Concepts 97 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.7 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 address – generated by the CPU; also referred to as virtual address.(逻辑地址—由CPU产生;也叫做虚拟空间 。) – Physical address – address seen by the memory unit.(物 理地址—内存设备所读入的地址) • Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme.(逻辑和物理地址在编译时期和装入时期的地址绑定策略是 相同的,而在执行时间的地址绑定策略是不同的。)
Memory-Management Unit MMU) ° Hardware device that maps virtual to physical address..(硬件 把虚拟地址映射到物理地址) In MMUscheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory.(在MMU策略中,基址寄存器中的值在其送入内 存的时候被加入到由一个用户进程所产生的每个地址中。) The user program deals with logical addresses; it never sees the real/ physical addresses.(用户程序所对应到的是逻辑地址 物理地址对它从来都不可见。) Applied Operating System Concepts 98 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.8 Memory-Management Unit (MMU) • Hardware device that maps virtual to physical address.(硬件 把虚拟地址映射到物理地址) • In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory.(在MMU策略中,基址寄存器中的值在其送入内 存的时候被加入到由一个用户进程所产生的每个地址中。) • The user program deals with logical addresses; it never sees the real physical addresses.(用户程序所对应到的是逻辑地址 ,物理地址对它从来都不可见。)
Swapping A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution.(一个进程可以暂时被交换到内存外的一个 备份区,随后可以被换回内存继续执行。) e Backing store -fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images.(备份区一是一个固定 的足够大的可以容纳所有用户内存映像的拷贝;对于可以让这些内 存映像直接存取。) Applied Operating System Concepts 9 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.9 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 for all users; must provide direct access to these memory images.(备份区—是一个固定 的足够大的可以容纳所有用户内存映像的拷贝;对于可以让这些内 存映像直接存取。)
Swapping 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.(滚入,滚出 交换由于基于优先级的算法而不同,低优先级的进程被换出, 这样高优先级的进程可以被装入和执行。) Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped.(交换时 间的主要部分是转移时间,总的转移时间直接同交换的内存的数一 量成比例。) Modified versions of swapping are found on many systems, 1. e, UNIX and Microsoft windows.(在许多系统如:UNIX Windows中,可以找到一些被修正过的交换措施。) Applied Operating System Concepts 9.10 Silberschatz, Galvin, and Gagne @1999
Silberschatz, Galvin, and Gagne ©1999 Applied Operating System Concepts 9.10 Swapping 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.(滚入,滚出 —交换由于基于优先级的算法而不同,低优先级的进程被换出, 这样高优先级的进程可以被装入和执行。) Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped.(交换时 间的主要部分是转移时间,总的转移时间直接同交换的内存的数 量成比例。) Modified versions of swapping are found on many systems, i.e., UNIX and Microsoft Windows.(在许多系统如:UNIX, Windows中,可以找到一些被修正过的交换措施。)