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

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

CS370 Operating Systems

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

CS370 Operating Systems

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

CS 153 Design of Operating Systems Winter 2016

Operating Systems Lecture 6: Memory Management II

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

CSE 153 Design of Operating Systems

Page Replacement Algorithms

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

Page replacement algorithms OS

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

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

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

CSE 120 Principles of Operating Systems

Last Class: Demand Paged Virtual Memory

Basic Page Replacement

1. Background. 2. Demand Paging

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

CS510 Operating System Foundations. Jonathan Walpole

Lecture 14 Page Replacement Policies

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

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

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

CS370 Operating Systems

Chapter 9: Virtual Memory

VIRTUAL MEMORY READING: CHAPTER 9

Lecture 12: Demand Paging

Memory management, part 2: outline

Virtual Memory III. Jo, Heeseung

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

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

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

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

Principles of Operating Systems

Where are we in the course?

Operating System Concepts

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

Operating System - Virtual Memory

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

Basic Memory Management

Virtual Memory Design and Implementation

Chapter 10: Virtual Memory. Background

Perform page replacement. (Fig 8.8 [Stal05])

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

Virtual Memory Management

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

Chapter 9: Virtual Memory

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Operating Systems, Fall

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

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Module 9: Virtual Memory

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

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

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

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

Virtual Memory Design and Implementation

Operating Systems. Operating Systems Sina Meraji U of T

Week 2: Tiina Niklander

Module 9: Virtual Memory

Virtual Memory COMPSCI 386

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

CSE 4/521 Introduction to Operating Systems. Lecture 27 (Final Exam Review) Summer 2018

CS 550 Operating Systems Spring Memory Management: Page Replacement

Roadmap. Handling large amount of data efficiently. Stable storage. Parallel dataflow. External memory algorithms and data structures

Chapter 9: Virtual Memory

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

Paging and Page Replacement Algorithms

VIRTUAL MEMORY. Maninder Kaur. 1

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

Chapter 9: Virtual Memory

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

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

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

Chapter 8: Virtual Memory. Operating System Concepts

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

CS 4284 Systems Capstone

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

Memory Management Ch. 3

Chapter 4 Memory Management

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

First-In-First-Out (FIFO) Algorithm

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

MODERN OPERATING SYSTEMS. Chapter 3 Memory Management

Computer Systems II. Memory Management" Subdividing memory to accommodate many processes. A program is loaded in main memory to be executed

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

Virtual Memory Design and Implementation

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

SMD149 - Operating Systems - VM Management

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

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

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

Paging Policies, Load control, Page Fault Handling, Case studies January WT 2008/09

Virtual Memory Outline

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

Transcription:

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

Today Algorithm that approximates the OPT replacement algorithm. 2

Least Recently Used (LRU) Page Replacement A recently used page is likely to be used again in the future. Replace the page that has not been used for the longest period of time. Use the recent past as an approximation of the near future. Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 5 2 3 5 4 4 3 3

Distinguish recently used from not recently used pages Counters Each page-table entry is associated with a time-of-use field. Add to the CPU a logical clock. The clock is incremented at every memory access. At every memory access, the field of the referenced page is updated with the clock. Scan the page table to find the LRU page. Stack Whenever a page is referenced, it is removed from the stack and put on the top. The LRU page is always at the bottom. The update is expensive.

LRU: Clock Algorithm Each page entry is associated with a reference bit. Set on use, reset periodically by the OS. Algorithm: Scan: if ref bit is 1, set to 0, and proceed. If ref bit is 0, stop and evict. Problem: Low accuracy for large memory R=0 R=0 R=0 R=0 R=0 5

LRU: Clock Algorithm Solution: Add another hand Leading edge clears ref bits Trailing edge evicts pages with ref bit 0 What if angle small? What if angle big? R=0 R=0 R=0 R=0 R=0 6

Global vs Local Allocation Global replacement Single memory pool for entire system. On page fault, evict oldest page in the system. Problem: lack of performance isolation. Local (per-process) replacement Have a separate pool of pages for each process. Page fault in one process can only replace pages from its own process. Problem: might have idle resources. 7

Thrashing Excessive rate of page replacement Keep throwing out page that will be referenced soon. Keep referencing pages that are not in memory. Why does it occur? Too many processes in the system. How can we solve this problem? Locality model of process execution. A locality is a set of pages that are actively used together. 8

