Page Replacement Algorithms

Similar documents
Chapter 9: Virtual Memory

CS370 Operating Systems

CS370 Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts

First-In-First-Out (FIFO) Algorithm

Page Replacement. 3/9/07 CSE 30341: Operating Systems Principles

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Chapter 9: Virtual-Memory

Basic Page Replacement

Chapter 10: Virtual Memory

Module 9: Virtual Memory

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical Memory

Operating System Concepts 9 th Edition

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

CS307: Operating Systems

OPERATING SYSTEM. Chapter 9: Virtual Memory

Module 9: Virtual Memory

Background. Virtual Memory (2/2) Demand Paging Example. First-In-First-Out (FIFO) Algorithm. Page Replacement Algorithms. Performance of Demand Paging

Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007

CS370 Operating Systems

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

CS420: Operating Systems

Lecture 17. Edited from slides for Operating System Concepts by Silberschatz, Galvin, Gagne

Optimal Algorithm. Replace page that will not be used for longest period of time Used for measuring how well your algorithm performs

Chapter 9: Virtual Memory. Chapter 9: Virtual Memory. Objectives. Background. Virtual-address address Space

Principles of Operating Systems

Chapter 9: Virtual Memory

Chapter 10: Virtual Memory. Background

Chapter 10: Virtual Memory. Background. Demand Paging. Valid-Invalid Bit. Virtual Memory That is Larger Than Physical Memory

Where are we in the course?

Operating System Concepts

Virtual Memory B: Objec5ves

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Chapter 9: Virtual Memory

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Virtual Memory - II. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XVI. University at Buffalo.

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory

Chapter 3: Virtual Memory ว ตถ ประสงค. Background สามารถอธ บายข อด ในการท ระบบใช ว ธ การจ ดการหน วยความจ าแบบเสม อนได

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani

Virtual Memory COMPSCI 386

Operating Systems. Overview Virtual memory part 2. Page replacement algorithms. Lecture 7 Memory management 3: Virtual memory

Virtual Memory: Page Replacement. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Chapter 9: Virtual Memory

Chapters 9 & 10: Memory Management and Virtual Memory

Virtual Memory Outline

Virtual Memory - Overview. Programmers View. Virtual Physical. Virtual Physical. Program has its own virtual memory space.

Chapter 9: Virtual-Memory Management. Operating System Concepts 8 th Edition,

Chapter 9: Virtual Memory

Chapter 6: Demand Paging

1. Background. 2. Demand Paging

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Swapping. Operating Systems I. Swapping. Motivation. Paging Implementation. Demand Paging. Active processes use more physical memory than system has

CSC Operating Systems Spring Lecture - XIV Virtual Memory - II. Tevfik Ko!ar. Louisiana State University. March 27 th, 2008.

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

Demand Paging. Valid-Invalid Bit. Steps in Handling a Page Fault. Page Fault. Transfer of a Paged Memory to Contiguous Disk Space

Chapter 8: Main Memory. Operating System Concepts 8th Edition

Virtual Memory III. Jo, Heeseung

UNIT - IV. What is virtual memory?

Operating System - Virtual Memory

Lecture 14 Page Replacement Policies

Memory management, part 2: outline

instruction is 6 bytes, might span 2 pages 2 pages to handle from 2 pages to handle to Two major allocation schemes

ECE7995 Caching and Prefetching Techniques in Computer Systems. Lecture 8: Buffer Cache in Main Memory (I)

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

CS370 Operating Systems

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced?

Virtual Memory. Reading: Silberschatz chapter 10 Reading: Stallings. chapter 8 EEL 358

Outline. 1 Paging. 2 Eviction policies. 3 Thrashing 1 / 28

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

e-pg Pathshala Subject: Computer Science Paper: Operating Systems Module 29: Allocation of Frames, Thrashing Module No: CS/OS/29 Quadrant 1 e-text

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Memory Management Outline. Operating Systems. Motivation. Paging Implementation. Accessing Invalid Pages. Performance of Demand Paging

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

Last Class: Demand Paged Virtual Memory

Chapter 4 Memory Management

Virtual Memory. ICS332 Operating Systems

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - XIV Virtual Memory - I. Louisiana State University.

Basic Memory Management

Perform page replacement. (Fig 8.8 [Stal05])

Operating Systems. Operating Systems Sina Meraji U of T

