CS370 Operating Systems

Similar documents
CS370 Operating Systems

CS370 Operating Systems

Page Replacement Algorithms

Chapter 9: Virtual Memory

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

Chapter 9: Virtual-Memory

Chapter 8: Virtual Memory. Operating System Concepts

Basic Page Replacement

Principles of Operating Systems

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

CS420: Operating Systems

CS370 Operating Systems

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

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

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

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

Module 9: Virtual Memory

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

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

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

Operating System Concepts

Chapter 10: Virtual Memory

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

CS307: Operating Systems

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

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

Virtual Memory B: Objec5ves

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

OPERATING SYSTEM. Chapter 9: Virtual Memory

Operating System Concepts 9 th Edition

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

Chapter 10: Virtual Memory. Background

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

First-In-First-Out (FIFO) Algorithm

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: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

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

Where are we in the course?

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

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

Virtual Memory Outline

Chapter 9: Virtual Memory

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

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

Chapter 9: Virtual Memory

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

Chapters 9 & 10: Memory Management and Virtual Memory

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

Virtual Memory COMPSCI 386

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

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

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

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

Basic Memory Management

Memory management, part 2: outline

CS370 Operating Systems

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

Lecture 14 Page Replacement Policies

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

Chapter 9: Virtual Memory

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

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

Chapter 6: Demand Paging

1. Background. 2. Demand Paging

UNIT - IV. What is virtual memory?

Operating Systems Lecture 6: Memory Management II

Last Class: Demand Paged Virtual Memory

Virtual Memory Management

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

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

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

Memory Management Prof. James L. Frankel Harvard University

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

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

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

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

CS510 Operating System Foundations. Jonathan Walpole

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

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

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

Operating Systems. Operating Systems Sina Meraji U of T

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

Chapter 4 Memory Management

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

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

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

CSE 153 Design of Operating Systems

CS 5523 Operating Systems: Memory Management (SGG-8)

CS 153 Design of Operating Systems Winter 2016

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

Memory Management Outline. Operating Systems. Motivation. Paging Implementation. Accessing Invalid Pages. Performance of Demand Paging

Operating System - Virtual Memory

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

Virtual Memory Design and Implementation

Course: Operating Systems Instructor: M Umair. M Umair

CSE 120 Principles of Operating Systems

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

Transcription:

CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2016 Lecture 33 Virtual Memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1

FAQ How does the virtual memory respond when the stack or heap grows? Or is the hole between them always there? Hole is always there in virtual memory. Frames in memory allocated as needed. How is the TLB affected when a page is moved from Memory to Disk, and is replaced by a page brought in from Disk? TLB is cache, has mechanism for removing and adding info to it. When does a TLB need to be flushed completely? Context switch Can more than one page loaded into memory when a process starts? prefetching Why are disk addresses of non-resident pages not stored in the page table? Generally contains only information used on page hits. 2

Is CS Graduate Program Right For You? What better career opportunities may a CS grad program provide? What is life like as a CS graduate student? What opportunities are there for paying for grad school without taking out more loans? Get answers from industry representatives, current graduate students and faculty Join us CS GRADUATE RECRUITMENT EVENT WEDNESDAY, NOVEMBER 16, 2016 5:00 PM 7:00 PM Rm 130 CSB AND PIZZA

Page Replacement Algorithms Page-replacement algorithm Which frames to replace Want lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string String is just page numbers, not full addresses Repeated access to the same page does not cause a page fault Results depend on number of frames available In all our examples, we use 3 frames and the reference string of referenced page numbers is 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 4

FIFO page replacement algorithm: Out with the old; in with the new When a page must be replaced Replace the oldest one OS maintains list of all pages currently in memory Page at head of the list: Oldest one Page at the tail: Recent arrival During a page fault Page at the head is removed New page added to the tail 5

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 Sometimes a page is needed soon after replacement 7,0,1,2,0,3,0,.. 6

Belady s Anomaly Consider Page reference string 1,2,3,4,1,2,5,1,2,3,4,5 3 frames, 9 faults, 4 frames 10 faults! Adding more frames can cause more page faults! Belady s Anomaly Belady was here at CSU. Guest in my CS530! 3 frames: 9 page faults 4 frames: 10 page faults 7

Optimal Algorithm Replace page that will not be used for longest period of time 9 page replacements is optimal for the example 4 th access: replace 7 because we will not use if got the longest time But how do we know this? Can t read the future Used for measuring how well an algorithm performs 8

Least Recently Used (LRU) Algorithm Use past knowledge rather than future Replace page that has not been used in the most amount of time (4 th access page 7 is least recently used _) Associate time of last use with each page 12 faults better than FIFO (15) but worse than OPT (9) Generally good algorithm and frequently used But how to implement it by tracking the page usage? 9

