1 Last Time: Paging Motivation Page Tables Hardware Support Benefits.

Slides:



Advertisements
Similar presentations
9.4 Page Replacement What if there is no free frame?
Advertisements

Page Replacement Algorithms
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. 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.
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.
Virtual Memory Background Demand Paging Performance of Demand Paging
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
03/26/2010CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying an earlier.
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.
Paging Algorithms Vivek Pai / Kai Li Princeton University.
Chapter 11 – Virtual Memory Management Outline 11.1 Introduction 11.2Locality 11.3Demand Paging 11.4Anticipatory Paging 11.5Page Replacement 11.6Page Replacement.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
Virtual Memory CSCI 444/544 Operating Systems Fall 2008.
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.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
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
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
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.
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.
CPS110: Page replacement Landon Cox. Replacement  Think of physical memory as a cache  What happens on a cache miss?  Page fault  Must decide what.
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.
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.
Virtual Memory. 2 Last Week Memory Management Increase degree of multiprogramming –Entire process needs to fit into memory Dynamic Linking and Loading.
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 Management
What Happens if There is no Free Frame?
Demand Paged Virtual Memory
Chapter 6 Virtual Memory
There’s not always room for one more. Brian Bershad
Contents Memory types & memory hierarchy Virtual memory (VM)
Operating Systems CMPSC 473
Lecture 9: Caching and Demand-Paged Virtual Memory
Module 9: Virtual Memory
Clock Algorithm Example
Module IV Memory Organization.
Presentation transcript:

1 Last Time: Paging Motivation Page Tables Hardware Support Benefits

2 Demand-Paged VM Reading pages Writing pages Swap space Page eviction Cost of paging Page replacement algorithms Evaluation

3 Demand-Paging Diagram

4 Key Policy Decisions Two key questions: When do we read page from disk? When do we write page to disk?

5 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

6 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 Begins loading new page from disk Switches to other process (demand paging = implicit I/O) Note: must restart instruction later

7 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?

8 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?

9 Swap Space Swap space = where victim pages go Partition or special file reserved on disk Sometimes: special filesystem (“tmpfs”) Evicted without going to swap? Read-only (“text”), untouched anonymous pages

10 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?)

11 Page Replacement Process is given a fixed memory space of n pages Question: process requests a page page is not in memory, all n pages are used which page should be evicted from memory?

12 Page Replacement: Cost of Paging Worst-case analysis Easy to construct adversary example: every page requires page fault Not much you can do, paging useless A, B, C, D, E, F, G, H, I, J, A... size of available memory

13 Page Replacement: Cost of Paging, cont’d 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)

14 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

15 Evaluating Page Replacement Algorithms Average-case: 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

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

17 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

18 MIN/OPT example Page faults: 5

19 RANDOM Evict any page Works surprisingly well Theoretically: very good Not used in practice: takes no advantage of locality

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

21 LRU example Page faults: ?

22 LRU example Page faults: 5

23 LRU, example II Page faults: ?

24 LRU, example II Page faults: 12

25 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!

26 FIFO & Belady’s Anomaly

27 LRU: No Belady’s Anomaly Why no anomaly for LRU (or other “stack” algs)? Pages in memory for memory size of n are also in memory for memory size of n+1

28 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

29 Summary Reading pages Writing pages Swap space Page eviction Cost of paging Page replacement algorithms Evaluation