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

Similar documents
Virtual Memory Design and Implementation

Virtual Memory Design and Implementation

Virtual Memory Design and Implementation

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

Page replacement algorithms OS

Perform page replacement. (Fig 8.8 [Stal05])

Chapter 4 Memory Management

Paging and Page Replacement Algorithms

Operating Systems Lecture 6: Memory Management II

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

CS510 Operating System Foundations. Jonathan Walpole

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

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

Memory Management Prof. James L. Frankel Harvard University

Week 2: Tiina Niklander

CS 550 Operating Systems Spring Memory Management: Page Replacement

Operating Systems, Fall

Memory management, part 2: outline

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

Virtual Memory III. Jo, Heeseung

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Chapter 4 Memory Management. Memory Management

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

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

CS 153 Design of Operating Systems Winter 2016

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

Lecture 14 Page Replacement Policies

CS450/550 Operating Systems

Lecture 12: Demand Paging

CSE 153 Design of Operating Systems

10: Virtual Memory Management

Memory: Paging System

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

CSE 120 Principles of Operating Systems

Operating Systems. Operating Systems Sina Meraji U of T

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

Virtual Memory Management

Memory Management. Memory Management. G53OPS: Operating Systems. Memory Management Monoprogramming 11/27/2008. Graham Kendall.

CS370 Operating Systems

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

Basic Page Replacement

Page Replacement Algorithms

CS370 Operating Systems

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

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

Memory Management Ch. 3

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

Chapter 8 Virtual Memory

Operating System Concepts

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

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

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

Motivation. Memory Management. Memory Management. Computer Hardware Review

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

CSE 380 Computer Operating Systems

Chapter 9: Virtual Memory

Memory management. Knut Omang Ifi/Oracle 10 Oct, 2012

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

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Last Class: Demand Paged Virtual Memory

OPERATING SYSTEM. Chapter 9: Virtual Memory

Operating Systems. User OS. Kernel & Device Drivers. Interface Programs. Memory Management

VIRTUAL MEMORY READING: CHAPTER 9

CS 4284 Systems Capstone

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

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

Chapter 10: Virtual Memory. Background

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

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

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

Module 9: Virtual Memory

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

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory Outline

First-In-First-Out (FIFO) Algorithm

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Chapter 9: Virtual Memory

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

CS370 Operating Systems

21 Lecture: More VM Announcements From last time: Virtual Memory (Fotheringham, 1961)

Virtual Memory COMPSCI 386

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

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

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

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University

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

Where are we in the course?

Chapter 9: Virtual Memory

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

Chapter 3 - Memory Management

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

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

Memory Management Virtual Memory

Transcription:

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

Reminder: virtual memory with paging! Hide the complexity let the OS do the job! Virtual address space split into pages! Physical memory split into page frames! Page & page frames = size (5B 64KB)! Map pages into page frames Doing the translation OS + MMU CPU package The CPU sends virtual addresses to the MMU CPU Memory management unit Memory Disk controller The MMU sends physical addresses to the memory Bus

Address translation with paging! Virtual to physical address Two parts virtual page number and offset Virtual page number index into a page table Page table maps virtual pages to page frames Managed by the OS One entry per page in virtual address space Physical address page number and offset Virtual address Virtual page # offset Physical memory Page frame Page table Page frame # Physical address Page frame # offset Page frame i Each process has its own page table Page frame N

Details of the MMU work! MMU with 6 4KB pages! Page # (first 4 bits) index into page table! If not there Page fault! Else Output register + bit offset 5 bit physical address Page number Offset 4

Page table entry! An opportunity there s a PTE lookup per memory reference, what else can we do with it?! Looking at the details Caching disable Present/absent D M R Prot. Page frame number Page frame number the most important field Protection bit for R&W or R or bits for RWX Present/absent bit Says whether or not the virtual address is used Modified (M): dirty bit Set when a write to the page has occurred Referenced (R): Has it being used? To ensure we are not reading from cache (D) Key for pages that map onto device registers rather than memory 5

Page replacement algorithms! OS uses main memory as (page) cache If only load when reference demand paging! Page fault cache miss Need room for new page? Page replacement algorithm What s your best candidate for removal? The one you will never touch again duh!! What do you do with victim page? A modified page must first be saved An unmodified one just overwritten Better not to choose an often used page It will probably need to be brought back in soon 6

How can any of this work?!?!! Locality Temporal locality location recently referenced tend to be referenced again soon Spatial locality locations near recently referenced are more likely to be referenced soon! Locality means paging could be infrequent Once you brought a page in, you ll use it many times Some issues that may play against you Degree of locality of application Page replacement policy and application reference pattern Amount of physical memory and application footprint 7

Optimal algorithm (Belady s algorithm)! For now, assume a process pages against itself, using a fixed number of page frames! Best page to replace the one you ll never need again Replace page needed at the farthest point in future Optimal but unrealizable! Estimate by Logging page use on previous runs of process Although impractical, useful for comparison Need room for this one,,, 4,,, 5,,,, 4, 5 Your ideal victim! 4 4 4 5 5 8

Not recently used (NRU) algorithm! Each page has Reference and Modified bits Set when page is referenced, modified R bit set means recently referenced, so you must clear it every now and then! Pages are classified R M Class How can this occur? Not referenced, not modified (, ) Not referenced, modified (, ) Referenced, but not modified (, ) Referenced and modified (, )! NRU removes page at random from lowest numbered, non-empty class! Easy to understand, relatively efficient to implement and sort-of OK performance 9

