CS 3204 Operating Systems Godmar Back Lecture 21.

Slides:



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

4.4 Page replacement algorithms
Chapter 11 – Virtual Memory Management
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory 3 Fred Kuhns
Chapter 11 – Virtual Memory Management
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Virtual Memory (II) CSCI 444/544 Operating Systems Fall 2008.
Virtual Memory: Page Replacement
Paging: Design Issues. Readings r Silbershatz et al: ,
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 36 Virtual Memory Read.
1 CSC 539: Operating Systems Structure and Design Spring 2005 Virtual memory  background  demand paging  page replacement: FIFO, OPT, LRU  allocation.
Virtual Memory. 2 What is virtual memory? Each process has illusion of large address space –2 32 for 32-bit addressing However, physical memory is much.
Virtual Memory.
Chapter 101 Cleaning Policy When should a modified page be written out to disk?  Demand cleaning write page out only when its frame has been selected.
CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War.
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)
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management – 4 Page Replacement Algorithms CS 342 – Operating Systems.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Paging Design.
Introduction to Systems Programming Lecture 7
Memory Management Virtual Memory Page replacement algorithms
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS444/CS544 Operating Systems Virtual Memory 4/06/2007 Prof. Searleman
CS 333 Introduction to Operating Systems Class 14 – Page Replacement Jonathan Walpole Computer Science Portland State University.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Page Replacement Algorithms
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement Jonathan Walpole Computer Science Portland State University.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Virtual Memory.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
Copyright ©: Lawrence Angrave, Vikram Adve, Caccamo 1 Virtual Memory.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
Lecture 11 Page 1 CS 111 Online Working Sets Give each running process an allocation of page frames matched to its needs How do we know what its needs.
Lecture 11 Page 1 CS 111 Online Virtual Memory A generalization of what demand paging allows A form of memory where the system provides a useful abstraction.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Virtual Memory Questions answered in this lecture: How to run process when not enough physical memory? When should a page be moved from disk to memory?
Page Buffering, I. Pages to be replaced are kept in main memory for a while to guard against poorly performing replacement algorithms such as FIFO Two.
CSE 153 Design of Operating Systems Winter 2015 Lecture 12: Page Replacement.
NETW3005 Virtual Memory. Reading For this lecture, you should have read Chapter 9 (Sections 1-7). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory2.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
1 Page Replacement Algorithms. 2 Virtual Memory Management Fundamental issues : A Recap Key concept: Demand paging  Load pages into memory only when.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Virtual Memory. 2 Last Week Memory Management Increase degree of multiprogramming –Entire process needs to fit into memory Dynamic Linking and Loading.
Virtual Memory Operating Systems 1 Computer Science Dept Va Tech August 2007 © McQuain Page Buffering LRU and the Clock Algorithm are generally.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Chapter 9: Virtual Memory – Part II
CENG334 Introduction to Operating Systems
Chapter 9: Virtual Memory – Part I
Chapter 21 Virtual Memoey: Policies
Day 23 Virtual Memory.
Day 24 Virtual Memory.
Memory Management and Virtual Memory - 2
CS703 - Advanced Operating Systems
CSE 120 Principles of Operating
O.S Lecture 13 Virtual Memory.
Chapter 9: Virtual-Memory Management
CSC 539: Operating Systems Structure and Design Spring 2006
Operating Systems CMPSC 473
Virtual Memory: Working Sets
CS 3204 Operating Systems Lecture 19 Godmar Back.
Virtual Memory – Page Replacement
CSE 153 Design of Operating Systems Winter 19
Virtual Memory – Page Replacement
Presentation transcript:

CS 3204 Operating Systems Godmar Back Lecture 21

12/6/2015CS 3204 Spring Announcements Project 3 due Apr 11

VM Design Issues & Techniques

12/6/2015CS 3204 Spring # of Page Faults vs Frame Allocation Desired behavior of paging algorithm: reduce page fault rate below “acceptable level” as number of available frames increases Q.: does increasing number of physical frames always reduce page fault rate? –A.: usually yes, but for some algorithms not guaranteed (“Belady’s anomaly”)

12/6/2015CS 3204 Spring Page Buffering Select victim (as dictated by page replacement algorithm – works as an add-on to any algorithm we discussed) But don’t evict victim – put victim on tail of victim queue. Evict head of that queue instead. If victim page is touched before it moves to head of victim queue, simply reuse frame Further improvement: keep queue of unmodified victims (for quick eviction – aka free page list) and separate queue of modified pages (aka modified list - allows write- back in batch) Related issue: when should you write modified pages to disk? –Options: demand cleaning vs pre-cleaning (or pre-flushing)

