Page Replacement in Real Systems Questions answered in this lecture: How can the LRU page be approximated efficiently? How can users discover the page.

Slides:



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

CS Introduction to Operating Systems
9.4 Page Replacement What if there is no free frame?
4.4 Page replacement algorithms
Page Replacement Algorithms
Chapter 3.3 : OS Policies for Virtual Memory
Virtual Memory 3 Fred Kuhns
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: Page Replacement
Page Replacement Algorithms
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
1 Cache and Caching David Sands CS 147 Spring 08 Dr. Sin-Min Lee.
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.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
Exploiting Gray-Box Knowledge of Buffer Cache Management Nathan C. Burnett, John Bent, Andrea C. Arpaci-Dusseau, Remzi H. Arpaci-Dusseau University of.
1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management – 4 Page Replacement Algorithms CS 342 – Operating Systems.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
CS 104 Introduction to Computer Science and Graphics Problems
Computer Organization and Architecture
Virtual Memory CSCI 444/544 Operating Systems Fall 2008.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Caching and Demand-Paged Virtual Memory
Page Replacement Algorithms
Demand Paging Virtual memory = indirect addressing + demand paging –Without demand paging, indirect addressing by itself is valuable because it reduces.
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.
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
1 First-in, First-out Remove the oldest page Determine the age based on the loading time, not on the time being referenced Old pages may be heavily used.
PR SM Laboratory A Parameter Extraction Tool for Windows I/O System Characterization Versailles Saint Quentin University National Scientific research center.
Exploiting Gray-Box Knowledge of Buffer Cache Management Nathan C. Burnett, John Bent, Andrea C. Arpaci-Dusseau, Remzi H. Arpaci-Dusseau University of.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Paging.
Demand Paged Virtual Memory Andy Wang Operating Systems COP 4610 / CGS 5765.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
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.
Demand Paging Reference Reference on UNIX memory management
CS307 Operating Systems Virtual Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
File Systems 2. 2 File 1 File 2 Disk Blocks File-Allocation Table (FAT)
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?
CS 149: Operating Systems March 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Transforming Policies into Mechanisms with Infokernel Andrea C. Arpaci-Dusseau, Remzi H. Arpaci-Dusseau, Nathan C. Burnett, Timothy E. Denehy, Thomas J.
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.
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.
PAGE REPLACEMNT ALGORITHMS FUNDAMENTAL OF ALGORITHMS.
CS 3204 Operating Systems Godmar Back Lecture 18.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Chapter 21 Virtual Memoey: Policies
Lecture 28: Virtual Memory-Address Translation
Chapter 9: Virtual-Memory Management
Distributed Systems CS
What Happens if There is no Free Frame?
Demand Paged Virtual Memory
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Practical Session 8, Memory Management 2
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Operating Systems CMPSC 473
Virtual Memory: Working Sets
Lecture 9: Caching and Demand-Paged Virtual Memory
Practical Session 9, Memory Management continues
Presentation transcript:

Page Replacement in Real Systems Questions answered in this lecture: How can the LRU page be approximated efficiently? How can users discover the page replacement algorithm of the OS? What page replacement algorithms are used in existing systems? UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 537 Introduction to Operating Systems Andrea C. Arpaci-Dusseau Remzi H. Arpaci-Dusseau

Implementing LRU Software Perfect LRU OS maintains ordered list of physical pages by reference time When page is referenced: Move page to front of list When need victim: Pick page at back of list Trade-off: Slow on memory reference, fast on replacement Hardware Perfect LRU Associate register with each page When page is referenced: Store system clock in register When need victim: Scan through registers to find oldest clock Trade-off: Fast on memory reference, slow on replacement (especially as size of memory grows) In practice, do not implement Perfect LRU LRU is an approximation anyway, so approximate more Goal: Find an old page, but not necessarily the very oldest

Clock (Second Chance) Algorithm Hardware Keep use (or reference) bit for each page frame When page is referenced: set use bit Operating System Page replacement: Look for page with use bit cleared (has not been referenced for awhile) Implementation: –Treat pages as circular buffer –Keep pointer to last examined page frame –Traverse pages in circular buffer –Clear use bits as search –Stop when find page with cleared use bit, replace this page

Clock Algorithm Example What if clock hand is sweeping very fast? What if clock hand is sweeping very slow?

Clock Extensions Replace multiple pages at once Intuition: Expensive to run replacement algorithm and to write single block to disk Find multiple victims each time Two-handed clock Intuition: –If takes long time for clock hand to sweep through pages, then all use bits might be set –Traditional clock cannot differentiate between usage of different pages Allow smaller time between clearing use bit and testing –First hand: Clears use bit –Second hand: Looks for victim page with use bit still cleared

