- 常规存储器段长特征
- 一次性
-
- 作业在允许前需要一次性的全部装入内存
- 驻留型
-
- 作业装入内存后,便一直驻留在内存中,直到作业结束
- Virtual memory: is a technique that allows the execution of processes that may not be completely in memory
- Principle of locality
- Only part of the program needs to be in memory for execution
- Logical address space can therefore be much larger than physical address space
- Need to allow pages to be swapped in and out
- 虚拟存储器的特征
- 离散性:最基本
- 多次性
- 对换性
-
- 作业在运行过程中信息在内存和外存的对换区之间换进、换出
- 虚拟性:从逻辑上扩充内存容量
- 页面调入策略
- Fetch policy
-
- Prepaging
-
- 主动的页面调入策略,即把那些预计很快会被访问内存的程序或数据所在的页面,预先调入内存
- 预测的准确率不高,主要用于进程的首次调入
- Demand paging: bring a page into memory only when it is needed
-
- Less I/O needed
- Less memory needed
- Faster response
- More users
- 页表机制
-
- 时在纯分页的页表机制上形成的
- 需要在页表中再增加若干项,供程序再换进、换出时参考
-
- P
-
- 指示该页是否已调入内存
- A
-
- 记录被访问次数
- M
-
- 表示该页在调入内存后是否被修改过
- 外存地址
- 缺页中断机构
-
- 每当所要访问的页面不在内存中时,便要产生一缺页中断,请求OS将所缺页调入内存
- 与一般中断区别
-
-
缺页中断在指令执行期间产生和处理中断信号,而一般中断在一条指令执行完后检查和处理中断信号。
-
缺页中断返回到该指令的开始重新执行该指令,而一般中断返回到该指令的下一条指令执行。
-
一条指令在执行期间,可能产生多次缺页中断。
-
- 当进程在运行中发生缺页时,由系统将缺页调入内存
- 大多数系统采取此策略
- 在调页时须花较大的系统开销,如需频繁启动磁盘I/O
- Performance
-
- Page Fault Rate 0 <= p <= 1.0
- if p = 0 no page faults (如果p = 0 ,没有缺页)
- if p = 1, every reference is a fault(每次访问都缺页)
- Effective Access Time (EAT)(有效存取时间)
-
EAT = (1 – p) x memory access + p(page fault overhead + [swap page ] + [restart overhead])
- Assignment policy
- 从何处调入页面
-
- 外存被分为两部分:文件区和对换区。对换区(连续分配)的磁盘I/O速度比文件区(离散分配)要高
- 从文件系统中调入页面
- 从交换区中调入页面
- Page replacement
- Find some page in memory, but not really in use, swap it out
- 如果没有空闲帧,需要两个页面传输,一个换出,一个换入
- Algorithms
-
- OPT: Replace page that will not be used for longest period of time
- FIFO
-
- Bleady异常现象
- LRU
-
- Counter implementation
-
- Every page entry has a counter
- Stack implementation
-
- Keep a stack of page numbers in a double link form
- LRU近似算法
-
- (1) Reference bit
-
- With each page associate a bit, initially = 0
- When a page is referenced page, bit set to 1
- Replace the one whose bit is 0, however, we do not know the order
- (2) Second chance
-
- Need a reference bit
- Clock replacement
- (3) Enhanced second chance
-
- 不仅要考虑页面的使用情况,还要考虑置换代价,选择淘汰页面时,既要是未被访问的,还要是未被修改的页面
- 实现
-
- 设置两位
-
- 访问位A,修改位M
- 启动一个进程时,A、M置0
- A被定期置零
- 步骤
-
- OS首先寻找第0类页面,将找到的第一个页面淘汰;
- 若没找到,则找第1类页面,将找到的第一个页面淘汰,并将扫描过的页面的A位全部置为0;
- 若没找到,则指针回到开始位置,将所有的A位置为0。然后重复第一步。
- Counting algorithms
-
- LFU
-
- Replaces page with smallest count
- MFU
-
- Based on the argument that the page with the smallest count was probably just brought in and has yet to be used
- Allocation of frames
- Each process needs minimum number of pages
-
- 保证进程正常运行所需的最小物理块数
- Major allocation schemes
-
- Fixed allocation
-
- Equal allocation
- Proportional allocation
- Priority allocation
- Global allocation & Local allocation
-
- Global replacement
-
- Selects a replacement frame from the set of all frames
- Local replacement
-
- Selects from only its own set of allocated frame
- 局部置换时,分配给每个进程的帧数量不变
- 全局置换时,进程的帧数量会增加,但是无法控制页错误率
- 相对而言,全局替换会带来较高的系统吞吐率
- Thrashing
- 刚被换出的页很快又被访问,需重新调入,导致系统频繁地交换页面,以致大部分CPU时间花费在完成页面置换的工作上
- 局部置换能限制系统颠簸,但也会增加进程的有效访问时间
- Solution
-
- ∑ size of locality < total memory size
- Working set
- 基本思想
-
- 根据程序的局部性原理
- 如果为进程提供与活跃页面数相等的物理块数,则可减少缺页中断次数
Chapter 10 Virtual Memory
最新推荐文章于 2024-04-22 20:26:57 发布