Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Advertisements

Chapter 4 Memory Management Basic memory management Swapping
Virtual Memory (Chapter 4.3)
Chapter 3.3 : OS Policies for Virtual Memory
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Module 10: Virtual Memory
Chapter 3 Memory Management
Chapter 10: Virtual Memory
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Chapter 9: Virtual Memory
Memory Management.
Page Replacement Algorithms
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Virtual Memory Management G. Anuradha Ref:- Galvin.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
1 Memory Management Managing memory hierarchies. 2 Memory Management Ideally programmers want memory that is –large –fast –non volatile –transparent Memory.
Memory Management Design & Implementation Segmentation Chapter 4.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
1 Pertemuan 16 Isu-Isu pada Sistem Paging dan Segmentasi Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Introduction to Systems Programming Lecture 7
Memory Management Virtual Memory Page replacement algorithms
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p
Memory Management From Chapter 4, Modern Operating Systems, Andrew S. Tanenbaum.
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
“ Memory Management Function ” Presented By Lect. Rimple Bala GPC,Amritsar 1.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
操作系统原理 OPERATING SYSTEM Chapter 3 Memory Management 内存管理.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 9: Virtual-Memory Management 9.1 Background.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
1 Memory Management Chapter Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
1 Memory Management Adapted From Modern Operating Systems, Andrew S. Tanenbaum.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Memory Management Chapter 3
Memory Management Paging (continued) Segmentation
Chapter 9: Virtual Memory – Part I
Operating Systems Virtual Memory Alok Kumar Jagadev.
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Chapter 9: Virtual-Memory Management
Page Replacement.
Memory Management Paging (continued) Segmentation
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Chapter 4: Memory Management
Memory Management Paging (continued) Segmentation
Module 9: Virtual Memory
Virtual Memory.
Presentation transcript:

Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?

Thrashing If a process does not have “enough” pages, the page-fault rate is very high. This leads to: low CPU utilization OS scheduler thinks that it needs to increase the degree of multiprogramming  new processes are added  even less pages for each process … Thrashing  a process is busy swapping pages in and out  Spending more time paging than executing.

Transfer of a Paged Memory to Contiguous Disk Space Demand Paging Demand paging: pages are only loaded into memory when they are demanded during execution Less I/O needed Less memory needed Higher degree of multiprogramming Faster response Pager (lazy swapper) never swaps a page into memory unless that page will be needed. An extreme case: Pure demand paging starts a process with no pages in memory … Transfer of a Paged Memory to Contiguous Disk Space

Page Replacement Algorithms Page fault forces choice which page must be removed make room for incoming page Modified page must first be saved unmodified just over written Better not to choose an often used page will probably need to be brought back in soon 页面淘汰算法的好坏直接决定了系统的性能。

Page Replacement Algorithms Random page replacement Optimal page replacement algorithm Not recently used page replacement First-In, First-Out page replacement Second chance page replacement Clock page replacement Least recently used page replacement Working set page replacement WSClock page replacement Random page replacement Choose a page randomly 随机 最优 最近未使用 FIFO 第二次机会 时钟 最近最少使用 工作集 工作集时钟 每次页面失效时,尽管可以随机选择一个页面淘汰,但是选择不常使用的页面会使系统性能提升,反之 ,如果一个经常使用的页面被淘汰,很有可能很快又被调入,引起不必要的开销。

Optimal Page Replacement Algorithm Replace page needed at the farthest point in future Optimal but unrealizable Estimate by … logging page use on previous runs of process although this is impractical

Optimal Example 12 references, 7 faults

Not Recently Used Page Replacement Algorithm(NRU) Each page has Reference bit, Modified bit bits are set when page is referenced, modified Pages are classified not referenced, not modified not referenced, modified referenced, not modified referenced, modified NRU removes page at random from lowest numbered non empty class

FIFO Page Replacement Algorithm Maintain a linked list of all pages in order they came into memory Page at beginning of list replaced Disadvantage page in memory the longest may be often used

FIFO 12 references, 9 faults

Belady's Anomaly (for FIFO) Same reference string as with 3 frames (9 page faults). 12 references, 10 faults Belady’s Anomaly for FIFO: (Sometimes) as the number of page frames increase, so does the fault rate.

Second Chance Algorithm Operation of second chance. (a) Pages sorted in FIFO order. (b) Page list if a page fault occurs at time 20 and A has its R bit set. The numbers above the pages are their load times.

Second Chance Example 12 references, 9 faults

The Clock Page Replacement Algorithm

Least Recently Used (LRU) Assume pages used recently will used again soon throw out page that has been unused for longest time Must keep a linked list of pages most recently used at front, least at rear update this list every memory reference !! Alternatively keep counter in each page table entry choose page with lowest value counter periodically zero the counter

LRU Page Replacement Algorithm LRU using a matrix when pages are referenced in the order 0, 1, 2, 3, 2, 1, 0, 3, 2, 3.

Simulating LRU in Software NFU Aging The aging algorithm simulates LRU in software. Shown are six pages for five clock ticks. The five clock ticks are represented by (a) to (e).

