1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set.

Slides:



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

Virtual Memory (Chapter 4.3)
Chapter 101 The LRU Policy Replaces the page that has not been referenced for the longest time in the past By the principle of locality, this would be.
Module 10: Virtual Memory
Page-replacement policies On some standard algorithms for the management of resident virtual memory pages.
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.
Page Replacement Algorithms
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
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.
Allocation of Frames Each process needs minimum number of pages
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  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 38 Frame Allocation Read.
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.
Day 23 Virtual Memory. Operating system’s role in VM Hardware-support Use VM or not Use paging or segmentation or both Software domain Algorithms for.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set.
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 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Memory Management Virtual Memory Page replacement algorithms
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Page Replacement Algorithms
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.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
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.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
CSS430 Virtual Memory Textbook Ch9
Virtual Memory.
Page 19/17/2015 CSE 30341: Operating Systems Principles Optimal Algorithm  Replace page that will not be used for longest period of time  Used for measuring.
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Paging.
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.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
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.
CPS110: Page replacement Landon Cox. Replacement  Think of physical memory as a cache  What happens on a cache miss?  Page fault  Must decide what.
Demand Paging Reference Reference on UNIX memory management
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Virtual Memory & Paging Emery Berger and Mark Corner.
1 Page Replacement Algorithms. 2 Virtual Memory Management Fundamental issues : A Recap Key concept: Demand paging  Load pages into memory only when.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
COS 318: Operating Systems Virtual Memory Paging.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Day 22 Virtual Memory.
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Lecture 28: Virtual Memory-Address Translation
Chapter 9: Virtual-Memory Management
5: Virtual Memory Background Demand Paging
Demand Paged Virtual Memory
Operating Systems CMPSC 473
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
Chapter 9: Virtual Memory CSS503 Systems Programming
Virtual Memory.
Presentation transcript:

1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set

2 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A, B, C, B, C, C, D

3 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 A, B, C, B, C, C, D

4 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B2B2 A, B, C, B, C, C, D

5 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B2B2 C3C3 A, B, C, B, C, C, D

6 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B4B4 C3C3 A, B, C, B, C, C, D

7 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B4B4 C5C5 A, B, C, B, C, C, D

8 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B4B4 C6C6 A, B, C, B, C, C, D

9 Implementing Exact LRU On each reference, time stamp page When we need to evict: select oldest page = least-recently used A1A1 B4B4 C6C6 A, B, C, B, C, C, D D7D7 LRU page How should we implement this?

10 Implementing Exact LRU: Data Structures Hash table: optimize the common case (memory hit) Location of a page in memory: apply hash function to a page number update: O(1), eviction: O(n) (n: # of pages to process) Expensive: on every reference, compute hash of page address; update time stamp doubly-linked list Move items to front when referenced LRU items at end of list Still too expensive: Linear lookup time to find a page 4-6 pointer updates per reference

11 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Reference-bit algorithm Clock Algorithm Thrashing Cause Working Set

12 Reference-bit algorithm Hardware support: reference bit Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0

13 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A1A1 B1B1 C1C1 A, B, C, B, C, C, D

14 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B0B0 C0C0 A, B, C, B, C, C, D reset reference bits

15 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B1B1 C0C0 A, B, C, B, C, C, D

16 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B1B1 C1C1 A, B, C, B, C, C, D

17 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B1B1 C1C1 A, B, C, B, C, C, D

18 Reference-bit algorithm: example Maintain reference bit for every page On each access, set reference bit to 1 Periodically resets reference bits Evict page with reference bit = 0 A0A0 B1B1 C1C1 A, B, C, B, C, C, D D1D1

19 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Reference-bit algorithm Clock Algorithm Thrashing Cause Working Set

20 The Clock Algorithm Set reference bit to 1 for an access Consider frames in circle Pointer: 0: initially Only advance pointer when page fault happens On page fault, OS: Repeat Checks reference bit of the current pointer If reference bit = 0, replace page, set bit to 1; advance pointer to next frame; break; If reference bit = 1, set bit to 0, advance pointer to next frame

21 The Clock Algorithm: example A, B, C, D, B, C, E, F, C, G

22 The Clock Algorithm: Summary Variant of FIFO & LRU LRU: ? FIFO: ? No need to reset reference bit periodically

23 Enhancing Clock Idea: favor eviction of unmodified pages We don’t write back unmodified pages Extend hardware to keep another bit: modified bit Total order of tuples: (ref bit, mod bit) (0,0), (0,1), (1,0), (1,1) Evict page from lowest nonempty class

24 Page Replacement in Enhanced Clock OS may scan multiple times: Page (0,0) – replace that page Page (0,1) – replace and write out page Page (1,0) – replace that page Page (1,1) – replace and write out page Fast, but still coarse approximation of LRU

25 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Reference-bit algorithm Clock Thrashing Cause Working Set

26 Thrashing A process is busy swapping pages in and out; no useful work is done low CPU utilization OS adds processes → even more page swapping & lower CPU utilization

27 Cause of Thrashing Locality A set of pages that are actively used together Process migrates from one locality to another Total locality of processes > total memory size Process cannot keep in memory all pages that it is currently using

28 Working Set Strategy Working set = pages referred in last  references (approximate of locality) OS monitors working set of each process; allocate enough frames to process Another process can be started if there are enough extra frames Suspend process(es) if the sum of working-set sizes exceeds RAM

29 Working Set Problems Algorithm relies on key parameter,  How do we set  ? Is there one correct  ? Different processes have different timescales over which they refer pages Not acceptable (or necessarily possible) to suspend processes altogether Not really used Very rough variant used in Windows