操作系统 内存管理

将地址与指令、数据绑定的时期:

1Compile time

2Load time

3Execution time


逻辑地址  、物理地址:

 Logical address – generated by the CPU; also referred to as virtual address
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)

1Hardware device that maps virtual to physical address 
2In 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
3The user program deals with logicaladdresses; it never sees the realphysical addresses

动态重新定位



动态加载

1 Routine is not loaded until it is called
2 Better memory-space utilization; unused routine is never loaded
3 Useful when large amounts of code are needed to handle infrequently occurring cases

动态链接Dynamic Linking

1Linking postponed until execution time
2 Small piece of code, stub, used to locate the appropriate memory-resident library routine
3 Stub replaces itself with the address of the routine, and executes the routine
4 Operating system needed to check if routine is in processes’ memory address
5 Dynamic linking is particularly useful for libraries
6 System also known as shared libraries


交换Swapping

 A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution

 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


内存管理策略:

1大小不等的固定分区 连续分配 Contiguous Allocation

1Main memory usually into two partitions:
 Resident operating system, usually held in low memory with interrupt vector
 User processes then held in high memory
2. Relocation registers used to protect user processes from each other, and from changing operating-system code and data


 Base register contains value of smallest physical address  基址寄存器 保存物理地址
 Limit register contains range of logical addresses – each logical address must be less than the limit register 限制寄存器 保存进程的最大可能长度
 MMU maps logical address dynamically   MMU 动态将逻辑地址映射成物理地址


缺陷:Hole – block of available memory; holes of various size are scattered throughout memory


2大小可变的分区Dynamic Storage-Allocation Problem

分配策略:

1First-fit: Allocate the first hole that is big enough
2.Best-fit: Allocate the smallesthole that is big enough; must search entire list, unless ordered by size Produces the smallest leftover hole
3.Worst-fit: Allocate the largesthole; must also search entire list Produces the largest leftover hole


碎片类型:

External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used


3分页管理

大小不等的固定分区和大小可变的分区效率低下,会产生内部或外部碎片。若将主存划分为固定大小块,并且块较小,每个进程也被分为同样大小的小块,可以将进程的块(称为页)指定到内存中的可用块(称为帧或页帧),最后一页可能形成内部碎片,没有外部碎片。

1Set up a page table to translate logical to physical addresses
2 Internal fragmentation

Page number (p) – used as an index into a page table which contains base address of each page in physical memory
Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit




提高效率:

Associative Memory

 If p is in associative register, get frame # out  Otherwise get frame # from page table in memory



Hit ratio = a

 Effective Access Time (EAT)
EAT = (1 + $) a + (2 + $)(1 – a)
= 2 + $ – a


保护内存Memory Protection

 Memory protection implemented by associating protection bit with each frame
 Valid-invalid bit attached to each entry in the page table:
l “valid” indicates that the associated page is in the process’ logical address space, and is thus a legal page
l “invalid” indicates that the page is not in the process’ logical address space




分页管理-页表结构

 Hierarchical Paging

 A logical address (on 32-bit machine with 1K page size) is divided into:
 a page number consisting of 22 bits
 a page offset consisting of 10 bits
 Since the page table is paged, the page number is further divided into:
 a 12-bit page number
 a 10-bit page offset

 Hashed Page Tables


 Inverted Page Tables




提高利用率Shared Pages

1Shared code

2Private code and data



4分段管理

 程序和相关的数据被划分成一组段(segment)。
 分段技术的逻辑地址由两部分组成:段号和偏移量。
 由于使用大小不等的段,分段类似于动态分区。与动态分区不同的是,在分段方案中,一个程序可以占据多个分区,并且这些分区不要求是连续的。
 分段消除了内部碎片,但是和动态分区一样,会产生很多外部碎片。
 由于进程被分为许多小块,外部碎片较小。




5分段与分页管理  分页 :存储空间需要连续,内部碎片,分段:存储空间不需要连续,外部碎片

用户的地址空间被程序员划分为多个段,段由大小相同的若干页构成,页面有页内地址。
段页式管理系统的地址结构为(S,P,d),其中S为段号,P为段内页号,d为页内偏移量。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值