Working Set Estimate locality Identify useful pages Do not evict these pages, because they are likely to be referenced again. Working Set = An approximation of the program's locality. The set of pages in the most recent Δ page references. Δ: working-set window As a process executes, it moves from locality to locality. Example (Δ = 10): t1 WS = {1,2,5,6,7} t2 WS = {3,4} If allocated frames do not accommodate current locality, the process will thrash. 9

Computing the working set Working set = sets of pages in the working set window. Difficulty: the working set window is a moving window. At each memory reference: a new reference appears at one end -> the corresponding page should be marked as a member of the working set. The oldest reference drops off the other end -> the corresponding page should be unmarked.

Computing the working set 2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3 4 4 4 1 3 2 3 4 4 4 3 4 4 4 Δ t1 t2 t3 t4 t5 Δ=10 ti WS t1 {1,2,5,6,7} t2 {1,5,6,7} t3 {1,2,5,6,7} t4 {1,2,3,5,6,7} t5 {1,2,3,4,5,6,7} How can we compute WS without recording the reference history, but with specialized bits associated to page table entries? These bits signify whether a page belongs to the WS.

Computing the working set Each page table entry is associated with 1 reference bit and Δ WS-bits. At every page reference: Set the corresponding reference bit to 1. Update the working set: Shift WS-bits one bit to the right. Put reference bit to the most significant WS-bit. Reset reference bits to 0. If some WS-bits of a page are set to 1, then the page belongs to the WS. If all WS-bits of a page are 0, then the page does not belong to WS. This page can be evicted.

Computing the working set 2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3 4 4 4 1 3 2 3 4 4 4 3 4 4 4 Δ t1 t2 t3 t4 t5 Δ=10 Page number 1 2 3 4 5 6 7 WS WS-bits after access ti t1 t2 t3 t4 t5

Computing the working set 2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3 4 4 4 1 3 2 3 4 4 4 3 4 4 4 Δ t1 t2 t3 t4 t5 Δ=10 Page number WS-bits after access ti t1 t2 t3 t4 t5 1 1000000100 0100000010 0010000001 0001000000 0000100000 2 0000000001 0000000000 1000000000 0100000000 0010000000 3 0000000000 0000000000 0000000000 1000000000 0100000000 4 0000000000 0000000000 0000000000 0000000000 1000000000 5 0100001000 0010000100 0001000010 0000100001 0000010000 6 0000000010 1000000001 0100000000 0010000000 0001000000 7 0011110000 0001111000 0000111100 0000011110 0000001111 WS {1,2,5,6,7} {1,5,6,7} {1,2,5,6,7} {1,2,3,5,6,7} {1,2,3,4,5,6,7}

Working Set Approximation It is expensive to update the WS at every page reference. We can approximate the WS by updating it after Δ/n references. Need n WS-bits per page table entry. After Δ/n references there will be an interrupt. At every page reference: Set the corresponding reference bit to 1. At every interrupt: Update the working set: Shift WS-bits one bit to the right. Put reference bit to the most significant WS-bit of each page. Reset reference bits to 0. 15

Working Set Approximation 2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3 4 4 4 1 3 2 3 4 4 4 3 4 4 4 Δ t1 t2 t3 t4 t5 Δ=10, n=5 Page number 1 2 3 4 5 6 7 WS WS-bits after access ti t1 t3 t5

Working Set Approximation 2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3 4 4 4 1 3 2 3 4 4 4 3 4 4 4 Δ t1 t2 t3 t4 t5 Δ=10, n=5 Page number WS-bits after access ti t1 t3 t5 1 10010 01001 00100 2 00001 10000 01000 3 00000 00000 10000 4 00000 00000 10000 5 10010 01001 00100 6 00001 10001 01000 7 01100 00110 00011 WS {1,2,5,6,7} {1,2,5,6,7} {1,2,3,4,5,6,7}

Page Fault Frequency PFF = page faults / instructions executed. If PFF rises above threshold, process needs more memory. Not enough memory on the system? Swap out. If PFF sinks below threshold, memory can be taken away. 18

Working Sets and Page Fault Rates Working set Page fault rate transition stable 19

Today Algorithm that approximates the OPT replacement algorithm. 20

Coming up Next lecture: Review HW3: due today Exam2: Wednesday, last 30mis of class