Paging Algorithms Vivek Pai / Kai Li Princeton University.

Slides:



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

CS 241 Spring 2007 System Programming 1 Memory Replacement Policies Lecture 32 Klara Nahrstedt.
4.4 Page replacement algorithms
Chapter 3.3 : OS Policies for Virtual Memory
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Page Replacement Algorithms
Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
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.
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.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
Virtual Memory Today Virtual memory Page replacement algorithms
VM Design Issues Vivek Pai / Kai Li Princeton University.
Introduction to Systems Programming Lecture 7
Memory Management Virtual Memory Page replacement algorithms
Virtual Memory CSCI 444/544 Operating Systems Fall 2008.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
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.
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.
Part 8: Virtual Memory. Silberschatz, Galvin and Gagne ©2005 Virtual vs. Physical Address Space Each process has its own virtual address space, which.
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
© 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.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
CPS110: Page replacement Landon Cox. Replacement  Think of physical memory as a cache  What happens on a cache miss?  Page fault  Must decide what.
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.
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.
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.
CSE 153 Design of Operating Systems Winter 2015 Lecture 12: Page Replacement.
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.
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.
CS 3204 Operating Systems Godmar Back Lecture 18.
COS 318: Operating Systems Virtual Memory Paging.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory What if program is bigger than available memory?
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
CS703 - Advanced Operating Systems
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Demand Paging Reference Reference on UNIX memory management
CSE 120 Principles of Operating
Demand Paging Reference Reference on UNIX memory management
EECE.4810/EECE.5730 Operating Systems
Chapter 9: Virtual-Memory Management
Demand Paged Virtual Memory
Morgan Kaufmann Publishers Memory Hierarchy: 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
CSE 153 Design of Operating Systems Winter 19
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Virtual Memory.
Presentation transcript:

Paging Algorithms Vivek Pai / Kai Li Princeton University

2 Virtual Memory Gedankenexperiment Assume memory costs $20 per 256MB What does it cost to fill a 32-bit system? What does it cost to fill a 64-bit system? –What about at $1 per 256MB? What implications does this have for the design of virtual to physical translation when using 64-bit address spaces? –(hint: think hierarchical page tables)

3 Memory Hierarchy Revisited CPU TLB L1 L2 Main MemoryDevices What does this imply about L1 addresses? Where do we hope requests get satisfied?

4 Memory Hierarchy Re-Revisited CPU TLB L1 L2 Main MemoryDevices Now what does this imply about L1 addresses? Any speed benefits? Any drawbacks?

5 Definitions Paging – moving pages to (from) disk ex: paging begins five minutes into the test Pressure – the demand for some resource (often used when demand exceeds supply) ex: the system experienced memory pressure Optimal – the best (theoretical) strategy Eviction – throwing something out ex: cache lines and memory pages got evicted Pollution – bringing in useless pages/lines ex: this strategy causes high cache pollution

6 Big Picture Load M i Free frame Page table VM ref fault

7 Really Big Picture Every “page-in” requires an eviction Hopefully, kick out a less-useful page –Dirty pages require writing, clean pages don’t –Where do you write? To “swap space” Goal: kick out the page that’s least useful Problem: how do you determine utility? –Heuristic: temporal locality exists –Kick out pages that aren’t likely to be used again

8 More definitions Thrashing / Flailing – extremely high rate of paging, usually induced by other decisions Dirty/Clean – indicates whether modifications have been made versus copy on stable storage Heuristic – set of rules to use when no good rigorous answer exists Temporal – in time Spatial – in space (location) Locality – re-use – it makes the world go round

9 What Makes This Hard? Perfect reference stream hard to get –Every memory access would need bookkeeping Imperfect information available, cheaply –Play around with PTE permissions, info Overhead is a bad idea –If no memory pressure, ideally no bookkeeping –In other words, make the common case fast

10 Steps in Paging Data structures –A list of unused page frames –Data structure to map a frame to its pid/ virtual address On a page fault –Get an unused frame or a used frame –If the frame is used If it has been modified, write it to disk Invalidate its current PTE and TLB entry –Load the new page from disk –Update the faulting PTE and invalidate its TLB entry –Restart the faulting instruction

11 Optimal or MIN Algorithm: –Replace the page that won’t be used for the longest time Pros –Minimal page faults –This is an off-line algorithm for performance analysis Cons –No on-line implementation Also called Belady’s Algorithm

12 Not Recently Used (NRU) Algorithm –Randomly pick a page from the following (in order) Not referenced and not modified Not referenced and modified Referenced and not modified Referenced and modified Pros –Easy to implement Cons –Not very good performance, takes time to classify

13 First-In-First-Out (FIFO) Algorithm –Throw out the oldest page Pros –Low-overhead implementation Cons –May replace the heavily used pages Recently loaded Page out

14 FIFO with Second Chance Algorithm –Check the reference-bit of the oldest page –If it is 0, then replace it –If it is 1, clear the reference-bit, move it to end of list, and continue searching Pros –Fast and does not replace a heavily used page Cons –The worst case may take a long time Recently loaded Page out If reference bit is 1

15 Clock: A Simple FIFO with 2 nd Chance FIFO clock algorithm –Hand points to the oldest page –On a page fault, follow the hand to inspect pages Second chance –If the reference bit is 1, set it to 0 and advance the hand –If the reference bit is 0, use it for replacement What is the difference between Clock and the previous one? Oldest page

16 Enhanced FIFO with 2nd-Chance Algorithm Same as the basic FIFO with 2nd chance, except that this method considers both reference bit and modified bit –(0,0): neither recently used nor modified –(0,1): not recently used but modified –(1,0): recently used but clean –(1,1): recently used and modified Pros –Avoid write back Cons –More complicated

17 More Page Frames  Fewer Page Faults? Consider the following reference string with 4 page frames –FIFO replacement –1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 –10 page faults Consider the same reference string with 3 page frames –FIFO replacement –1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 –9 page faults! This is called Belady’s anomaly

18 Least Recently Used (LRU) Algorithm –Replace page that hasn’t been used for the longest time Question –What hardware mechanisms required to implement LRU?

19 Implement LRU Perfect –Use a timestamp on each reference –Keep a list of pages ordered by time of reference Mostly recently used Least recently used

20 Approximate LRU Most recently used Least recently used N categories pages in order of last reference LRU Crude LRU 2 categories pages referenced since the last page fault pages not referenced since the last page fault bit count 256 categories

21 Aging: Not Frequently Used (NFU) Algorithm –Shift reference bits into counters –Pick the page with the smallest counter Main difference between NFU and LRU? –NFU has a short history (counter length) How many bits are enough? –In practice 8 bits are quite good Pros: Require one reference bit Cons: Require looking at all counters

22 Where Do We Get Storage? 32 bit VA to 32 bit PA – no space, right? –Offset within page is the same No need to store offset –4KB page = 12 bits of offset –Those 12 bits are “free” in PTE Page # + other info <= 32 bits –Makes storing info easy