Lecture 14 Page Replacement Policies

Similar documents
CS370 Operating Systems

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Basic Page Replacement

Memory - Paging. Copyright : University of Illinois CS 241 Staff 1

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

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

Page replacement algorithms OS

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Memory Management Ch. 3

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

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

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

Page Replacement Algorithms

Principles of Operating Systems

Memory management, part 2: outline

CS 153 Design of Operating Systems Winter 2016

Virtual Memory Management

Operating Systems Lecture 6: Memory Management II

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

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

CS370 Operating Systems

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

Module 9: Virtual Memory

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

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

Virtual Memory Design and Implementation

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

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

Where are we in the course?

Module 9: Virtual Memory

Chapter 10: Virtual Memory. Background

Virtual Memory III. Jo, Heeseung

Chapter 9: Virtual Memory

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

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

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

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

CSE 120 Principles of Operating Systems

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

Clock page algorithm. Least recently used (LRU) NFU algorithm. Aging (NFU + forgetting) Working set. Process behavior

Virtual Memory Outline

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

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

Operating Systems. Operating Systems Sina Meraji U of T

Chapter 4 Memory Management

Chapter 8 Virtual Memory

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

Chapter 9: Virtual Memory

Chapter 9: Virtual-Memory

CS450/550 Operating Systems

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

CS510 Operating System Foundations. Jonathan Walpole

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

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

Lecture 12: 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 9: Virtual Memory. Chapter 9: Virtual Memory. Objectives. Background. Virtual-address address Space

CSE 153 Design of Operating Systems

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

CS370 Operating Systems

Operating System Concepts

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

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

Chapter 4 Memory Management. Memory Management

Virtual Memory COMPSCI 386

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

CS 4284 Systems Capstone

VIRTUAL MEMORY READING: CHAPTER 9

10: Virtual Memory Management

Operating Systems, Fall

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Chapter 8: Virtual Memory. Operating System Concepts

Memory Management Virtual Memory

Last Class: Demand Paged Virtual Memory

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

Week 2: Tiina Niklander

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

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

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 9: Virtual Memory

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

CS 550 Operating Systems Spring Memory Management: Page Replacement

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

Perform page replacement. (Fig 8.8 [Stal05])

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

Chapter 6: Demand Paging

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

OPERATING SYSTEM. Chapter 9: Virtual Memory

1. Background. 2. Demand Paging

UNIT - IV. What is 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

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

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

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

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

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

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

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

Transcription:

CS 423 Operating Systems Design Lecture 14 Page Replacement Policies Klara Nahrstedt Fall 2011 Based on slides by YY Zhou and Andrew S. Tanenbaum

Overview Administrative Issues Page Replacement Policies Read Tanenbaum Section 2.3.3. - 2.3.6

Review: Paging Policies Fetch Strategies When should a page be brought into primary (main) memory from secondary (disk) storage. Placement Strategies When a page is brought into primary storage, where is it to be put? Replacement Strategies Which page now in primary storage is to be removed from primary storage when some other page is to be brought in and there is not enough room.

Review: Page Cleaning Paging works best when there are plenty of free page frames that can be claimed as page fault occurs Page fault handling time includes swap out time if there is no free page Paging daemon (background process) Wakened up periodically to inspect memory If too few pages, the paging daemon begins selecting pages to evict using a page replacement algorithm

Review: Page Replacement 1. Find location of page on disk 2. Find a free page frame 1. If free page frame, use it 2. Otherwise, select a page frame using the page replacement algorithm 3. Write the selected page to the disk and update any necessary page table information 3. Read the requested page from the disk. 4. Restart the user process. (It is necessary to be careful of synchronization problems. For example, page faults may occur for pages being paged out.)

Issue: Page replacement algorithm Hopefully, kick out a less-useful page Dirty pages require writing, clean pages don t Hardware has a dirty bit for each page frame indicating this page has been updated or not Where do you write? To swap space Goal: kick out the page that s least useful Problem: how do you determine locality? Heuristic: temporal locality exists Kick out pages that aren t likely to be used again

Terminology Reference string: the memory reference sequence generated by a program. Paging moving pages to/from disk Eviction throwing something out Pollution bringing in useless pages/lines Optimal the best (theoretical) strategy (This does not mean no page fault.)

Principal of Optimality Description (Belady s algorithm): Assume that each page can be labeled with the number of instructions that will be executed before that page is first references, i.e., we would know the future reference string for a program. Then the optimal page algorithm would choose the page with the highest label to be removed from the memory. This algorithm provides a basis for comparison with other schemes. Impractical because it needs future references If future references are known should not use demand paging should use pre paging to allow paging to be overlapped with computation.

Optimal Example 12 references, 7 faults 7 3 2 5 3 2 3 2

FIFO 12 references, 9 faults

Belady's Anomaly (for FIFO) Possible to have more page faults in FIFO when number of page frames increases 12 references, 10 faults (Reference) http://dl.acm.org/citation.cfm?doid=363011.363155

