博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OS Review Chapter 10: Virtual Memory
阅读量:3948 次
发布时间:2019-05-24

本文共 3671 字,大约阅读时间需要 12 分钟。

Chapter 10: Virtual Memory

Virtual memory can be implemented via:

  • Demand paging 请求分页 更加简单,不需要考虑外部碎片
  • Demand segmentation 请求分段

在这里插入图片描述

Demand Paging

Bring a page into memory only when it is needed

invalid reference -->abort

not-in-memory -->bring to memory

  • Less I/O needed
  • Less memory needed
  • Faster response
  • More users

Pure demand paging–never bring a page into memory unless page will be needed

Valid-Invalid Bit

With each page table entry a valid–invalid bit is associated

(1 --> in-memory, 0–> not-in-memory)

Page Fault

trap to OS

OS looks at another table to decide:

  • Invalid reference -->abort. Just not in memory.
  • Just not in memory.

在这里插入图片描述

在这里插入图片描述

Performance of Demand Paging

Effective Access Time (EAT) =(1 –p) x memory access + p(page fault overhead + [swap page out ] + swap page in + restart overhead)

Copy-on-Write

Copy-on-Write (COW) allows both parent and child processes to initially share the same pages in memory.

If either process modifies (修改) a shared page, only then is the page copied

Page Replacement

  1. Find the location of the desired page on disk.
  2. Find a free frame: -If there is a free frame, use it. -If there is no free frame, use a page replacement algorithm to select a victim frame.
  3. Read the desired page into the (newly) free frame. Update the page and frame tables.
  4. Restart the instruction.

First-In-First-Out (FIFO) Algorithm

FIFO Replacement –Belady’s Anomaly

more frames --> less page faults

在这里插入图片描述

Optimal Page Replacement 最优算法

Replace page that will not be used for longest period of time.

**Used for measuring how well your algorithm performs.**最优算法,主要是作为度量

在这里插入图片描述

Least Recently Used (LRU) Algorithm

Counter implementation :

Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter.

When a page needs to be changed, look at the counters to determine which are to change.

缺点:开销太大

LRU Algorithm

Stack implementation –keep a stack of page numbers in a double link form

LRU Approximation Algorithms LRU近似算法

Additional-Reference-Bits Algorithm

Second chance

Counting Algorithms

Keep a counter of the number of references that have been made to each page

LFU(least frequently used) Algorithm: replaces page with smallest count.

MFU(most frequent used) Algorithm: 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

Two major allocation schemes.

  • fixed allocation
  • priority allocation

Global replacement –process selects a replacement frame from the set of all frames; one process can take a frame from another.

Local replacement –each process selects from only its own set of allocated frames.

两周置换各有利弊,分析应用场合

Thrashing

抖动 颠簸

If a process does not have “enough” pages, the page-fault rate is very high. This leads to:

  • low CPU utilization.
  • operating system thinks that it needs to increase the degree of multiprogramming
  • another process added to the system.

Thrashing=a process is busy swapping pages in and out

Locality model

Process migrates from one locality to another.

Localities may overlap

Why does thrashing occur? Σsize of locality > total memory size

Working-Set Model

在这里插入图片描述

Keeping Track of the Working Set

Allocating Kernel Memory

Buddy System

在这里插入图片描述

Slab Allocator

在这里插入图片描述

Other Considerations

Prepaging

  • To reduce the large number of page faults that occurs at process startup
  • Prepage all or some of the pages a process will need, before they are referenced
  • But if prepaged pages are unused, I/O and memory was wasted
  • Assume s pages are prepaged and αof the pages is used

Page Size

  • fragmentation 小了好,考虑内部碎片,平均大小是1/2 page size
  • table size 大了好
  • I/O overhead 大
  • locality

TLB Reach

Program Structure

在这里插入图片描述

I/O interlock

Pages must sometimes be locked into memory

在这里插入图片描述

转载地址:http://umgwi.baihongyu.com/

你可能感兴趣的文章
iOS--Masonry解决 tableViewCell 重用时约束冲突
查看>>
git 与 svn 的主要区别!
查看>>
iOS-截屏,从相册选择图片,制作磨砂效果图片
查看>>
iOS-截取字符串中两个指定字符串中间的字符串
查看>>
数据库-数据库操作(使用FMDB)
查看>>
swift-计算型属性和存储型属性的区别
查看>>
FMDB介绍以及在 swift 中的数据库操作
查看>>
iOS运行时机制(附Demo演练)
查看>>
iOS-利用运行时给分类添加属性
查看>>
整理的最新WebSHell (php过狗一句话,过狗菜刀,2016过狗一句话,2016php免杀一句话)
查看>>
2016年11月整理的最新php免杀一句话木马, 2017php免杀一句话(php过狗一句话,过狗菜刀,2016过狗一句话,2016php免杀一句话,php过waf一句话)
查看>>
坑:ADO连数据库服务器地址要加端口号
查看>>
宽字符串输出问题
查看>>
将整数转换为宽字符串
查看>>
在类中定义enum实现整数常量功能
查看>>
VS2008下编译MFC报平台版本低解决办法
查看>>
VS2008中新增对话框的初始化函数是虚函数,需要时重写
查看>>
如何在遍历中使用list的删除函数
查看>>
wstring需要显示初始化
查看>>
vs2008下CString和wstring间的转换
查看>>