More Clock Extensions Add software counter (“chance”) Intuition: Better ability to differentiate across pages (how much they are being accessed) Increment software counter chance if use bit is 0 Replace when chance exceeds some specified limit Use dirty bit to give preference to dirty pages Intuition: More expensive to replace dirty pages –Dirty pages must be written to disk, clean pages do not Replace pages that have use bit and dirty bit cleared

What if no Hardware Support? What can the OS do if hardware does not have use bit (or dirty bit)? Can the OS “emulate” these bits? Leading question: How can the OS get control (i.e., generate a trap) every time use bit should be set? (i.e., when a page is accessed?)

Problems with LRU-based Replacement LRU does not consider frequency of accesses Is a page that has been accessed once in the past as likely to be accessed in the future as one that has been accessed N times? Common workload problem: Scan (sequential read, never used again) of one large data region (larger than physical memory) flushes memory contents Solution: Track frequency of accesses to page Pure LFU (Least-frequently-used) replacement Problem: LFU can never forget pages from the far past

Combine LRU and LFU LRU-K: Combines recency and frequency attributes Track K-th reference to page in past, replace page with oldest (LRU) K-th reference (or does not have K-th reference) History: Remembers access time of pages not now in memory Expensive to implement, LRU-2 used in databases 2Q: More efficient than LRU-2, similar performance Intuition: Instead of removing cold pages, only admit hot pages to main buffer A1in for short-term accesses, managed with FIFO Am for long-term accesses, managed with LRU On first page fault, page enters A1in queue On subsequent page faults, page enters Am queue A1out: pages not in buffer cache, but remembered

More Problems with LRU-based Replacement Problematic workload for LRU Repeated scans of large memory region (larger than physical memory) Example: 5 blocks of physical memory, 6 blocks of address space repeatedly scanned (ABCDEFABCDEFABCDEF...) –What happens with LRU? Solution?

Policy Discovery for Real Systems Page replacement policies not well documented Often change across versions of OS Fingerprinting: automatic discovery of algorithms or policies (e.g. replacement policy, scheduling algorithm) Software that runs at user-level Requires no kernel modifications Portable across operating systems Approach Probe the OS by performing sequence of operations (e.g., read/write) Time operations to see how long they take Use time to infer the policy the OS is employing

Dust Research project in our group “Exploiting Gray-Box Knowledge of Buffer-Cache Management”, N. Burnett, J. Bent, A. Arpaci-Dusseau, R. Arpaci-Dusseau, USENIX’’02 Dust - Fingerprints file buffer cache policies OS manages physical memory for two purposes file buffer cache virtual memory often same replacement policy for each (but not always) Simpler to fingerprint file buffer cache policy read() seek()

Size of Memory How can we infer the amount of physical memory used for buffer cache (or virtual memory)? Idea for user-level fingerprinting process: Access some amount of data, N (i.e., bring it into physical memory) Re-access each page of data, timing how long each access takes –“Fast” access --> –“Slow” access --> If all pages appear in memory, increase N and repeat Stop when pages no longer all fit in memory –Implies N > number of physical pages

Replacement Policies How can we infer replacement policy? Assume policy uses combination of attributes: initial access order (FIFO) recency (LRU) frequency (LFU) Algorithm I. Move memory to known state by accessing test data such that each page has unique attributes II. Cause part of test data to be evicted by reading in eviction data III. Sample test data to determine cache state Read a block and time it Which blocks are still present determines policy of OS Repeat for confidence

Setting Initial Access Order Test Region Eviction Region for ( 0  test_region_size/read_size) { read(read_size); }

Detecting FIFO FIFO evicts the first half of test region Out of Cache In Cache Results from reading and timing test on FIFO simulator

Setting Recency Left Pointer Right Pointer Test Region Eviction Region do_sequential_scan(); left = 0; right = test_region_size/2; for ( 0  test_region_size/read_size){ seek(left); read(read_size); seek(right); read(read_size); right+=read_size; left+= read_size; }

Detecting LRU LRU evicts 1 st and 3 rd quarters of test region

Setting Frequency Left Pointer Right Pointer Test Region Eviction Region do_sequential_scan(); left = 0; right = test_region_size/2; left_count = 1; right_count = 5; for ( 0  test_region_size/read_size) for (0  left_count) seek(left); read(read_size); for (0  right_count) seek(right); read(read_size); right+=read_size; left+= read_size; right_count++; left_count--;

Detecting LFU LFU evicts outermost stripes of test (Two stripes partially evicted)

NetBSD 1.5 Noisier data on real systems due to disk performance variations Conclusion: LRU FIFOFIFO LRULRU LFULFU

Linux Very noisy but looks like LRU - actually clock FIFOFIFO LRULRU LFULFU

Linux Low recency areas are evicted Low frequency areas also evicted Conclusion: LRU with page aging (similar to 2Q) FIFOFIFO LRULRU LFULFU

Solaris 2.7 Clock with some frequency component FIFOFIFO LRULRU LFULFU