LRU and Anomalies Anomalies cannot occur. 12 references, 8 faults

Working Set Page Replacement (1) 一个进程当前正在使用的页面的集合,称为工作集。如果在内存中装入的是整个工作集,进程的运行在进入下一运行阶段之前,则不会产生很多页面失效。 工作集页面置换算法:在单纯的分页系统里,刚启动进程时,在内存中没有页面。在CPU试图取第一条指令时就会产生一次页面失效,使操作系统装入含有第一条指令的页面。其他由访问全局数据和堆栈引起的页面失效通常会紧接着发生。一段时间后,进程需要的大部分页面都已经在内存了,进程开始在较少页面失效的情况下运行。这个策略称为请求式分页,因为页面是在需要时调入,而不是预先装入。 程序的局部性:即在进程运行的任何阶段,它都指访问较少的一部分页面。 工作集是最近k次内存访问所用过页面的集合。 The working set is the set of pages used by the k most recent memory references. The function w(k, t) is the size of the working set at time t.

Working Set Page Replacement (2) 基于工作集的页面置换算法 The working set algorithm.

The WSClock Page Replacement Algorithm (1) When the hand comes all the way around to its starting point there are two cases to consider: At least one write has been scheduled. No writes have been scheduled. 工作集时钟页面置换算法:当页面发生失效后,在确定被淘汰的页面之前,基本工作集算法需要扫描整个工作集内页面。 工作集时钟算法:基于时钟算法,并且收集了工作集信息。 与时钟算法一样,每次页面失效时,首先检查指针指向的页面。如果R位被置为1,该页面在当前时钟滴答中被使用过,那么该页面就不适合被淘汰。然后把该页面的R位置为0,指针指向下一个页面,并重复该算法。该时间序列之后的状态可以见下图。

The WSClock Page Replacement Algorithm (2) Operation of the WSClock algorithm. (a) and (b) give an example of what happens when R = 1.

The WSClock Page Replacement Algorithm (3) Operation of the WSClock algorithm. (c) and (d) give an example of R = 0.

Summary of Page Replacement Algorithms Page replacement algorithms discussed in the text.

Local versus Global Allocation Policies (1) Figure 3-23. Local versus global page replacement. (a) Original configuration. (b) Local page replacement. (c) Global page replacement.

Local versus Global Allocation Policies (2) Page fault rate as a function of the number of page frames assigned.

Modeling Page Replacement Algorithms Belady's Anomaly FIFO with 3 page frames FIFO with 4 page frames P's show which page references show page faults

Stack Algorithms State of memory array, M, after each item in reference string is processed

Original configuration Local page replacement Global page replacement Design Issues for Paging Systems Local versus Global Allocation Policies (1) Original configuration Local page replacement Global page replacement

Local versus Global Allocation Policies (2) Page fault rate as a function of the number of page frames assigned

Load Control Despite good designs, system may still thrash When some processes need more memory but no processes need less Solution : Reduce number of processes competing for memory swap one or more to disk, divide up pages they held reconsider degree of multiprogramming

Page Size (1) Small page size Advantages less internal fragmentation better fit for various data structures, code sections less unused program in memory Disadvantages programs need many pages, larger page tables

Page Size (2) Overhead due to page table and internal fragmentation Where s = average process size in bytes p = page size in bytes e = page entry page table space internal fragmentation 从数学上分析的结论,最优页面大小的公式。 Optimized when

Separate Instruction and Data Spaces 大多数计算机只有一个地址空间,既存放程序也存放数据,如果地址空间足够大还不会有什么问题。然而通常地址空间太小了,这就使得程序员对地址空间的使用出现困难。 为指令和数据设置分离的地址空间。I空间和D空间两种地址空间都可以分页,相互独立。他们分别有自己的页表,完成虚拟页面到物理页帧的映射。 One address space Separate I and D spaces

Two processes sharing same program sharing its page table Shared Pages 页面共享:避免同时在内存中有相同的页面。 Two processes sharing same program sharing its page table

Implementation Issues Operating System Involvement with Paging Four times when OS involved with paging Process creation determine program size create page table Process execution MMU reset for new process TLB flushed Page fault time determine virtual address causing fault swap target page out, needed page in Process termination time release page table, pages

Page Fault Handling (1) Hardware traps to kernel General registers saved OS determines which virtual page needed OS checks validity of address, seeks page frame If selected frame is dirty, write it to disk

Page Fault Handling (2) OS brings schedules new page in from disk Page tables updated Faulting instruction backed up to when it began Faulting process scheduled Registers restored Program continues

An instruction causing a page fault Instruction Backup An instruction causing a page fault

Locking Pages in Memory Virtual memory and I/O occasionally interact Proc issues call for read from device into buffer while waiting for I/O, another processes starts up has a page fault buffer for the first proc may be chosen to be paged out Need to specify some pages locked exempted from being target pages

Backing Store (a) Paging to static swap area (b) Backing up pages dynamically

Separation of Policy and Mechanism Page fault handling with an external pager

作业 P 139 页 12, 22, 24,26, 27, 28