LRU Algorithm: Implementations Possible implementations Counter implementation Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter When a page needs to be changed, look at the counters to find smallest value Search through table needed 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 Each update expensive No search for replacement needed (bottom is least recently used) LRU and OPT are cases of stack algorithms that don t have Belady s Anomaly 10

Use Of A Stack to Record Most Recent Page References Too slow if done in software 11

LRU Approximation Algorithms LRU needs special hardware and still slow Reference bit With each page associate a bit, initially = 0 When page is referenced bit set to 1 Replace any with reference bit = 0 (if one exists) 0 implies not used since initialization We do not know the order, however. Advanced schemes using more bits: preserve more information about the order 12

Ref bit + history shift register LRU approximation Ref bit: indicates used Ref Bit Shift Register Shift Register after OS timer interrupt 1 0000 0000 1000 0000 1 1001 0001 1100 1000 0 0110 0011 0011 0001 Interpret 8-bit bytes as unsigned integers Page with the lowest number is the LRU page: replace. Example: 00000000 : Not used in last 8 periods 01100101 : Used 4 times in the last 8 periods 11000100 used more recently than 01110111 13

LRU Approximation Algorithms Second-chance algorithm Generally FIFO, plus hardware-provided reference bit Avoid throwing out a heavily used page Clock replacement (using circular queue): hand as a pointer Consider next page Reference bit = 0 -> replace it reference bit = 1 then: set reference bit 0, leave page in memory consider next page, subject to same rules 14

Second-Chance (clock) Page-Replacement Algorithm Clock replacement: hand as a pointer Consider next page Reference bit = 0 -> replace it reference bit = 1 then: set reference bit 0, leave page in memory consider next page, subject to same rules (a) change to 0 (b) replace page 15

Enhanced Second-Chance Algorithm Improve algorithm by using reference bit and modify bit (if available) in concert clean page: better candidate Take ordered pair (reference, modify) 1. (0, 0) neither recently used not modified best page to replace 2. (0, 1) not recently used but modified not quite as good, must write out before replacement 3. (1, 0) recently used but clean probably will be used again soon 4. (1, 1) recently used and modified probably will be used again soon and need to write out before replacement When page replacement called for, use the clock scheme but use the four classes replace page in lowest non-empty class Might need to search circular queue several times 16

Counting Algorithms Keep a counter of the number of references that have been made to each page Not common Least Frequently Used (LFU) Algorithm: replaces page with smallest count Most Frequently Used (MFU) Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used 17

Clever Techniques: Page-Buffering Algorithms Keep a buffer (pool) of free frames, always Then frame available when needed, not found at fault time Read page into free frame and select victim to evict and add to free pool When convenient, evict victim Keep list of modified pages When backing store is otherwise idle, write pages there and set to non-dirty (being proactive!) Keep free frame previous contents intact and note what is in them If referenced again before reused, no need to load contents again from disk Generally useful to reduce penalty if wrong victim frame selected 18

Buffering and applications Applications often understand their memory/disk usage better than the OS Provide their own buffering schemes If both the OS and the application were to buffer Twice the I/O is being utilized for a given I/O 19

20 Allocation of Frames

Allocation of Frames How to allocate frames to processes? Each process needs minimum number of frames Depending on specific needs of the process Maximum of course is total frames in the system Two major allocation schemes fixed allocation priority allocation Many variations 21

Fixed Allocation Equal allocation For example, if there are 100 frames (after allocating frames for the OS) and 5 processes, give each process 20 frames Keep some as free frame buffer pool Proportional allocation Allocate according to the size of process Dynamic as degree of multiprogramming, process sizes change s S s a i i size of i process p m total number of frames allocation for p i i si m S m = 64 s1 =10 s 2 =127 a 1 = 10 137 62» 4 a 2 = 127 62» 57 137 22

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 or select for replacement a frame from a process with lower priority number 23

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 But then process execution time can vary greatly But greater throughput, so more common Local replacement each process selects from only its own set of allocated frames More consistent per-process performance But possibly underutilized memory 24

Thrashing If a process does not have enough pages, the page-fault rate is very high Page fault to get page Replace existing frame But quickly need replaced frame back This leads to: Low CPU utilization Operating system thinking that it needs to increase the degree of multiprogramming Another process added to the system Thrashing a process is busy swapping pages in and out 26

27 Thrashing (Cont.)

Demand Paging and Thrashing Why does demand paging work? Locality model Process migrates from one locality to another Localities may overlap Why does thrashing occur? size of locality > total memory size Limit effects by using local or priority page replacement 28