ShanghaiTech CS130 | Lecture Note | Virtual Memory
说明:笔记旨在整理我校CS130课程的基本概念。由于授课及考试语言为英文,故用英文为主,中文为辅的方式整理。由于是整理,仅提供最低限度的解释,以便提供简洁快速的查阅。
全部笔记索引:【传送门】 | 上一节: Main Memory | 下一节: Storage Management
目录
ShanghaiTech CS130 | Lecture Note | Virtual Memory
2.1 Performance of demand paging(恐龙书10.2.3, PPT14)
2.2 Copy on write(恐龙书10.3, PPT16)
3 Page replacement algorithms(10.4.2+)
3.1 FIFO algorithm(恐龙书10.4.2, PPT 26)
3.3 Least-recently-used page replacement(10.4.4, PPT29)
3.4 LRU-Approximation Page Replacement(恐龙书10.4.5)
3.5 counting-based page replacement
4 Page-buffering algorithms(恐龙书10.4.7)
5 Allocation of frames(恐龙书10.5.1)
5.3 Priority allocatoin(PPT41)
5.4 Global vs. Local Allocation(PPT42)
6.1 Working-set Model(恐龙书10.6.2)
6.2 Page-Fault Frequency(10.6.3)
1 General Ideas
1.1 Motivation
(1)function: separate logical from physical memory / only PART of a program needs to be in memory / logical addr. space be much larger.
(2)implementation: virtual memory can be implemented via: paging / segmentation
1.2 Demand Paging (恐龙书10.2)
def: with demand-paged virtual memory, pages are loaded only when they are demanded during program execution.
properties: (1) first reference will trap to OS with a page fault. (2) OS looks at another table to decide: invalid reference - abort / just not in memory - bring to memory
1.3 swapper vs pager
swapper: swap a page into memory unless page will be needed(lazy) / manipulate entire processes
pagger: concern with the individual pages of a process
1.4 Valid-Invalid bit(10.2.1)
1.motivation: need HW support to distinguish whether page in memory or secondary storage.
2.semantics:
- valid -> associated page is both legal and in memory
- invalid -> page either is not valid (that is, not in logical address or not in logical addr. space of the process) or is valid but is currently in secondary page.
3.access invalid page will cause page fault, which brings desired page into memory or terminated when it is invalid indeed(not in addr. space).
- page fault occurs - trap ot OS (suspend process)
- check the validity of virtual memory address: if invalid reference: kill job; valid reference, page not in memory:continue
- bring into memory: find a free page frame / map address to disk block / fetch disk block into page frame / set validation bit to OK
- restart the instruction
4.pure demand paging(恐龙书p395): never bring a page into memory until it is required.
5.locality of reference: the fact that accessing serveral new pages of memory with each instruction executation is rare(which deteriorate the performance)
6.HW support of pagging and swapping:
- page table with valid bit
- secondary memory(aka swap space): hold page not in memory
2 Adanced analysis
2.1 Performance of demand paging(恐龙书10.2.3, PPT14)
1.page fault ratio: 0 <= p <= 1.0:
- If p = 0, no page fault
- If p = 1, every reference is a page fault
2.effective access time(EAT)
EAT=(1 - p) x memory access + p(page fault overhead + swap page out + swap page in)
2.2 Copy on write(恐龙书10.3, PPT16)
1.def: allow parent and child to share the same page. If either process writes to a share page, a copy of the shared pages is created.
2. allows more efficient creation: only modified pages are copied.
3. In general, free pages are allocated from a pool of zero-fill-on-demand page:
- pool should always have free frames
- zero-out a page before allocating