Why Belady's Anomaly exists?

LRU (Least Recently Used) 12 references, 10 faults

Least Recently Used Issues Does not suffer from Belady's anomaly How to track recency? use time record time of reference with page table entry use counter as clock (e.g., increment by one) search for smallest time. use stack remove reference of page from stack (linked list) push it on top of stack (for every memory access) Both approaches require large processing overhead, more space, and HW support.

LRU and Anomalies Anomalies cannot occur, why? 12 references, 8 faults

NRU: A LRU Approximation NRU: Evict a page that is NOT recently used NRU implementation: simpler than LRU Two status bits per page R: Reference (when read or written) D: Dirty (only when written) Periodically, R bit is cleared to track the recency. A page in the lowest class is replaced. 1. (0,0) neither referenced nor dirtied 2. (0,1) not referenced (recently) but dirtied 3. (1,0) referenced but clean 4. (1,1) referenced and dirtied If conflict, use random or FIFO. Any impact on the system reliability? (e.g., bd/pdflush in Linux) Still require large processing overhead and HW support.

Second Chance Page loaded first A* B C* D* B C* D* C* D* A E* New page A The most recently loaded Treated likely a newly loaded page Only one reference (R) bit per page. Pages are kept in FIFO order using a circular list. Choose victim to evict Select head of FIFO If page has R bit set, reset bit and select next page in FIFO list. keep processing until reach a page with zero reference bit and page that one out. Does this algorithm always terminate?

Clock A* A D* B E C* Clock replacement algorithm addresses the inefficient of second change (i.e., constantly move pages around on its list) When a page fault occurs, the page pointed by the clock hand is inspected. If R = 0, the page is evicted If R = 1, it s cleared and the hand is advanced.

Page Fault Rate Curve As page frames per VM space decrease, the page fault rate increases.

Working Set (Denning) The working set model assumes locality. The principle of locality states that a program clusters its access to data and text temporally. As the number of page frames increases above some threshold, the page fault rate will drop dramatically.

Thrashing As page frames decrease, the page frames available are not large enough to contain the locality of the process (or working set). The processes start faulting heavily. Pages that are read in, are used and immediately paged out.

Thrashing and CPU Utilization As the page fault rate goes up, processes get suspended on page out queues for the disk. The system may try to optimize performance by starting new jobs. Starting new jobs will reduce the number of page frames available to each process, increasing the page fault requests. System throughput plunges.

Page Fault Frequency Version of Working Set Assume that if the working set is correct there will not be many page faults. PFF (Page fault frequency) algorithm If page fault rate increases beyond assumed knee of curve, then increase number of page frames available to process. If page fault rate decreases below foot of knee of curve, then decrease number of page frames available to process.

Working Set Model Try to keep track of each process working set If # free physical pages > working set of some suspended process, activate the process and map in all its working set If working set size of some process increases and no page frame is free, suspend the process and release all its pages (Definition) Working set is the set of pages used in the k most recent memory references (Approximation) set of pages referenced during the past t seconds of virtual CPU time

WS Page Replacement Example Approximate WS model uses a timer to interrupt after approximately x references,, and remove pages that have not been referenced and reset reference bit. Window size is = 4 12 references, 8 faults

http://dl.acm.org/citation.cfm?id=806596 WSClock (Carr and Hennessey 1981) Used very widely Circular list as in the clock algorithm. Initially, list is empty. As pages are loaded into memory, pages are added to the list Each entry contains time of last use as well as reference and dirty bits. Algorithm At each page fault, the page pointed to by the clock hand is examined. If R-bit = 1, keep and advance to the next page. If R-bit is 0, check if it is in working set window (i.e., if current time - time of last use is less than the working set window size time). If page is not in the working set and the page is clean, claim it (no disk I/O). If the page is not in working set and page is dirty, request write to disk.

Allocation Policy How memory should be allocated among processes? Local page replacement: allocating every process a fixed fraction of the memory (fairness) Global: dynamically allocate page frames among the processes (efficient) In general, global algo. works better as the WS size varies. Allocate an equal number of frames per job But jobs use memory unequally, high priority jobs have the same number of pages as low priority jobs, and degree of multiprogramming might vary Allocate physical pages proportional to job size Challenge: how do you determine job size: by run command parameters or dynamically? PFF (Page fault frequency) algorithm: Measure page fault rate of each process to increase or decrease a process s page allocation

Conclusion The Principle of Optimality Replace the page that will not be used in the farthest future Not implementable but useful for benchmarking FIFO - First in First Out Might throw out important pages LRU - Least Recently Used Excellent, but difficult to implement exactly NRU - Not Recently Used Very crude approximation of LRU Second Change Big improvement over FIFO by considering recency Clock Realistic Working Set Somewhat expensive to implement WSClock Good efficient algorithm