U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.

Slides:



Advertisements
Similar presentations
Page Replacement Algorithms
Advertisements

Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 36 Virtual Memory Read.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
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.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set.
03/26/2010CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying an earlier.
Operating Systems CMPSCI 377 Lecture 11: Memory Management
1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
Virtual Memory CSCI 444/544 Operating Systems Fall 2008.
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.
Caching and Demand-Paged Virtual Memory
Memory Management 2 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
1 Review for Final Exam Memory management Three central questions File system I/O system Network Protection Security.
1 Last Time: Paging Motivation Page Tables Hardware Support Benefits.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Virtual Memory.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Demand Paged Virtual Memory Andy Wang Operating Systems COP 4610 / CGS 5765.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
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.
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.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
CSC 360, Instructor: Kui Wu Memory Management II: Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
1 Virtual Memory. Cache memory: provides illusion of very high speed Virtual memory: provides illusion of very large size Main memory: reasonable cost,
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?
Virtual Memory The address used by a programmer will be called a virtual address or logical address. An address in main memory is called a physical address.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner.
CSE 153 Design of Operating Systems Winter 2015 Lecture 12: Page Replacement.
1 Lecture 8: Virtual Memory Operating System Fall 2006.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
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.
1 Contents Memory types & memory hierarchy Virtual memory (VM) Page replacement algorithms in case of VM.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
Virtual Memory Chapter 8.
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Chapter 9: Virtual Memory – Part I
Operating Systems Virtual Memory Alok Kumar Jagadev.
Lecture 10: Virtual Memory
CSE 120 Principles of Operating
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
What Happens if There is no Free Frame?
5: Virtual Memory Background Demand Paging
Demand Paged Virtual Memory
Contents Memory types & memory hierarchy Virtual memory (VM)
Operating Systems CMPSC 473
Lecture 9: Caching and Demand-Paged Virtual Memory
Module 9: Virtual Memory
Module IV Memory Organization.
Presentation transcript:

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture 13: Demand Paging

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 2 Last Time: Paging Motivation Fragmentation Page Tables Hardware Support Other Benefits

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 3 Today: Demand-Paged VM Reading pages Writing pages Swap space Page eviction Cost of paging Page replacement algorithms Evaluation

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 4 Demand-Paged Virtual Memory Key idea: use RAM as cache for disk OS transparently moves pages Page table: page on disk, in memory OS updates whenever pages change state Requires locality: Working set (pages referenced recently) must fit in memory If not: thrashing (nothing but disk traffic)

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 5 Demand-Paging Diagram

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 6 Key Policy Decisions Two key questions: (for any cache): When do we read page from disk? When do we write page to disk?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 7 Reading Pages Read on-demand: OS loads page on its first reference May force an eviction of page in RAM Pause while loading page = page fault Can also perform pre-paging: OS guesses which page will next be needed, and begins loading it Advantages? Disadvantages? Most systems just do demand paging

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 8 Demand Paging On every reference, check if page is in memory (valid bit in page table) If not: trap to OS OS checks address validity, and Selects victim page to be replaced Invalidates old page in page table Begins loading new page from disk Switches to other process (paging = implicit I/O) Note: must restart instruction later

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 9 Demand Paging, Continued Interrupt signals page arrival, then: OS updates page table entry Continues faulting process Stops current process We could continue currently executing process – but why not? And where does the victim page go?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 10 Demand Paging, Continued Interrupt signals page arrival, then: OS updates page table entry Continues faulting process Stops current process We could continue currently executing process – but why not? Page just brought in could get paged out... And where does the victim page go?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 11 Swap Space Swap space = where victim pages go Partition or special file reserved on disk Sometimes: special filesystem (“tmpfs”) What kind of victim pages can be evicted without going to swap? Size of reserved swap space limits what?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 12 Swap Space Swap space = where victim pages go Partition or special file reserved on disk Sometimes: special filesystem (“tmpfs”) What kind of victim pages can be evicted without going to swap? Read-only (“text”), untouched anonymous pages Size of reserved swap space limits what?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 13 Swap Space Swap space = where victim pages go Partition or special file reserved on disk Sometimes: special filesystem (“tmpfs”) What kind of victim pages can be evicted without going to swap? Read-only (“text”), untouched anonymous pages Size of reserved swap space limits what? Total virtual memory

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 14 Virtual Memory Locations VM pages can now exist in one or more of following places: Physical memory (in RAM) Swap space (victim page) Filesystem (why?) Requires more sophisticated page table Slightly more expensive, but real expense...

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 15 Cost of Paging Worst-case analysis – useless Easy to construct adversary example: every page requires page fault A, B, C, D, E, F, G, H, I, J, A... size of available memory

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 16 Cost of Paging, continued “Average-case” No such thing (what’s “average” reference behavior?) But: processes exhibit locality, so performance generally not bad Temporal locality: processes tend to reference same items repeatedly Spatial locality: processes tend to reference items near each other (e.g., on same page)

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 17 Effective Access Time Let p = probability of page fault (0 · p · 1) ma = memory access time Effective access time = (1 – p) * ma + p * page fault service time Memory access = 200ns, page fault = 25ms: effective access time = (1-p)*200 + p*25,000,000 Desired effective access time = 10% slower than memory access time: p = ?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 18 Effective Access Time Let p = probability of page fault (0 · p · 1) ma = memory access time Effective access time = (1 – p) * ma + p * page fault service time Memory access = 200ns, page fault = 25ms: effective access time = (1-p)*200 + p*25,000,000 Desired effective access time = 10% slower than memory access time: p = 8*10 -7

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 19 Evaluating Page Replacement Algorithms Worst-case – all just as bad Average-case – what does that mean? Empirical studies – real application behavior Theory: competitive analysis Can’t do better than optimal How far (in terms of faults) is algorithm from optimal in worst-case? Competitive ratio If algorithm can’t do worse than 2x optimal, it’s 2-competitive

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 20 Page Replacement Algorithms MIN, OPT (optimal) RANDOM evict random page FIFO (first-in, first-out) give every page equal residency LRU (least-recently used) MRU (most-recently used)

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 21 MIN/OPT Invented by Belady (“MIN”), now known as “OPT”: optimal page replacement Evict page to be accessed furthest in the future Provably optimal policy Just one small problem... Requires predicting the future Useful point of comparison

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 22 MIN/OPT example Page faults: 5

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 23 RANDOM Evict any page Works surprisingly well Theoretically: very good 2 * H k competitive (H k ¼ ln k) Not used in practice: takes no advantage of locality

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 24 LRU Evict page that has not been used in longest time (least-recently used) Approximation of MIN if recent past is good predictor of future A variant of LRU used in all real operating systems Competitive ratio: k, (k = # of page frames) Best possible for deterministic algs.

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 25 LRU example Page faults: ?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 26 LRU example Page faults: 5

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 27 LRU, example II Page faults: ?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 28 LRU, example II Page faults: 12!

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 29 FIFO First-in, first-out: evict oldest page Also has competitive ratio k But: performs miserably in practice! LRU takes advantage of locality FIFO does not Suffers from Belady’s anomaly: More memory can mean more paging! LRU & other “stack” algs. do not

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 30 FIFO & Belady’s Anomaly

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 31 LRU: No Belady’s Anomaly Why no anomaly for LRU?

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 32 MRU Evict most-recently used page Shines for LRU’s worst-case: loop that exceeds RAM size What we really want: adaptive algorithms (e.g., EELRU – Kaplan & Smaragdakis) A, B, C, D, A, B, C, D,... size of available memory

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 33 Summary Reading pages Writing pages Swap space Page eviction Cost of paging Page replacement algorithms Evaluation

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 34 Next Time Virtual memory implementation Interaction with multiprogramming