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

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

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

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

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

Basic Page Replacement

CS 153 Design of Operating Systems Winter 2016

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

Page Replacement Algorithms

CSE 120 Principles of Operating Systems

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

Module 9: Virtual Memory

Virtual Memory - I. Roadmap. Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

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

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

CSE 153 Design of Operating Systems

Module 9: Virtual Memory

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

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

Virtual Memory III. Jo, Heeseung

Lecture 12: Demand Paging

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

CS370 Operating Systems

Operating Systems. Operating Systems Sina Meraji U of T

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

CS370 Operating Systems

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

Principles of Operating Systems

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

Chapter 9: Virtual-Memory

Operating System Concepts

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

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

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Chapter 10: Virtual Memory. Background

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

CSE 421/521 - Operating Systems Fall Lecture - XII Main Memory Management. Tevfik Koşar. University at Buffalo. October 18 th, 2012.

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

Where are we in the course?

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

Chapter 9: Virtual Memory

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

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

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

Last Class: Demand Paged Virtual Memory

Chapter 8: Virtual Memory. Operating System Concepts

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

CS370 Operating Systems

Chapter 9: Virtual Memory

VIRTUAL MEMORY READING: CHAPTER 9

CS420: Operating Systems

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

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

Memory management, part 2: outline

Chapters 9 & 10: Memory Management and Virtual Memory

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

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

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

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XI Deadlocks - II. University at Buffalo. Deadlocks. October 6 th, 2011

Virtual Memory Management

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

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

Chapter 9: Virtual Memory

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

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

First-In-First-Out (FIFO) Algorithm

Chapter 6: Demand Paging

Lecture 14 Page Replacement Policies

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

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

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

Virtual Memory Outline

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

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

CSE 421/521 - Operating Systems Fall Lecture - VII CPU Scheduling - II. University at Buffalo

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

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

1. Background. 2. Demand Paging

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

Roadmap. Deadlock Prevention. Deadlock Prevention (Cont.) Deadlock Detection. Exercise. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

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

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

CS370 Operating Systems

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

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

Operating Systems Lecture 6: Memory Management II

Operating Systems (1DT020 & 1TT802) Lecture 9 Memory Management : Demand paging & page replacement. Léon Mugwaneza

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

Basic Memory Management

Virtual Memory Design and Implementation

Operating System Concepts 9 th Edition

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

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

Chapter 10: Virtual Memory

CS307: Operating Systems

Virtual Memory COMPSCI 386

Transcription:

CSE 421/521 - Operating Systems Fall 2012 Lecture - XVI Virtual Memory - II Tevfik Koşar University at Buffalo October 25 th, 2012 1 Roadmap Virtual Memory Page Replacement Algorithms Optimal Algorithm Least Recently Used (LRU) LRU Approximations Counting Algorithms Allocation Policies Thrashing Working Set Model

FIFO FIFO is obvious, and simple to implement when you page in something, put it on the tail of a list evict page at the head of the list Why might this be good? maybe the one brought in longest ago is not being used Why might this be bad? then again, maybe it is being used have absolutely no information either way In fact, FIFO s performance is typically lousy In addition, FIFO suffers from Belady s Anomaly there are reference strings for which the fault rate increases when the process is given more physical memory 3 Optimal Algorithm Replace page that will not be used for the longest time in future 4 frames example 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

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 would you know this in advance? Optimal (Belady s) Algorithm Provably optimal: lowest fault rate (remember SJF?) evict the page that won t be used for the longest time in future problem: impossible to predict the future Why is Belady s Optimal algorithm useful? as a yardstick to compare other algorithms to optimal if Belady s isn t much better than yours, yours is pretty good how could you do this comparison? Is there a best practical algorithm? no; depends on workload Is there a worst algorithm? no, but random replacement does pretty badly there are some other situations where OS s use near-random algorithms quite effectively! 6

Least Recently Used (LRU) Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Least Recently Used (LRU) Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 5 2 3 5 4 4 3

Least Recently Used (LRU) LRU uses reference information to make a more informed replacement decision idea: past experience gives us a guess of future behavior on replacement, evict the page that hasn t been used for the longest amount of time LRU looks at the past, Belady s wants to look at future How is LRU different from FIFO? Implementation to be perfect, must grab a timestamp on every memory reference, then order or search based on the timestamps way too costly in memory bandwidth, algorithm execution time, etc. so, we need a cheap approximation LRU Implementations 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 No search for replacement

LRU Approximation Algorithms Reference bit With each page associate a bit, initially = 0 When page is referenced bit set to 1 Replace the one which is 0 (if one exists). We do not know the order, however. Additional Reference bits 1 byte for each page: eg. 00110011 Shift right at each time interval LRU Clock Algorithm AKA Not Recently Used (NRU) or Second Chance replace page that is old enough logically, arrange all physical page frames in a big circle (clock) just a circular linked list a clock hand is used to select a good LRU candidate sweep through the pages in circular order like a clock if ref bit is off, it hasn t been used recently, we have a victim so, what is minimum age if ref bit is off? if the ref bit is on, turn it off and go to next page arm moves quickly when pages are needed low overhead if have plenty of memory if memory is large, accuracy of information degrades add more hands to fix

Second-Chance (clock) Page-Replacement Algorithm Counting Algorithms Keep a counter of the number of references that have been made to each page LFU Algorithm: replaces page with smallest count MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used

Allocation of Frames Each process needs minimum number of pages Two major allocation schemes fixed allocation priority allocation 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

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 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 Local replacement each process selects from only its own set of allocated frames

Thrashing If a process does not have enough frames, the page-fault rate is very high. This leads to: Replacement of active pages which will be needed soon again! Thrashing a process is busy swapping pages in and out Which will in turn cause: low CPU utilization operating system thinks that it needs to increase the degree of multiprogramming another process added to the system Thrashing (Cont.)

Locality in a Memory-Reference Pattern Working-Set Model Δ 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 Δ (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 if D > m Thrashing Policy if D > m, then suspend one of the processes

Working-set model Exercise Consider the following page-reference string: 1, 2, 3, 4, 4, 3, 2, 1, 5, 6, 2, 1, 2, 3, 7, 8, 3, 2, 1, 5 Assuming 4 memory frames and LFU, LRU, or Optimal page replacement algorithms, how many page faults, page hits, and page replacements would occur? Show your page assignments to frames. 24

Summary Virtual Memory Page Replacement Algorithms Optimal Algorithm Least Recently Used (LRU) LRU Approximations Counting Algorithms Allocation Policies Thrashing Working Set Model Hmm.. Next Lecture: Project 2 Discussion Reading Assignment: Chapter 9 from Silberschatz. Acknowledgements Operating Systems Concepts book and supplementary material by A. Silberschatz, P. Galvin and G. Gagne Operating Systems: Internals and Design Principles book and supplementary material by W. Stallings Modern Operating Systems book and supplementary material by A. Tanenbaum R. Doursat and M. Yuksel from UNR Gribble, Lazowska, Levy, and Zahorjan from UW