Basic Page Replacement

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

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

Module 9: Virtual Memory

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

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

Page Replacement Algorithms

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

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

Chapter 9: Virtual-Memory

Chapter 9: Virtual Memory

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

CS370 Operating Systems

Chapter 10: Virtual Memory. Background

Chapter 9: Virtual Memory

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

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

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

CS370 Operating Systems

Where are we in the course?

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

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

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

Principles of Operating Systems

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

Operating System Concepts

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

Chapter 8: Virtual Memory. Operating System Concepts

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

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

CS420: Operating Systems

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

Chapter 9: Virtual Memory

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

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

First-In-First-Out (FIFO) Algorithm

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

Virtual Memory III. Jo, Heeseung

CS370 Operating Systems

Chapters 9 & 10: Memory Management and Virtual Memory

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

Lecture 14 Page Replacement Policies

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

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

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

Chapter 6: Demand Paging

Chapter 10: Virtual Memory

Virtual Memory COMPSCI 386

Operating System Concepts 9 th Edition

1. Background. 2. Demand Paging

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

SMD149 - Operating Systems - VM Management

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

Virtual Memory B: Objec5ves

Virtual Memory Outline

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

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

Memory management, part 2: outline

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

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

CS 153 Design of Operating Systems Winter 2016

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

UNIT - IV. What is virtual memory?

Operating Systems. Operating Systems Sina Meraji U of T

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

CS307: Operating Systems

CS370 Operating Systems

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

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

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

VIRTUAL MEMORY READING: CHAPTER 9

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

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

Lecture 12: Demand Paging

Operating System - Virtual Memory

CSE 153 Design of Operating Systems

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

OPERATING SYSTEM. Chapter 9: Virtual Memory

CSE 120 Principles of Operating Systems

Virtual Memory Design and Implementation

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

Readings and References. Virtual Memory. Virtual Memory. Virtual Memory VPN. Reading. CSE Computer Systems December 5, 2001.

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Chapter 9: Virtual Memory

Paging algorithms. CS 241 February 10, Copyright : University of Illinois CS 241 Staff 1

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

CS510 Operating System Foundations. Jonathan Walpole

Basic Memory Management

Perform page replacement. (Fig 8.8 [Stal05])

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

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

Chapter 4 Memory Management

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Operating Systems Lecture 6: Memory Management II

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

Practice Exercises 449

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Transcription:

Basic Page Replacement 1. Find the location of the desired page on disk 2. Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame 3. Allocate & read the desired page into the (newly) free frame. Update the page and frame tables. 4. Restart the process c.f., Use modify (dirty) bit to reduce overhead of page transfers only modified pages are written back into disk 9.1 Silberschatz, Galvin and Gagne 2009

Page Replacement 9.2 Silberschatz, Galvin and Gagne 2009

Page Replacement Algorithms We want the lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (called reference string) and computing the number of page faults on that string In all our examples, the reference string is 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 9.3 Silberschatz, Galvin and Gagne 2009

Graph of Page Faults vs. The Number of Frames : General Tendency 9.4 Silberschatz, Galvin and Gagne 2009

First-In-First-Out (FIFO) Algorithm FIFO page replacement Replace page that has been in the system the longest Can be implemented with relatively low overhead Evaluation Possible to replace heavily used pages Impractical for most systems 9.5 Silberschatz, Galvin and Gagne 2009

First-In-First-Out (FIFO) Algorithm Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 3 frames (3 pages can be in memory at a time per process) 1 1 4 5 2 2 1 3 9 page faults 4 frames 3 3 2 4 1 1 5 4 2 2 1 5 10 page faults 3 3 2 4 4 3 FIFO Replacement Belady s Anomaly more frames, on the contrary, result in more page faults. 9.6 Silberschatz, Galvin and Gagne 2009

FIFO Illustrating Belady s Anomaly 9.7 Silberschatz, Galvin and Gagne 2009

FIFO Page Replacement 9.8 Silberschatz, Galvin and Gagne 2009

Optimal Algorithm Replace page that will not be used for longest period of time 4 frames example 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 4 2 6 page faults 3 4 5 How do you know this? Used for measuring how well your algorithm performs 9.9 Silberschatz, Galvin and Gagne 2009

Optimal Page Replacement 9.10 Silberschatz, Galvin and Gagne 2009

Least Recently Used (LRU) Algorithm Exploits temporal locality by replacing the page that has spent the longest time in memory without being referenced Can provide better performance than FIFO Increased overhead of system implementation LRU can perform poorly if the least-recently used page is the next page to be referenced by a program E.g., iterating inside a loop that references several pages and iterating back to outside a loop 9.11 Silberschatz, Galvin and Gagne 2009

Least Recently Used (LRU) Algorithm Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 5 2 3 5 4 4 3 9.12 Silberschatz, Galvin and Gagne 2009

