Chapter 21 Beyond Physical Memory: Mechanisms
第 21 章 超越物理内存:机制
目前为止,我们一直假定地址空间非常小...能放入物理内存...
事实上,假设每个正在运行的进程的地址空间都能放入内存...这些轻松的假设...并不成立...
内存层级
memory hierachy 加一层...
1. 交换空间
要做的第一件事情:在 硬盘 上开辟一部分空间用于物理页的移入和移出...
在操作系统中,一般这样的空间称为交换空间(swap space...)
1.1. 大小
现在假设它很大,这很重要...
1.2. 注意
交换空间不是唯一的硬盘交换目的地...
2. 存在位
我们需要增加高级机制来支持硬盘交换页
2.1. 内存引用发生了什么
正在运行的进程生成虚拟内存引用
硬件将其转换为物理地址
从内存中获取所需数据
2.2. 细看
the hardware first extracts the VPN from the virtual address
checks the TLB for a match (a TLB hit)
if a hit, produces the resulting physical address and fetches it from memory
else if miss, the hardware locates the page table in memory (using the page table base register) and looks up the page table entry (PTE) for this page using the VPN as an index.
3. 页错误
在 TLB 未命中情况下...有两种类型:
硬件管理的 TLB
软件管理的 TLB
无论在哪种情况,如果也不存在,都由 OS 来负责处理也错误。即使是硬件处理的 TLB 硬件也信任操作系统来管理这个重要的任务。
4. 内存满了怎么办
我们之前假设内存无限大...但是情况并非如此
操作系统可能希望先 page out 一个或多个也,以便将 page in 的新页留出空间...
称为页交换策略
page-replacement policy
4.1. 注意
这样的机制还需要讨论
如果page out的是不合适的页,会运行更慢......
我们要知道有没有这样的策略存在...
5. 页错误处理流程
5.1. TLB miss
First, that the page was both present and valid (Lines 18–21); in this case, the TLB miss handler can simply grab the PFN from the PTE, retry the instruction (this time resulting in a TLB hit), and thus continue as described (many times) before.
In the second case (Lines 22–23), the page fault handler must be run; although this was a legitimate page for the process to access (it is valid, after all), it is not present in physical memory.
Third (and finally), the access could be to an invalid page, due for example to a bug in the program (Lines 13–14). In this case, no other bits in the PTE really matter; the hardware traps this invalid access, and the OS trap handler runs, likely terminating the offending process.
6. 交换何时真正发生
6.1. 并不是这样
我们说内存满了或快满了才会 page out ...但是不是
操作系统会主动预留一小部分空闲内存...
6.2. 水位线
大多数 OS 会预设 高水位线 High Watermark...HW 或 Low Watermark...LW
后台进程有时称为交换守护进程 swap daemon 或 页守护进程 page daemon
Last updated