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

Similar documents
CS 153 Design of Operating Systems Winter 2016

CSE 120 Principles of Operating Systems

CSE 153 Design of Operating Systems

Lecture 12: Demand Paging

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Reminder: Mechanics of address translation. Paged virtual memory. Reminder: Page Table Entries (PTEs) Demand paging. Page faults

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Virtual Memory III. Jo, Heeseung

Operating Systems. Operating Systems Sina Meraji U of T

VIRTUAL MEMORY READING: CHAPTER 9

EvicMng the best page #2: FIFO. #1: Belady s Algorithm. CS 537 Lecture 11 Page Replacement Policies 11/1/11. Michael SwiF

CS 153 Design of Operating Systems Spring 18

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

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

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

Virtual Memory Design and Implementation

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

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

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

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 15: Caching: Demand Paged Virtual Memory

Lecture 14 Page Replacement Policies

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

Virtual Memory Design and Implementation

Basic Page Replacement

Page replacement algorithms OS

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

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

Page Replacement Algorithms

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

Virtual Memory Design and Implementation

Virtual Memory Management

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Page Replacement. (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018

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

CS370 Operating Systems

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

Chapter 9: Virtual-Memory

SMD149 - Operating Systems - VM Management

! What is virtual memory and when is it useful? ! What is demand paging? ! What pages should be. ! What is the working set model?

Chapter 9: Virtual Memory

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

Last Class: Demand Paged Virtual Memory

CS370 Operating Systems

10: Virtual Memory Management

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

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

Past: Making physical memory pretty

Lecture#16: VM, thrashing, Replacement, Cache state

Last Class. Demand Paged Virtual Memory. Today: Demand Paged Virtual Memory. Demand Paged Virtual Memory

CS370 Operating Systems

Virtual Memory. Chapter 8

Module 9: Virtual Memory

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

Memory management, part 2: outline

Principles of Operating Systems

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

Chapter 6: Demand Paging

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

Memory: Paging System

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

CS510 Operating System Foundations. Jonathan Walpole

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

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory

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

Virtual Memory COMPSCI 386

Module 9: Virtual Memory

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

Chapter 4 Memory Management

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

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

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

Operating System Concepts

CS420: Operating Systems

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

a process may be swapped in and out of main memory such that it occupies different regions

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

Page 1. Goals for Today" TLB organization" CS162 Operating Systems and Systems Programming Lecture 11. Page Allocation and Replacement"

CS370 Operating Systems

Role of OS in virtual memory management

Operating Systems Lecture 6: Memory Management II

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.

Address spaces and memory management

How to create a process? What does process look like?

Chapter 8 Virtual Memory

Today. Adding Memory Does adding memory always reduce the number of page faults? FIFO: Adding Memory with LRU. Last Class: Demand Paged Virtual Memory

Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory CS 111. Operating Systems Peter Reiher

Memory Management: Virtual Memory and Paging CS 111. Operating Systems Peter Reiher

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

Chapter 8 Virtual Memory

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

ECE519 Advanced Operating Systems

3/3/2014! Anthony D. Joseph!!CS162! UCB Spring 2014!

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

Basic Memory Management

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

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

Transcription:

3/14/2001 1 All Paging Schemes Depend on Locality VM Page Replacement Emin Gun Sirer Processes tend to reference pages in localized patterns Temporal locality» locations referenced recently likely to be referenced again Spatial locality» locations near recently referenced locations are likely to be referenced soon.» Goal of a paging system is stay out of the way when there is plenty of available memory don t bring the system to its knees when there is not. 3/14/2001 2 Demand Paging Paging Demand Paging refers to a technique where program pages are loaded from disk into memory as they are referenced. Each reference to a page not previously touched causes a page fault. The fault occurs because the reference found a page table entry with its valid bit off. As a result of the page fault, the OS allocates a new page frame and reads the faulted page from the disk. When the I/O completes, the OS fills in the PTE, sets its valid bit, and restarts the faulting process. Demand paging» don t load page until absolutely necessary» commonly used in most systems» doing things one at a time can be slower than batching them. Prepaging» anticipate fault before it happens» overlap fetch with computation» hard to predict the future» some simple schemes (hints from programmer or program behavior) can work. vm_advise larger virtual page size sequential pre-paging from mapped files 3/14/2001 3 3/14/2001 4

3/14/2001 5 High Level Page Replacement Imagine that when a program starts, it has: no pages in memory a page table with all valid bits off The first instruction to be executed faults, loading the first page. Instructions fault until the program has enough pages to execute for a while. It continues until the next page fault. Faults are expensive, so once the program is running they should not occur frequently, assuming the program is well behaved (has good locality). When a fault occurs, the OS loads the faulted page from disk into a page of memory. At some point, the process has used all of the page frames it is allowed to use. When this happens, the OS must replace a page for each page faulted in. That is, it must select a page to throw out of primary memory to make room. How it does this is determined by the page replacement algorithm. The goal of the replacement algorithm is to reduce the fault rate by selecting the best victim page to remove. 3/14/2001 6 Finding the Best Page Optimal Algorithm A good property» if you put more memory on the machine, then your page fault rate will go down.» Increasing the size of the resource pool helps everyone. The best page to toss out is the one you ll never need again» that way, no faults. Never is a long time, so picking the one closest to never is the next best thing.» Replacing the page that won t be used for the longest period of time absolutely minimizes the number of page faults.» Example: 3/14/2001 7 The optimal algorithm, called Belady s algorithm, has the lowest fault rate for any reference string. Basic idea: replace the page that will not be used for the longest time in the future. Basic problem: phone calls to psychics are expensive. Basic use: gives us an idea of how well any implementable algorithm is doing relative to the best possible algorithm.» compare the fault rate of any proposed algorithm to Optimal» if Optimal does not do much better, then your proposed algorithm is pretty good.» If your proposed algorithm doesn t do much better than Random, go home. 3/14/2001 8

3/14/2001 9 Evaluating Replacement Policies FIFO execution time Random LRU Opt Few frames Up here, forget it. Effective Access.Time = (1-p)*Tm + p*td Tm = time to access main memory Td = time to fault Execution time = (roughly) #memory refs * E.A.T. In here, you can expect to have some effect. # of physical page frames Lots of frames Down in this range, it doesn t matter so much what you do. FIFO is an obvious algorithm and simple to implement. Basic idea, maintain a list or queue of pages in the order in which they were paged into memory. On replacement, remove the one brought in the longest time ago. Why might it work?» Maybe the one brought in the longest ago is one we re not using now. Why it might not work?» Maybe it s not.» We have no real information to tell us if it s being used or not. FIFO suffers from Belady s anomaly» the fault rate might actually increase when the algorithm is given more memory -- a bad property. was faulted a long time ago. was faulted recently 3/14/2001 10 An Example of Optimal and FIFO in Action Least Recently Used (LRU) A B C D A B C Reference stream is A B C A B D A D B C OPTIMAL A B C A B D A D B C B FIFO 5 Faults toss C toss A or D A B C A B D A D B C B 7 Faults toss A toss? Basic idea: we can t look into the future, but let s look at past experience to make a good guess. LRU: on replacement, remove the page that has not been used for the longest time in the past. Implementation: to really implement this, we would need to time stamp every reference, or maintain a stack that s updated on every reference. This would be too costly. So, we can t implement this exactly, but we can try to approximate it.» why is an approximate solution totally acceptable? was least recently used. was most recently used. Our bet is that pages which you used recently are ones which you will use again (principle of locality) and, by implication, those that you didn t, you won t. 3/14/2001 11 3/14/2001 12

3/14/2001 13 Using the Reference Bit Various LRU approximations use the PTE reference bit. keep a counter for each page at regular intervals, do: for every page: if ref bit = 0, increment its counter if ref bit = 1, zero its counter zero the reference bit the counter will thus contain the number of intervals since the last reference to the page. the page with the largest counter will be least recently used one. If we don t have a reference bit, we can simulate it using the VALID bit and taking a few extra faults.» therefore want impact when there is plenty of memory to be low. LRU Clock (Not Recently Used) Basic idea is to reflect the passage of time in the actual data structures and sweeping method. Arrange all of physical pages in a big circle (a clock). A clock hand is used to select a good LRU candidate:» sweep through the pages in circular order like a clock.» if the ref bit is off, it s a good page.» else, turn the ref bit off and try next page. Arm moves quickly when pages are needed. Low overhead when plenty of memory If memory is big, accuracy of information degrades.» add in additional hands 3/14/2001 14 P0 P1 P2 Fixed Space Vs. Variable Space In a multiprogramming system, we need a way to allocate memory to the competing processes.» Question is: how to determine how much memory to give to each process? In a fixed-space algorithm each process is given a limit of pages it can use; when it reaches its limit, it starts replacing new faults with its own pages. This is called local replacement.» some processes may do well while others suffer. In variable-spaced algorithms, each process can grow or shrink dynamically, displacing other process pages. This is global replacement.» one process can ruin it for the rest. 3/14/2001 15 Working Set Model Peter Denning defined the working set of a program as a way to model the dynamic locality of a program in execution. Definition: WS(t,w) = {pages i s.t. i was referenced in the interval (t,t-w)} t is a time, w is the working set window, a backward looking interval,measured in references. So, a page is in the WS only if it was referenced in the last w references. 3/14/2001 16

3/14/2001 17 references w Working Set Size t time The working set size is the number of pages in the working set; i.e., the number of pages touched in the interval (t, t- w). The working set size changes with program locality.» during periods of poor locality, you reference more pages.» so, within that period of time, you will have a larger working set size. For some parameter w, we could keep the working sets of each process in memory. Don t run process unless working set is in memory. WS But, we have two problems: how do we select w? how do we know when the working set changes? So, working set is not used in practice. 3/14/2001 18 Page Fault Frequency What do you do to pages? PFF is a variable space algorithm that uses a more ad hoc approach. Basic idea: monitor the fault rate for each process if the fault rate is above a high threshold, give it more memory should fault less but it doesn t always if the rate is below a low threshold, take away memory should fault more but it doesn t always Hard to tell between changes in locality and changes in size of working set. Fault Rate TIME 3/14/2001 19 If the page is dirty, you have to write it out to disk.» record the disk block number for the page in the PTE. If the page is clean, you don t have to do anything.» just overwrite the page with new data» make sure you know where the old copy of the page came from Want to avoid THRASHING» When a paging algorithm breaks down» Most of the OS time spent in ferrying pages to and from disk» no time spent doing useful work.» the system is OVERCOMMITTED no idea what pages should be resident in order to run effectively» Solutions include: SWAP Buy more memory 3/14/2001 20