Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

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

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

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

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

Page Replacement Algorithms

Virtual Memory Design and Implementation

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

CS370 Operating Systems

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

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. Today.! Virtual memory! Page replacement algorithms! Modeling page replacement algorithms

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

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

Chapter 9: Virtual Memory

Virtual Memory Management

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

Module 9: Virtual Memory

Module 9: Virtual Memory

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

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

CS370 Operating Systems

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

Where are we in the course?

CS510 Operating System Foundations. Jonathan Walpole

Basic Page Replacement

Chapter 10: Virtual Memory. Background

Principles of Operating Systems

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

Virtual Memory Design and Implementation

Virtual Memory COMPSCI 386

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

Chapter 9: Virtual-Memory

CS370 Operating Systems

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

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

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

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

Chapter 6: Demand Paging

Chapter 9: Virtual Memory

Basic Memory Management

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

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

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

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

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

Memory management, part 2: outline

Operating System Concepts

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

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

Chapter 9: Virtual Memory

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

Address spaces and memory management

Operating Systems Lecture 6: Memory Management II

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

Chapter 9: Virtual Memory

Virtual Memory Design and Implementation

CS 153 Design of Operating Systems Spring 18

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

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

CS370 Operating Systems

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

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Page replacement algorithms OS

Chapter 8: Virtual Memory. Operating System Concepts

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

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

First-In-First-Out (FIFO) Algorithm

Virtual Memory Outline

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

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

OPERATING SYSTEM. Chapter 9: Virtual Memory

Memory: Paging System

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

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Chapter 9: Virtual Memory

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

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

Chapter 10: Virtual Memory

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

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

Operating System Concepts 9 th Edition

Caching and Demand-Paged Virtual Memory

EECS 482 Introduction to Operating Systems

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

Chapter 8 Virtual Memory

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

Memory Management Ch. 3

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

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

Transcription:

Operating Systems Virtual Memory Lecture 11 Michael O Boyle 1

Paged virtual memory Allows a larger logical address space than physical memory All pages of address space do not need to be in memory the full (used) address space on disk in page-sized blocks main memory used as a (page) cache Needed page transferred to a free page frame if no free page frames, evict a page evicted pages go to disk only if dirty Transparent to the application, except for performance managed by hardware and OS Traditionally called paged virtual memory 2

Virtual Memory That is Larger Than Physical Memory

Page Table When Some Pages Are Not in Main Memory

Page Fault If there is a reference to a page, first reference to that page will trap to operating system: page fault 1. Operating system looks at another table to decide: Invalid reference abort Just not in memory 2. Find free frame 3. Swap page into frame via scheduled disk operation 4. Reset tables to indicate page now in memory Set validation bit = v 5. Restart the instruction that caused the page fault

Steps in Handling a Page Fault

Demand paging Pages only brought into memory when referenced Only code/data that is needed by a process needs to be loaded What s needed changes over time Hence, it s called demand paging Few systems try to anticipate future needs But sometimes cluster pages OS keeps track of pages that should come and go together bring in all when one is referenced interface may allow programmer or compiler to identify clusters 7

Page replacement When you read in a page, where does it go? if there are free page frames, grab one if not, must evict something else this is called page replacement Page replacement algorithms try to pick a page that won t be needed in the near future try to pick a page that hasn t been modified (thus saving the disk write) OS tries to keep a pool of free pages around so that allocations don t inevitably cause evictions OS tries to keep some clean pages around so that even if you have to evict a page, you won t have to write it 8

Page Replacement

Evicting the best page The goal of the page replacement algorithm: reduce fault rate by selecting best victim page to remove the best page to evict is one that will never be touched again Belady s proof: evicting the page that won t be used for the longest period of time minimizes page fault rate Examine page replacement algorithms assume that a process pages against itself using a fixed number of page frames Number of frames available impacts page fault rate Note Belady s anomaly 10

Graph of Page Faults Versus The Number of Frames

First-In-First-Out (FIFO) Algorithm Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 3 frames (3 pages can be in memory at a time per process) 15 page faults Can vary by reference string: consider 1,2,3,4,1,2,5,1,2,3,4,5 Adding more frames can cause more page faults! Belady s Anomaly

FIFO Illustrating Belady s Anomaly 16 number of page faults 14 12 10 8 6 4 2 1 2 3 number of frames 4 5 6 7

Belady s Optimal Algorithm Replace page that will not be used for longest period of time 9 is optimal for the example How do you know this? Can t read the future Used for measuring how well your algorithm performs

Least Recently Used (LRU) Algorithm Use past knowledge rather than future Replace page that has not been used in the most amount of time Associate time of last use with each page 12 faults better than FIFO but worse than Belady s/ OPT Generally good algorithm and frequently used But how to implement?

Approximating LRU Many approximations, all use the PTE s referenced bit keep a counter for each page at some regular interval, for each page, do: if ref bit = 0, increment the counter (hasn t been used) if ref bit = 1, zero the counter (has been used) regardless, zero ref bit the counter will contain the # of intervals since the last reference to the page page with largest counter is least recently used Some architectures don t have PTE reference bits can simulate reference bit using the valid bit to induce faults 16

Second-chance Clock 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 If the ref bit is on, turn it off and go to next page arm moves quickly when pages are needed 17

18

Allocation of frames among processes FIFO and LRU Clock each can be implemented as either local or global replacement algorithms local each process is given a limit of pages it can use it pages against itself (evicts its own pages) global the victim is chosen from among all page frames, regardless of owner processes page frame allocation can vary dynamically Issues with local replacement? poor utilization of free page frames, long access time Issues with global replacement? Linux uses global replacement: global thrashing 19

The working set model of program behavior Working set of a process is used to model the dynamic locality of its memory usage working set = set of pages process currently needs formally defined by Peter Denning in the 1960 s Definition: WS(t,w) = {pages P such that P was referenced in the time interval (t, t-w)} t: time w: working set window (measured in page refs) a page in WS only if it was referenced in the last w references Working set varies over the life of the program so does the working set size 20

Number of memory references between page faults Why? Number of page frames allocated to process Why? 21

Example: Working set 22

Working set size The working set size, WS(t,w), Changes with program locality During periods of poor locality, more pages are referenced Within that period of time, the working set size is larger Intuitively, the working set must be in memory, otherwise you ll experience heavy faulting thrashing 23

Hypothetical Working Set algorithm Estimate WS(0,w) for a process Allow that process to start only if you can allocate it that many page frames Use a local replacement algorithm (LRU Clock?) make sure that the working set are occupying the process s frames Track each process s working set size, and re-allocate page frames among processes dynamically Problem keep track of working set size. Use reference bit with a fixed-interval timer interrupt 24

Working Sets and Page Fault Rates Direct relationship between working set of a process and its page-fault rate Working set changes over time Peaks and valleys over time

Page-Fault Frequency More direct approach than WSS Establish acceptable page-fault frequency (PFF) rate and use local replacement policy If actual rate too low, process loses frame If actual rate too high, process gains frame page-fault rate increase number of frames upper bound lower bound decrease number of frames number of frames

Thrashing Thrashing when the system spends most of its time servicing page faults, little time doing useful work Could be that there is enough memory but a poor replacement algorithm - incompatible with program behavior Could be that memory is over-committed OS sees CPU poorly utilized and adds more processes too many active processes Makes problem worse 27

System throughput (requests/sec.) with thrashing Number of active processes 28

Summary Virtual memory Page faults Demand paging don t try to anticipate Page replacement Belady, LRU, Clock, local, global Locality temporal, spatial Working set Thrashing 29