12/6/2015CS 3204 Spring Local Replacement So far, considered global replacement algorithms –Most widely used But could also divide memory in pools –Per-process or per-user On frame allocation, requesting process will evict pages from pool to which it belongs Advantage: Isolation –No between-process interference Disadvantage: Isolation –Can’t temporarily “borrow” frames from other pools Q.: How big should pools be? –And when should allocations change? P1 used P2 used P2 free ?

12/6/2015CS 3204 Spring When Virtual Memory works well Locality –80% of accesses are to 20% of pages –80% of accesses are made by 20% of code Temporal locality: –Page that’s accessed will be accessed again in near future Spatial locality: –Prefetching pays off: if a page is accessed, neighboring page will be accessed If VM works well, average access to all memory is about as fast as access to physical memory

12/6/2015CS 3204 Spring VM Access Time & Page Fault Rate Consider expected access time in terms of fraction p of page accesses that don’t cause page faults. Then 1-p is page fault frequency Assume p = 0.99, assume memory is 100ns fast, and page fault servicing takes 10ms – how much slower is your VM system compared to physical memory? access time = 99ns *( ) ns  100,000ns or 0.1ms –Compare to 100ns or ms speed  about 1000x slowdown Conclusion: even low page fault rates lead to huge slowdown access time = p * memory access time + (1-p) * (page fault service time + memory access time)

12/6/2015CS 3204 Spring Thrashing: When Virtual Memory Does Not Work Well System accesses a page, evicts another page from its frame, and next access goes to just- evicted page which must be brought in Worst case a phenomenon called Thrashing –leads to constant swap-out/swap-in –100% disk utilization, but no process makes progress CPU most idle, memory mostly idle

12/6/2015CS 3204 Spring When does Thrashing occur? Process does exhibit locality, but is simply too large –Here: (assumption of) locality hurts us Process doesn’t exhibit locality –Does not reuse pages Processes individually fit & exhibit locally, but in total are too large for the system to accommodate all

12/6/2015CS 3204 Spring What to do about Thrashing? Buy more memory –ultimately have to do that –increasing memory sizes ultimately reason why thrashing is nowadays less of a problem than in the past – still OS must have strategy to avoid worst case Ask user to kill process Let OS decide to kill processes that are thrashing –Linux has an option to do that In many cases, still: reboot only time-efficient option –But OS should have reasonable strategy to avoid it if it can

12/6/2015CS 3204 Spring OS Strategies to prevent thrashing Or contain its effects Define: “working set” (1968, Denning) Set of pages that a process accessed during some window/period of length T in the past –Hope that it’ll match the set accessed in the future Idea: if we can manage to keep working set in physical memory, thrashing will not occur

12/6/2015CS 3204 Spring Working Set Suppose we know or can estimate working set – how could we use it? Idea 1: give each process as much memory as determined by size of its WS Idea 2: preferably evict frames that hold pages that don’t seem to be part of WS Idea 3: if WS cannot be allocated, swap out entire process (and exclude from scheduling for a while) –“medium term scheduling”, “swap-out scheduling” –(Suspended) inactive vs active processes –Or don’t admit until there’s enough frames for their WS (“long term scheduling”)

12/6/2015CS 3204 Spring Estimating Working Set Compute “idle time” for each page –Amount of CPU time process received since last access to page On page fault, scan resident pages –If referenced, set idle time to 0 –If not referenced, idle_time += time since last scan –If idle_time > T, consider to not be part of working set This is known as working set replacement algorithm [Denning 1968] Variation is WSClock [Carr 1981] –treats working set a circular list like global clock does, and updates “time of last use” (using a process’s CPU use as a measure) – evicting those where T_last < T_current - T

12/6/2015CS 3204 Spring Page Fault Frequency Alternative method of working set estimation –PFF: # page faults/instructions executed –Pure CPU perspective vs memory perspective provided by WSClock Below threshold – can take frames away from process Above threshold – assign more frames Far above threshold – suspect thrashing & swap out Potential drawback: can be slow to adopt to periods of transition

12/6/2015CS 3204 Spring Clock-PRO Clock and algorithms like it try to approximate LRU: –LRU does not work well for: –Sequential scans, large loops Alternative: –Reuse distance: should replace page with large reuse distance Clock-PRO: Idea – extend our focus by remembering information about pages that were evicted from frames previously See [Jiang 2005]Jiang 2005