FIFO algorithm! Maintain a linked list of all pages in order of arrival! Victim is first page of list Maybe the oldest page will not be used again! Disadvantage But maybe it will the fact is, you have no idea! Increasing physical memory might increase page faults (Belady s anomaly) A, B, C, D, A, B, E, A, B, C, D, E A B A C B A D C B A D C B A D E B A E B A E B A C E B D C E D C E

Second chance algorithm! Simple modification of FIFO Avoid throwing out a heavily used page look at the R bit! Operation of second chance Pages sorted in FIFO order If page has been used, give it another chance move it to the end of the list of pages, clear R and update its timestamp Page list if fault occurs at time, A has R bit set (time is loading time) Most recently loaded Oldest page Page Time R H 8 X G 5 X F 4 X E X D 8 X C 7 X B A Page Time R A H 8 X G 5 X F 4 X E X D 8 X C 7 X B

Clock algorithm! Second chance is reasonable but inefficient Quit moving pages around move a pointer?! Same as Second chance but for implementation Keep all pages in a circular list, as a clock, with the hand pointing to the oldest page When page fault Look at page pointed at by hand If R =, evict page If R =. clear R & move hand R: K R: L A R: B R: C R: R: J D R: I Evict this one! E R: R: G G R: F R: R:

Least recently used (LRU) algorithm! Pages used recently will used again soon Throw out page unused for longest time Idea: past experience is a decent predictor of future behavior LRU looks at the past, Belady s wants to look at the future How is LRU different from FIFO?! Must keep a linked list of pages Most recently used at front, least at rear Update this list every memory reference!! Too expensive in memory bandwidth, algorithm execution time, etc! Alternatively keep counter in page table entry Equipped hardware with a counter, incremented after each instruction After each reference, update PTE for the referenced page with value of the counter Choose page with lowest value counter

A second HW LRU implementation! Use a matrix n page frames n x n matrix! Page k is reference Set all bits of row k to Set all bits of column k to! Page of lowest row is LRU,,,,,,,,,,, 4

Simulating LRU in software! Not Frequently Used Software counter associated with each page At clock interrupt add R to counter for each page Problem - it never forgets!! Better Aging Push R from the left, drop bit on the right How is this not LRU? One bit per tick & a finite number of bits per counter 4 5 R 4 5 R 4 5 5

Working set! Most programs show locality of reference Over a short time, just a few common pages! Working set Models the dynamic locality of a process memory usage i.e. the set of pages currently needed by a process! Intuitively, working set must be in memory, otherwise you ll experience heavy faulting (thrashing) What does it mean how much memory does program x need? what is program x average/worst-case working set size? 6

Working set! Demand paging Simplest strategy, load page when needed! Can you do better knowing a process WS? How could you use this to reduce turnaround time? Prepaging! Working set definition ws(k,t) = {pages p such that p was referenced in the k most recent memory references} (k is WS window size) What bounds ws(k, t) as you increase k? ws(k,t) Clearly ws(k i,t) ws(k j,t) for i < j k A more operational definition instead of k reference pages, t msec of execution time 7

Working set algorithm! Working set and page replacement Victim a page not in the working set! At each clock interrupt scan the page table R =? Write Current Virtual Time (CVT) into Time of Last Use R =? CVT Time of Last Use > Threshold? out! else see if there s some other page and evict oldest (w/ R=) If all are in the working set (all R = ), random, preferably clean Information about a page Time of last use 4 R bit Current virtual time 4 Threshold = 7 4 4 4 Page to remove 6 6 8

WSClock algorithm! Problem with WS algorithm Scans the whole table! Instead, scan only what you need to find a victim! Combine clock & working set If R =, unset it If R =, if age > T and page clean, out If dirty, schedule write and check next one If loop around, There s + write scheduled you ll have a clean page soon There s none, pick any one 6 Current virtual time 4 84 98 4 4 4 R = & 4 > T 9

Cleaning policy! To avoid having to write pages out when needed paging daemon Periodically inspects state of memory Keep enough pages free If we need the page before it s overwritten reclaim it!! Two hands for better performance (BSD) First one clears R, second checks it If hands are kept close, only heavily used pages have a chance If back is just ahead of front hand (59 degrees), original clock Two key parameters, adjusted at runtime Scanrate rate at which hands move through the list Handspread gap between them

Design issues global vs. local policy! When you need a page frame, pick a victim from Among your own resident pages Local Among all pages Global! Local algorithms Basically every process gets a fixed % of memory! Global algorithms Dynamically allocate frames among processes Better, especially if working set size changes at runtime How many page frames per process? Start with basic set & react to Page Fault Frequency (PFF)! Most replacement algorithms can work both ways except for those based on working set Why not working set based algorithms?

Load control! Despite good designs, system may still thrash Sum of working sets > physical memory! Page Fault Frequency (PFF) indicates that Some processes need more memory but no process needs less! Way out: Swapping So yes, even with paging you still need swapping Reduce number of processes competing for memory ~ two-level scheduling careful with which process to swap out (there s more than just paging to worry about!) What would you like of the remaining processes?

Next time! We ll now consider design & implementation issues for paging systems Things you want/need to pay attention for good performance