Virtual Memory Design and Implementation

Chapter 9: Virtual Memory

Virtual Memory. Today.! Virtual memory! Page replacement algorithms! Modeling page replacement algorithms

Virtual Memory Management

All Paging Schemes Depend on Locality. VM Page Replacement. Paging. Demand Paging

SMD149 - Operating Systems - VM Management

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Global Replacement Algorithms (1) Ken Wong Washington University. Global Replacement Algorithms (2) Replacement Example (1)

CS 153 Design of Operating Systems Winter 2016

Chapter 4 Memory Management. Memory Management

Week 2: Tiina Niklander

Chapter 8: Main Memory Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

CS 4410 Operating Systems. Page Replacement (2) Summer 2016 Cornell University

Transcription:

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) 1 9.1 Silberschatz, Galvin and Gagne 2013

First-In-First-Out (FIFO) Algorithm Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 3 frames (3 pages can be in memory at a time per process) 15 page faults Can vary by reference string: consider 1,2,3,4,1,2,5,1,2,3,4,5 Adding more frames can cause more page faults! Belady s Anomaly How to track ages of pages? Just use a FIFO queue 9.2 Silberschatz, Galvin and Gagne 2013

FIFO Illustrating Belady s Anomaly 9.3 Silberschatz, Galvin and Gagne 2013

Optimal Algorithm Replace page that will not be used for longest period of time 9 is optimal for the example How do you know this? Can t read the future Used for measuring how well your algorithm performs 9.4 Silberschatz, Galvin and Gagne 2013

Least Recently Used (LRU) Algorithm Use past knowledge rather than future Replace page that has not been used in the most amount of time Associate time of last use with each page 12 faults better than FIFO but worse than OPT Generally good algorithm and frequently used But how to implement? 9.5 Silberschatz, Galvin and Gagne 2013

LRU Algorithm (Cont.) Counter implementation Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter When a page needs to be changed, look at the counters to find smallest value Search through table needed Stack implementation Keep a stack of page numbers in a double link form: Page referenced: move it to the top requires 6 pointers to be changed But each update more expensive No search for replacement LRU and OPT are cases of stack algorithms that don t have Belady s Anomaly 9.6 Silberschatz, Galvin and Gagne 2013

Use Of A Stack to Record Most Recent Page References 9.7 Silberschatz, Galvin and Gagne 2013

LRU Approximation Algorithms LRU needs special hardware and still slow Reference bit With each page associate a bit, initially = 0 When page is referenced bit set to 1 Replace any with reference bit = 0 (if one exists) We do not know the order, however Second-chance algorithm Generally FIFO, plus hardware-provided reference bit Clock replacement If page to be replaced has Reference bit = 0 -> replace it reference bit = 1 then: set reference bit 0, leave page in memory replace next page, subject to same rules 9.8 Silberschatz, Galvin and Gagne 2013

Second-Chance (clock) Page-Replacement Algorithm 9.9 Silberschatz, Galvin and Gagne 2013

Enhanced Second-Chance Algorithm Improve algorithm by using reference bit and modify bit (if available) in concert Take ordered pair (reference, modify) 1. (0, 0) neither recently used not modified best page to replace 2. (0, 1) not recently used but modified not quite as good, must write out before replacement 3. (1, 0) recently used but clean probably will be used again soon 4. (1, 1) recently used and modified probably will be used again soon and need to write out before replacement When page replacement called for, use the clock scheme but use the four classes replace page in lowest non-empty class Might need to search circular queue several times 9.10 Silberschatz, Galvin and Gagne 2013

Counting Algorithms Keep a counter of the number of references that have been made to each page Not common Lease Frequently Used (LFU) Algorithm: replaces page with smallest count Most Frequently Used (MFU) Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used 9.11 Silberschatz, Galvin and Gagne 2013

Page-Buffering Algorithms Keep a pool of free frames, always Then frame available when needed, not found at fault time Read page into free frame and select victim to evict and add to free pool When convenient, evict victim Possibly, keep list of modified pages When backing store otherwise idle, write pages there and set to non-dirty Possibly, keep free frame contents intact and note what is in them If referenced again before reused, no need to load contents again from disk Generally useful to reduce penalty if wrong victim frame selected 9.12 Silberschatz, Galvin and Gagne 2013