LRU Algorithm Implementation (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 determine which one should be changed Additional space overhead in page table for counter bit Also needs additional search (or sort) time to least recent entry in page table 9.13 Silberschatz, Galvin and Gagne 2009

LRU Algorithm Implementation (Cont.) Stack implementation keep a stack of page numbers in an array or a double link form Page referenced: move it to the top requires array movement or pointers to be changed Stack size overhead No search for replacement 9.14 Silberschatz, Galvin and Gagne 2009

Use of Stack to Record the Most Recent Page References expensive operation 9.15 Silberschatz, Galvin and Gagne 2009

LRU Approximation Algorithms Reference bit each page is associated with a reference bit, initially = 0 When page is referenced, the bit set to 1 That is, 0 bit indicate that no reference at all after allocation Replace the page which has reference bit value 0 (if one exists). Problems We do not know the exact order. Problem1, The page which is just brought in (set to 0) is not LRU candidate, but can be replaced. Problem2, The oldest brought entry (set to 0) with immediate re-reference (set to 1, eventually) is actually LRU, but can not be replaced. 9.16 Silberschatz, Galvin and Gagne 2009

LRU Approximation Algorithms Second Chance algorithm Also called as Clock Replacement Need reference bit If page to be replaced (in clock order) has reference bit = 1 then: set reference bit 0 leave page in memory replace next page (in clock order) if reference bit = 0 9.17 Silberschatz, Galvin and Gagne 2009

Second-Chance (clock) Page-Replacement Algorithm 9.18 Silberschatz, Galvin and Gagne 2009

LRU Approximation Algorithms NUR (Not Used Recently) algorithms A kind of LRU approximation Similar to LRU but low overhead Two additional hardware bits Reference bit and Modified bit Algorithm Search pages in which R=0, and replace one of them. If all pages R =1 then, Search M=0 and replace one of them. 9.19 Silberschatz, Galvin and Gagne 2009

Far Page Replacement Creates an access graph that characterizes a process s reference patterns Replace the unreferenced page that is furthest away from any referenced page in the access graph Performs at near-optimal levels Has not been implemented in real systems Access graph is complex to search and manage without hardware support 9.20 Silberschatz, Galvin and Gagne 2009

Far Page Replacement 9.21 Silberschatz, Galvin and Gagne 2009

Count based Replacement Algorithms Keep a counter of the number of references that have been made to each page LFU Algorithm: replaces page with smallest count Page which is just fetched could possibly be replaced. 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.22 Silberschatz, Galvin and Gagne 2009

Count based Replacement Algorithms Replacement Algorithm Confliction LFU vs. MFU LRU vs. LFU with reference string 1 1 1 1 1 2 3 4 LRU : entry 1 is candidate to replace LFU : entry 1 is the most frequent entry 9.23 Silberschatz, Galvin and Gagne 2009

Allocation of Frames Each process needs at least minimum number of pages Two major allocation schemes fixed allocation priority allocation 9.24 Silberschatz, Galvin and Gagne 2009

Fixed Allocation Equal allocation For example, if there are 100 frames and 5 processes, give each process 20 frames. Proportional allocation Allocate according to the size of process si = size of process pi ; Size of virtual memory for process S = s a i i m = total number of = allocation for m = 64 s s a a i 2 1 2 = 10 = 127 p i frames si = m S 10 = 64 5 137 127 = 64 59 137 9.25 Silberschatz, Galvin and Gagne 2009

Priority Allocation Use a proportional allocation scheme using priorities rather than size 9.26 Silberschatz, Galvin and Gagne 2009

Global vs. Local Page Replacement If process P i generates a page fault, select for replacement page within its frames select for replacement a frame from other process frame with lower priority number Global replacement process selects a replacement frame from the set of all frames; one process can take a frame from another Local replacement each process selects from only its own set of allocated frames 9.27 Silberschatz, Galvin and Gagne 2009

Thrashing If a process does not have enough pages, the page-fault rate is very high. This leads to: low CPU utilization operating system thinks 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.28 Silberschatz, Galvin and Gagne 2009

Thrashing (Cont.) 9.29 Silberschatz, Galvin and Gagne 2009

Demand Paging and Thrashing Why does demand paging work? Locality model Process migrates from one locality to another Localities may overlap Why does thrashing occur? Σ size of locality > required memory size in total i.e., unbalance between locality size and the number of properly required page frames 9.30 Silberschatz, Galvin and Gagne 2009

Locality In A Memory-Reference Pattern 9.31 Silberschatz, Galvin and Gagne 2009

Working-Set Model Working set : number of page frames for a process Δ working-set window a fixed number of page references Example: 10,000 instruction WSS i (working set of Process P i ) = total number of pages referenced in the most recent working-set windows Δ (it may vary 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 (i.e., total sum of demand frames for each process) Let m be the total number of available frame if D > m Thrashing Need policy if D > m, then suspend one of the processes 9.32 Silberschatz, Galvin and Gagne 2009

Working-set model Here shows the difficulty of finding proper WS(t i ). 9.33 Silberschatz, Galvin and Gagne 2009

Working-set vs. Page Fault Rates 9.34 Silberschatz, Galvin and Gagne 2009

Approximation of Working-Set Model Example Δ = 10,000 Timer interrupts happen after every 5000 references Maintains 2 bit-wide reference bits for each page in page table Operation When we get a timer interrupt, we clear all reference bits for each page Future reference of processor will make the reference bit as one again If one of reference bits in memory = 1 the page is IN the working set Why is this not completely accurate? We cannot tell where, within an interval, the reference happens. Improvement Precise operation such as 10 reference bits and interrupt every 1000 time units. Cost to service will be correspondingly higher. 9.35 Silberschatz, Galvin and Gagne 2009

Page-Fault Frequency Scheme Another strategy to handle the thrashing : PFF (Page Fault Frequency) Establish acceptable page-fault rate for each process If actual rate too high, process gains frame If actual rate too low, process has too many frames so it loses frame to provide other process utilization. 9.36 Silberschatz, Galvin and Gagne 2009