操作系统 ShanghaiTech CS130 | Virtual Memory

ShanghaiTech CS130 | Lecture Note | Virtual Memory

说明:笔记旨在整理我校CS130课程的基本概念。由于授课及考试语言为英文,故用英文为主,中文为辅的方式整理。由于是整理,仅提供最低限度的解释,以便提供简洁快速的查阅。

全部笔记索引:【传送门】 | 上一节: Main Memory | 下一节: Storage Management

目录

ShanghaiTech CS130 | Lecture Note | Virtual Memory

1 General Ideas

1.1 Motivation

1.2 Demand Paging (恐龙书10.2)

1.3 swapper vs pager

1.4 Valid-Invalid bit(10.2.1)

2 Adanced analysis

2.1 Performance of demand paging(恐龙书10.2.3, PPT14)

2.2 Copy on write(恐龙书10.3, PPT16)

2.3 Page replacement(恐龙书10.4)

3 Page replacement algorithms(10.4.2+)

3.1 FIFO algorithm(恐龙书10.4.2, PPT 26)

3.2 Optimal Algoirhtm(10.4.3)

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.1 Equal allocation(10.5.2)

5.2 Proportional allocation

5.3 Priority allocatoin(PPT41)

5.4 Global vs. Local Allocation(PPT42)

6 Thrashing(恐龙书10.6)

6.1 Working-set Model(恐龙书10.6.2)

6.2 Page-Fault Frequency(10.6.3)

6.3 Demand paging issues

Q&A

Reference


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).

  1. page fault occurs - trap ot OS (suspend process)
  2. check the validity of virtual memory address: if invalid reference: kill job; valid reference, page not in memory:continue
  3. bring into memory: find a free page frame / map address to disk block / fetch disk block into page frame / set validation bit to OK
  4. 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:

  1. page table with valid bit
  2. 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值