Applications and Page Replacement All of these algorithms have OS guessing about future page access Some applications have better knowledge i.e. databases Memory intensive applications can cause double buffering OS keeps copy of page in memory as I/O buffer Application keeps page in memory for its own work Operating system can given direct access to the disk, getting out of the way of the applications Raw disk mode Bypasses buffering, locking, etc 9.13 Silberschatz, Galvin and Gagne 2013

Allocation of Frames Each process needs minimum number of frames Defined by the computer architecture Maximum of course is total frames in the system Two major allocation schemes fixed allocation priority allocation Many variations 9.14 Silberschatz, Galvin and Gagne 2013

Fixed Allocation Equal allocation For example, if there are 100 frames (after allocating frames for the OS) and 5 processes, give each process 20 frames Keep some as free frame buffer pool Proportional allocation Allocate according to the size of process Dynamic as degree of multiprogramming, process sizes change s S s a i i size of process i m total number of allocation for p i p i frames si m S m 64 s1 10 s 2 127 a 1 10 137 62 4 a 2 127 62 57 137 9.15 Silberschatz, Galvin and Gagne 2013

Priority Allocation Use a proportional allocation scheme using priorities rather than size If process P i generates a page fault, select for replacement one of its frames select for replacement a frame from a process with lower priority number 9.16 Silberschatz, Galvin and Gagne 2013

Global vs. Local Allocation Global replacement process selects a replacement frame from the set of all frames; one process can take a frame from another But then process execution time can vary greatly But greater throughput so more common Local replacement each process selects from only its own set of allocated frames More consistent per-process performance But possibly underutilized memory 9.17 Silberschatz, Galvin and Gagne 2013

Non-Uniform Memory Access So far all memory accessed equally Many systems are NUMA speed of access to memory varies Consider system boards containing CPUs and memory, interconnected over a system bus Optimal performance comes from allocating memory close to the CPU on which the thread is scheduled And modifying the scheduler to schedule the thread on the same system board when possible Solved by Solaris by creating lgroups Structure to track CPU / Memory low latency groups Used my schedule and pager When possible schedule all threads of a process and allocate all memory for that process within the lgroup 9.18 Silberschatz, Galvin and Gagne 2013

Thrashing If a process does not have enough pages, the page-fault rate is very high Page fault to get page Replace existing frame But quickly need replaced frame back This leads to: Low CPU utilization Operating system thinking that it needs to increase the degree of multiprogramming Another process added to the system Thrashing a process is busy swapping pages in and out 9.19 Silberschatz, Galvin and Gagne 2013

Thrashing (Cont.) 9.20 Silberschatz, Galvin and Gagne 2013

Demand Paging and Thrashing Why does demand paging work? Locality model A locality is a set of pages actively used together Process migrates from one locality to another Localities may overlap Localities are defined by the program structure and its data structure Why does thrashing occur? size of locality > total memory size Limit effects by using local or priority page replacement 9.21 Silberschatz, Galvin and Gagne 2013

Locality In A Memory-Reference Pattern 34 32 30 28 page numbers memory address 26 24 22 20 18 execution time 9.22 Silberschatz, Galvin and Gagne 2013

Working-Set Model working-set window a fixed number of page references Example: 10,000 instructions WSS i (working set of Process P i ) = total number of pages referenced in the most recent (varies in time) if too small will not encompass entire locality if too large will encompass several localities if = will encompass entire program D = WSS i total demand frames Approximation of locality if D > m Thrashing Policy if D > m, then suspend or swap out one of the processes 9.23 Silberschatz, Galvin and Gagne 2013

Keeping Track of the Working Set Approximate the working-set model with interval timer + a reference bit Example: = 10,000 Timer interrupts after every 5000 time units Keep in memory 2 bits for each page Whenever a timer interrupts copy and sets the values of all reference bits to 0 If one of the bits in memory = 1 page in working set Why is this not completely accurate? Improvement = 10 bits and interrupt every 1000 time units 9.24 Silberschatz, Galvin and Gagne 2013

Page-Fault Frequency More direct approach than WSS Establish acceptable page-fault frequency (PFF) rate and use local replacement policy If actual rate too low, process loses frame If actual rate too high, process gains frame 9.25 Silberschatz, Galvin and Gagne 2013

Working Sets and Page Fault Rates n n n Direct relationship between working set of a process and its page-fault rate Working set changes over time Peaks and valleys over time 9.26 Silberschatz, Galvin and Gagne 2013