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

Size: px
Start display at page:

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

Transcription

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

2 Announcements MP2 due Tuesday Fabulous Prizes Wednesday! 2

3 Paging On heavily-loaded systems, memory can fill up Need to make room for newly-accessed pages Heuristic: try to move inactive pages out to disk Paging What constitutes an inactive page? Refers to moving individual pages out to disk, and back We often use the terms paging and swapping interchangeably Different from context switching Background processes often have their pages remain resident in memory Paging could occur even with only one process running 3

4 Basic Page Replacement Find the location of the desired page on disk Find a free frame If there is a free frame, use it If there is no free frame, use a page replacement algorithm to select a victim frame Read the desired page into the (newly) free frame. Update the page and frame tables. Note: can also evict in advance OS keeps pool of free pages around, even when memory is tight Makes allocating a new page fast The process of evicting pages to disk is then performed in the background 4

5 Exploiting Locality Exploiting locality Temporal locality: Memory accessed recently tends to be accessed again soon Spatial locality: Memory locations near recently-accessed memory is likely to be referenced soon Locality helps to reduce the frequency of paging Once something is in memory, it should be used many times This depends on many things: The amount of locality and reference patterns in a program The page replacement algorithm The amount of physical memory and the application footprint 5

6 Fundamental technique: caching A cache keeps a subset of a data set in a more accessible but space-limited location Caches are everywhere in systems Such as? 6

7 Fundamental technique: caching A cache keeps a subset of a data set in a more accessible but space-limited location Caches are everywhere in systems Registers are a cache for L1 cache which is a cache for L2 cache which is a cache for memory which is a cache for disk which might be a cache for a remote file server Web proxy servers make downloads faster & cheaper Web browser stores downloaded files Local DNS servers remember recently-resolved DNS names Google servers remember your searches Key goal: minimize cache miss rate = minimize page fault rate (in context of paging) Requires a good algorithm 7

8 Evicting the Best Page Goal of the page replacement algorithm: Reduce page fault rate by selecting the best page to evict The best pages are those that will never be used again However, it's impossible to know in general whether a page will be touched If you have information on future access patterns, it is possible to prove that evicting those pages that will be used the furthest in the future will minimize the page fault rate What is the best algorithm for deciding the order to evict pages? Much attention has been paid to this problem. Used to be a very hot research topic. These days, widely considered solved (at least, solved well enough) 8

9 Algorithm: OPT (a.k.a. MIN) Evict page that won't be used for the longest time in the future Of course, this requires that we can foresee the future... So OPT cannot be implemented! This algorithm has the provably optimal performance Hence the name OPT OPT is useful as a yardstick to compare the performance of other (implementable) algorithms against 9

10 The Optimal Page Replacement Algorithm Idea: Select the page that will not be needed for the longest time in the future Time Requests c a d b e b a b c d Page 0 a Frames 1 b 2 c 3 d a a a a b b b b c c c c d d d d Page faults X Copyright : University of Illinois CS 241 Staff 10

11 The Optimal Page Replacement Algorithm Idea: Select the page that will not be needed for the longest time in the future Time Requests c a d b e b a b c d Page 0 a Frames 1 b 2 c 3 d Page faults a a a a a a a a a b b b b b b b b b c c c c c c c c c d d d d e e e e e X X Copyright : University of Illinois CS 241 Staff 11

12 The Optimal Page Replacement Algorithm Idea: Select the page that will not be needed for the longest time in the future Time Requests c a d b e b a b c d Page 0 a Frames 1 b 2 c 3 d a a a a a a a a a a b b b b b b b b b b c c c c c c c c c c d d d d e e e e e d Page faults X X Copyright : University of Illinois CS 241 Staff 12

13 Algorithms: Random and FIFO Random: Throw out a random page Obviously not the best scheme Although very easy to implement! FIFO: Throw out pages in the order that they were allocated Maintain a list of allocated pages When the length of the list grows to cover all of physical memory, pop first page off list and allocate it Why might FIFO be good? Why might FIFO not be so good? 13

14 Algorithms: Random and FIFO FIFO: Throw out pages in the order that they were allocated Maintain a list of allocated pages When the length of the list grows to cover all of physical memory, pop first page off list and allocate it Why might FIFO be good? Maybe the page allocated very long ago isn t used anymore Why might FIFO not be so good? Doesn t consider locality of reference! Suffers from Belady s anomaly: Performance of an application might get worse as the size of physical memory increases!!! 14

15 Belady s Anomaly Access pattern time Physical memory (3 page frames) Access pattern Physical memory (4 page frames) 9 page faults! 10 page faults! time

16 Algorithm: Least Recently Used (LRU) Evict the page that was used the longest time ago Keep track of when pages are referenced to make a better decision Use past behavior to predict future behavior LRU uses past information, while OPT uses future information When does LRU work well, and when does it not? Implementation Every time a page is accessed, record a timestamp of the access time When choosing a page to evict, scan over all pages and throw out page with oldest timestamp Problems with this implementation? 16

17 Algorithm: Least Recently Used (LRU) Evict the page that was used the longest time ago Keep track of when pages are referenced to make a better decision Use past behavior to predict future behavior LRU uses past information, while OPT uses future information When does LRU work well, and when does it not? Implementation Every time a page is accessed, record a timestamp of the access time When choosing a page to evict, scan over all pages and throw out page with oldest timestamp Problems with this implementation? 32-bit timestamp would double size of PTE Scanning all of the PTEs for lowest timestamp: slow 17

18 Least Recently Used (LRU) Keep track of when a page is used Replace the page that has been used least recently Time Requests c a d b e b a b c d Page 0 a Frames 1 b 2 c 3 d Page faults Copyright : University of Illinois CS 241 Staff 18

19 Least Recently Used (LRU) Keep track of when a page is used Replace the page that has been used least recently (farthest in the past) Time Requests c a d b e b a b c d Page 0 a Frames 1 b 2 c 3 d a a a a b b b b c c c c d d d d Page faults X Copyright : University of Illinois CS 241 Staff 19

20 Least Recently Used (LRU) Keep track of when a page is used Replace the page that has been used least recently (farthest in the past) Time Requests c a d b e b a b c d Page 0 a Frames 1 b 2 c 3 d Page faults a a a a a a a a b b b b b b b b c c c c e e e e d d d d d d d d X X Copyright : University of Illinois CS 241 Staff 20

21 Least Recently Used (LRU) Keep track of when a page is used Replace the page that has been used least recently (farthest in the past) Time Requests c a d b e b a b c d Page 0 a Frames 1 b 2 c 3 d Page faults a a a a a a a a a b b b b b b b b b c c c c e e e e e d d d d d d d d c X X X Copyright : University of Illinois CS 241 Staff 21

22 Least Recently Used (LRU) Keep track of when a page is used Replace the page that has been used least recently (farthest in the past) Time Requests c a d b e b a b c d Page 0 a Frames 1 b 2 c 3 d Page faults a a a a a a a a a a b b b b b b b b b b c c c c e e e e e d d d d d d d d d c c X X X Copyright : University of Illinois CS 241 Staff 22

23 Least Recently Used 3 frames of physical memory Run this for a long time with LRU page replacement: while true! for (i = 0; i < 4; i++)! read from page i! Q1: What fraction of page accesses are faults? None or almost none About 1 in 4 About 2 in 4 About 3 in 4 All or almost all Q2: How well does OPT do? 23

24 24

25 Least Recently Used 3 frames of physical memory Run this for a long time with LRU page replacement: while true! for (i = 0; i < 4; i++)! read from page i! Q1: What fraction of page accesses are faults? None or almost none About 1 in 4 About 2 in 4 About 3 in 4 All or almost all least recently used is always next to be used! Q2: How well does OPT do? 25

26 Least Recently Used Issues Not optimal Does not suffer from Belady's anomaly Implementation Use time of last reference Update every time page accessed (use system clock) Page replacement - search for smallest time Use a stack On page access : remove from stack, push on top Victim selection: select page at bottom of stack Both approaches require large processing overhead, more space, and hardware support. Copyright : University of Illinois CS 241 Staff 26

27 Approximating LRU Use the PTE reference bit and a small counter per page (Use a counter of, say, 2 or 3 bits in size, and store it in the PTE) Periodically (say every 100 msec), scan all physical pages in the system. For each page: If not accessed recently, (PTE reference bit == 0), counter++! If accessed recently (PTE reference bit == 1), counter = 0! Clear the PTE reference bit in either case! Counter will contain the number of scans since the last reference to this page. PTE that contains the highest counter value is the least recently used So, evict the page with the highest counter 27

28 Approximate LRU Example time Accessed pages in blue Increment counter for untouched pages These pages have the highest counter value and can be evicted. 28

29 Algorithm: LRU Second-Chance (Clock) LRU requires searching for the page with the highest lastref count Can do this with a sorted list or a second pass to look for the highest value Simpler technique: Second-chance algorithm Clock hand scans over all physical pages in the system Clock hand loops around to beginning of memory when it gets to end If PTE reference bit == 1, clear bit and advance hand to give it a second-chance If PTE reference bit == 0, evict this page No need for a counter in the PTE! Accessed pages in blue Clock hand Evict! 29

30 Algorithm: LRU Second-Chance (Clock) This is a lot like LRU, but operates in an iterative fashion To find a page to evict, just start scanning from current clock hand position What happens if all pages have ref bits set to 1? What is the minimum age of a page that has the ref bit set to 0? Slight variant -- nth chance clock Only evict page if hand has swept by N times Increment per-page counter each time hand passes and ref bit is 0 Evict a page if counter N Counter cleared to 0 each time page is used 30

31 Swap Files What happens to the page that we choose to evict? Depends on what kind of page it is and what state it's in! OS maintains one or more swap files or partitions on disk Special data format for storing pages that have been swapped out 31

32 Swap Files How do we keep track of where things are on disk? V bit Recall PTE format When V bit is 0, can recycle the PFN field to remember something about the page. 5 bits 24 bits 0 Swap file index Swap file offset Swap file (max 2 24 pages = 64 GB) But... not all pages are swapped in from swap files! Swap file table (max 32 entries) E.g., what about executables? 32

33 Page Eviction How we evict a page depends on its type. Code page: Just remove it from memory can recover it from the executable file on disk! Unmodified (clean) data page: If the page has previously been swapped to disk, just remove it from memory Assuming that page's backing store on disk has not been overwritten If the page has never been swapped to disk, allocate new swap space and write the page to it Exception: unmodified zero page no need to write out to swap at all! Modified (dirty) data page: If the page has previously been swapped to disk, write page out to the swap space If the page has never been swapped to disk, allocate new swap space and write the page to it 33

34 Physical Frame Allocation How do we allocate physical memory across multiple processes? What if Process A needs to evict a page from Process B? How do we ensure fairness? How do we avoid having one process hogging the entire memory of the system? Local replacement algorithms Per-process limit on the physical memory usage of each process When a process reaches its limit, it evicts pages from itself Global-replacement algorithms Physical size of processes can grow and shrink over time Allow processes to evict pages from other processes Note that one process' paging can impact performance of entire system! One process that does a lot of paging will induce more disk I/O 34

35 Working Set A process's working set is the set of pages that it currently needs Definition: WS(P, t, w) = the set of pages that process P accessed in the time interval [t-w, t] w is usually counted in terms of number of page references A page is in WS if it was referenced in the last w page references Working set changes over the lifetime of the process Periods of high locality exhibit smaller working set Periods of low locality exhibit larger working set Basic idea: Give process enough memory for its working set If WS is larger than physical memory allocated to process, it will tend to swap If WS is smaller than memory allocated to process, it's wasteful This amount of memory grows and shrinks over time 35

36 Estimating the Working Set How do we determine the working set? Simple approach: modified clock algorithm Sweep the clock hand at fixed time intervals Record how many seconds since last page reference All pages referenced in last T seconds are in the working set Now that we know the working set, how do we allocate memory? If working sets for all processes fit in physical memory, done! Otherwise, reduce memory allocation of larger processes Idea: Big processes will swap anyway, so let the small jobs run unencumbered Very similar to shortest-job-first scheduling: give smaller processes better chance of fitting in memory How do we decide the working set time limit T? If T is too large, very few processes will fit in memory If T is too small, system will spend more time swapping Which is better? 36

37 Page Fault Frequency Dynamically tune memory size of process based on # page faults Monitor page fault rate for each process (faults per sec) If page fault rate above threshold, give process more memory Should cause process to fault less Doesn't always work! Recall Belady's Anomaly If page fault rate below threshold, reduce memory allocation What happens when everyone s page fault rate is high? 37

38 Thrashing As system becomes more loaded, spends more of its time paging Eventually, no useful work gets done! Thrashing CPU utilization Number of processes System is overcommitted! If the system has too little memory, the page replacement algorithm doesn't matter Solutions? Change scheduling priorities to slow down processes that are thrashing Identify process that are hogging the system and kill them? Is thrashing a problem on systems with only one user? 38

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 18: Page Replacement Terminology in Paging A virtual page corresponds to physical page/frame Segment should not be used anywhere Page out = Page eviction

More information

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

Memory - Paging. Copyright : University of Illinois CS 241 Staff 1 Memory - Paging Copyright : University of Illinois CS 241 Staff 1 Physical Frame Allocation How do we allocate physical memory across multiple processes? What if Process A needs to evict a page from Process

More information

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

Reminder: Mechanics of address translation. Paged virtual memory. Reminder: Page Table Entries (PTEs) Demand paging. Page faults CSE 451: Operating Systems Autumn 2012 Module 12 Virtual Memory, Page Faults, Demand Paging, and Page Replacement Reminder: Mechanics of address translation virtual address virtual # offset table frame

More information

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

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

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Fall 2016 Lecture 11: Page Replacement Geoffrey M. Voelker Administrivia Lab time This week: Thu 4pm, Sat 2pm Next week: Tue, Wed At Washington University in St.

More information

CSE 153 Design of Operating Systems

CSE 153 Design of Operating Systems CSE 153 Design of Operating Systems Winter 18 Lecture 18/19: Page Replacement Memory Management Memory management systems Physical and virtual addressing; address translation Techniques: Partitioning,

More information

Lecture 12: Demand Paging

Lecture 12: Demand Paging Lecture 1: Demand Paging CSE 10: Principles of Operating Systems Alex C. Snoeren HW 3 Due 11/9 Complete Address Translation We started this topic with the high-level problem of translating virtual addresses

More information

Virtual Memory III. Jo, Heeseung

Virtual Memory III. Jo, Heeseung Virtual Memory III Jo, Heeseung Today's Topics What if the physical memory becomes full? Page replacement algorithms How to manage memory among competing processes? Advanced virtual memory techniques Shared

More information

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo PAGE REPLACEMENT Operating Systems 2015 Spring by Euiseong Seo Today s Topics What if the physical memory becomes full? Page replacement algorithms How to manage memory among competing processes? Advanced

More information

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

All Paging Schemes Depend on Locality. VM Page Replacement. Paging. Demand Paging 3/14/2001 1 All Paging Schemes Depend on Locality VM Page Replacement Emin Gun Sirer Processes tend to reference pages in localized patterns Temporal locality» locations referenced recently likely to be

More information

Virtual Memory Design and Implementation

Virtual Memory Design and Implementation Virtual Memory Design and Implementation To do q Page replacement algorithms q Design and implementation issues q Next: Last on virtualization VMMs Loading pages When should the OS load pages? On demand

More information

VIRTUAL MEMORY READING: CHAPTER 9

VIRTUAL MEMORY READING: CHAPTER 9 VIRTUAL MEMORY READING: CHAPTER 9 9 MEMORY HIERARCHY Core! Processor! Core! Caching! Main! Memory! (DRAM)!! Caching!! Secondary Storage (SSD)!!!! Secondary Storage (Disk)! L cache exclusive to a single

More information

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Swapping Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Swapping Support processes when not enough physical memory User program should be independent

More information

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Swapping Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE0: Introduction to Operating Systems, Fall 07, Jinkyu Jeong (jinkyu@skku.edu) Swapping

More information

Last Class: Demand Paged Virtual Memory

Last Class: Demand Paged Virtual Memory Last Class: Demand Paged Virtual Memory Benefits of demand paging: Virtual address space can be larger than physical address space. Processes can run without being fully loaded into memory. Processes start

More information

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

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management CSE 120 July 18, 2006 Day 5 Memory Instructor: Neil Rhodes Translation Lookaside Buffer (TLB) Implemented in Hardware Cache to map virtual page numbers to page frame Associative memory: HW looks up in

More information

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle 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

More information

Lecture 14 Page Replacement Policies

Lecture 14 Page Replacement Policies CS 423 Operating Systems Design Lecture 14 Page Replacement Policies Klara Nahrstedt Fall 2011 Based on slides by YY Zhou and Andrew S. Tanenbaum Overview Administrative Issues Page Replacement Policies

More information

Operating Systems. Operating Systems Sina Meraji U of T

Operating Systems. Operating Systems Sina Meraji U of T Operating Systems Operating Systems Sina Meraji U of T Recap Last time we looked at memory management techniques Fixed partitioning Dynamic partitioning Paging Example Address Translation Suppose addresses

More information

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

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced? Chapter 10: Virtual Memory Questions? CSCI [4 6] 730 Operating Systems Virtual Memory!! What is virtual memory and when is it useful?!! What is demand paging?!! When should pages in memory be replaced?!!

More information

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

Virtual Memory - II. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XVI. University at Buffalo. 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

More information

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

Virtual Memory: Page Replacement. CSSE 332 Operating Systems Rose-Hulman Institute of Technology Virtual Memory: Page Replacement CSSE 332 Operating Systems Rose-Hulman Institute of Technology Announcements Project E & presentation are due Wednesday Team reflections due Monday, May 19 The need for

More information

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

Readings and References. Virtual Memory. Virtual Memory. Virtual Memory VPN. Reading. CSE Computer Systems December 5, 2001. Readings and References Virtual Memory Reading Chapter through.., Operating System Concepts, Silberschatz, Galvin, and Gagne CSE - Computer Systems December, Other References Chapter, Inside Microsoft

More information

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 CS 333 Introduction to Operating Systems Class 14 Page Replacement Jonathan Walpole Computer Science Portland State University Page replacement Assume a normal page table (e.g., BLITZ) User-program is

More information

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 CS 333 Introduction to Operating Systems Class 14 Page Replacement Jonathan Walpole Computer Science Portland State University Page replacement Assume a normal page table (e.g., BLITZ) User-program is

More information

Virtual Memory Design and Implementation

Virtual Memory Design and Implementation Virtual Memory Design and Implementation Today! Page replacement algorithms! Some design and implementation issues Next! Last on virtualization VMMs How can any of this work?!?!! Locality Temporal locality

More information

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

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 15: Caching: Demand Paged Virtual Memory CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2003 Lecture 15: Caching: Demand Paged Virtual Memory 15.0 Main Points: Concept of paging to disk Replacement policies

More information

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

EvicMng the best page #2: FIFO. #1: Belady s Algorithm. CS 537 Lecture 11 Page Replacement Policies 11/1/11. Michael SwiF EvicMng the best page CS 537 Lecture 11 Page Replacement Policies Michael The goal of the page replacement algorithm: reduce fault rate by selecmng best vicmm page to remove the best page to evict is one

More information

Virtual Memory Design and Implementation

Virtual Memory Design and Implementation Virtual Memory Design and Implementation q q q Page replacement algorithms Design and implementation issues Next: Last on virtualization VMMs Loading pages When should the OS load pages? On demand or ahead

More information

Page replacement algorithms OS

Page replacement algorithms OS Page replacement algorithms OS 2007-08 1 When a page fault occurs OS has to choose a page to evict from memory If the page has been modified, the OS has to schedule a disk write of the page The page just

More information

Basic Page Replacement

Basic Page Replacement Basic Page Replacement 1. Find the location of the desired page on disk 2. Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select

More information

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

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory Chapter 4: Memory Management Part 1: Mechanisms for Managing Memory Memory management Basic memory management Swapping Virtual memory Page replacement algorithms Modeling page replacement algorithms Design

More information

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

Outline. 1 Paging. 2 Eviction policies. 3 Thrashing 1 / 28 Outline 1 Paging 2 Eviction policies 3 Thrashing 1 / 28 Paging Use disk to simulate larger virtual than physical mem 2 / 28 Working set model # of accesses virtual address Disk much, much slower than memory

More information

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

Lecture#16: VM, thrashing, Replacement, Cache state Lecture#16: VM, thrashing, Replacement, Cache state Review -- 1 min Multi-level translation tree: multi-level page table, paged paging, paged segmentation, hash table: inverted page table combination:

More information

CS370 Operating Systems

CS370 Operating Systems 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

More information

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

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical Memory Virtual Memory Virtual Memory CSCI Operating Systems Design Department of Computer Science Virtual memory separation of user logical memory from physical memory. Only part of the program needs to be in

More information

Virtual Memory Management

Virtual Memory Management Virtual Memory Management CS-3013 Operating Systems Hugh C. Lauer (Slides include materials from Slides include materials from Modern Operating Systems, 3 rd ed., by Andrew Tanenbaum and from Operating

More information

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

ECE7995 Caching and Prefetching Techniques in Computer Systems. Lecture 8: Buffer Cache in Main Memory (I) ECE7995 Caching and Prefetching Techniques in Computer Systems Lecture 8: Buffer Cache in Main Memory (I) 1 Review: The Memory Hierarchy Take advantage of the principle of locality to present the user

More information

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

CS 4410 Operating Systems. Page Replacement (2) Summer 2016 Cornell University 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

More information

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

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science Virtual Memory CSCI 315 Operating Systems Design Department of Computer Science Notice: The slides for this lecture were based on those Operating Systems Concepts, 9th ed., by Silberschatz, Galvin, and

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 23 Virtual memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Is a page replaces when

More information

Page Replacement Algorithms

Page Replacement Algorithms Page Replacement Algorithms MIN, OPT (optimal) RANDOM evict random page FIFO (first-in, first-out) give every page equal residency LRU (least-recently used) MRU (most-recently used) 1 9.1 Silberschatz,

More information

Paging and Page Replacement Algorithms

Paging and Page Replacement Algorithms Paging and Page Replacement Algorithms Section 3.4 Tanenbaum s book Kartik Gopalan OS Involvement with Page Table Management Four times when OS deals with page-tables 1. Process creation create page table

More information

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

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective Part I: Operating system overview: Memory Management 1 Hardware background The role of primary memory Program

More information

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

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels Memory management, part 2: outline 1 Page Replacement Algorithms Page fault forces choice o which page must be removed to make room for incoming page? Modified page must first be saved o unmodified just

More information

CS 4284 Systems Capstone

CS 4284 Systems Capstone CS 4284 Systems Capstone Virtual Memory Page Replacement Godmar Back VM Design Issues & Techniques CS 4284 Spring 2015 Page Replacement Policies Goal: want to minimize number of (major) page faults (situations

More information

CS 550 Operating Systems Spring Memory Management: Page Replacement

CS 550 Operating Systems Spring Memory Management: Page Replacement CS 550 Operating Systems Spring 2018 Memory Management: Page Replacement 1 OS Involvement with Page Table Management Four times when OS deals with page-tables 1. Process creation create page table 2. Upon

More information

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

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is. Chapter 4 Memory Management Ideally programmers want memory that is Memory Management large fast non volatile 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms

More information

Operating Systems Lecture 6: Memory Management II

Operating Systems Lecture 6: Memory Management II CSCI-GA.2250-001 Operating Systems Lecture 6: Memory Management II Hubertus Franke frankeh@cims.nyu.edu What is the problem? Not enough memory Have enough memory is not possible with current technology

More information

CS510 Operating System Foundations. Jonathan Walpole

CS510 Operating System Foundations. Jonathan Walpole CS510 Operating System Foundations Jonathan Walpole Page Replacement Page Replacement Assume a normal page table (e.g., BLITZ) User-program is executing A PageInvalidFault occurs! - The page needed is

More information

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

Page Replacement. (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018 Page Replacement (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018 Today s Goals Making virtual memory virtual : incorporating disk backing. Explore page replacement policies

More information

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

Today. Adding Memory Does adding memory always reduce the number of page faults? FIFO: Adding Memory with LRU. Last Class: Demand Paged Virtual Memory Last Class: Demand Paged Virtual Memory Benefits of demand paging: Virtual address space can be larger than physical address space. Processes can run without being fully loaded into memory. Processes start

More information

Chapter 4 Memory Management

Chapter 4 Memory Management Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms 4.6 Design issues for paging systems 4.7

More information

Memory management, part 2: outline

Memory management, part 2: outline Memory management, part 2: outline Page replacement algorithms Modeling PR algorithms o Working-set model and algorithms Virtual memory implementation issues 1 Page Replacement Algorithms Page fault forces

More information

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

Operating Systems. Overview Virtual memory part 2. Page replacement algorithms. Lecture 7 Memory management 3: Virtual memory Operating Systems Lecture 7 Memory management : Virtual memory Overview Virtual memory part Page replacement algorithms Frame allocation Thrashing Other considerations Memory over-allocation Efficient

More information

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

Page 1. Goals for Today TLB organization CS162 Operating Systems and Systems Programming Lecture 11. Page Allocation and Replacement Goals for Today" CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement" Finish discussion on TLBs! Page Replacement Policies! FIFO, LRU! Clock Algorithm!! Working Set/Thrashing!

More information

Principles of Operating Systems

Principles of Operating Systems Principles of Operating Systems Lecture 21-23 - Virtual Memory Ardalan Amiri Sani (ardalan@uci.edu) [lecture slides contains some content adapted from previous slides by Prof. Nalini Venkatasubramanian,

More information

Chapter 4 Memory Management. Memory Management

Chapter 4 Memory Management. Memory Management Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms 4.6 Design issues for paging systems 4.7

More information

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

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1 Memory Allocation Copyright : University of Illinois CS 241 Staff 1 Recap: Virtual Addresses A virtual address is a memory address that a process uses to access its own memory Virtual address actual physical

More information

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

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University Operating Systems CSE 410, Spring 2004 Virtual Memory Stephen Wagner Michigan State University Virtual Memory Provide User an address space that is larger than main memory Secondary storage is used to

More information

SMD149 - Operating Systems - VM Management

SMD149 - Operating Systems - VM Management SMD149 - Operating Systems - VM Management Roland Parviainen November 17, 2005 1 / 35 Outline Overview Virtual memory management Fetch, placement and replacement strategies Placement strategies Paging,

More information

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. Demand Paging TDDB68 Concurrent programming and operating systems Overview: Virtual Memory Virtual Memory [SGG7/8] Chapter 9 Background Demand Paging Page Replacement Allocation of Frames Thrashing and Data Access Locality

More information

10: Virtual Memory Management

10: Virtual Memory Management CSC400 - Operating Systems 10: Virtual Memory Management J. Sumey Introduction virtual memory management: concerned with the actual management operations of a virtual memory system fetch strategies: when

More information

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

Global Replacement Algorithms (1) Ken Wong Washington University. Global Replacement Algorithms (2) Replacement Example (1) Virtual Memory Part (CSE S) Ken Wong Washington University kenw@wustl.edu www.arl.wustl.edu/~kenw Global Replacement Algorithms () Example Page Reference Stream (String):»,,,,,,,,,,, Assume» ixed number

More information

Recall from Tuesday. Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS.

Recall from Tuesday. Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS. Paging 11/10/16 Recall from Tuesday Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS Process 3 Process 3 OS: Place Process 3 Process 1 Process

More information

Past: Making physical memory pretty

Past: Making physical memory pretty Past: Making physical memory pretty Physical memory: no protection limited size almost forces contiguous allocation sharing visible to program easy to share data gcc gcc emacs Virtual memory each program

More information

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

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement" October 3, 2012 Ion Stoica http://inst.eecs.berkeley.edu/~cs162 Lecture 9 Followup: Inverted Page Table" With

More information

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

! 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 Questions? CSCI [4 6] 730 Operating Systems Virtual Memory! What is virtual memory and when is it useful?! What is demand paging?! What pages should be» resident in memory, and» which should

More information

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

3/3/2014! Anthony D. Joseph!!CS162! UCB Spring 2014! Post Project 1 Class Format" CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement" Mini quizzes after each topic Not graded Simple True/False Immediate feedback for

More information

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

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science Virtual Memory CSCI 315 Operating Systems Design Department of Computer Science Notice: The slides for this lecture have been largely based on those from an earlier edition of the course text Operating

More information

Memory Management Prof. James L. Frankel Harvard University

Memory Management Prof. James L. Frankel Harvard University Memory Management Prof. James L. Frankel Harvard University Version of 5:42 PM 25-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Memory Management Ideal memory Large Fast Non-volatile

More information

Chapter 8 Virtual Memory

Chapter 8 Virtual Memory Chapter 8 Virtual Memory Contents Hardware and control structures Operating system software Unix and Solaris memory management Linux memory management Windows 2000 memory management Characteristics of

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 2018 L20 Virtual Memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 Questions from last time Page

More information

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

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory TDIU Operating systems Overview: Virtual Memory Virtual Memory Background Demand Paging Page Replacement Allocation of Frames Thrashing and Data Access Locality [SGG7/8/9] Chapter 9 Copyright Notice: The

More information

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

Page Replacement. 3/9/07 CSE 30341: Operating Systems Principles Page Replacement page 1 Page Replacement Algorithms Want lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number

More information

Virtual Memory COMPSCI 386

Virtual Memory COMPSCI 386 Virtual Memory COMPSCI 386 Motivation An instruction to be executed must be in physical memory, but there may not be enough space for all ready processes. Typically the entire program is not needed. Exception

More information

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

Last Class. Demand Paged Virtual Memory. Today: Demand Paged Virtual Memory. Demand Paged Virtual Memory Last Class Segmentation User view of programs Each program consists of a number of segments Segmented Paging: combine the best features of paging and segmentation Today: Demand Paged Virtual Memory Up

More information

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

Clock page algorithm. Least recently used (LRU) NFU algorithm. Aging (NFU + forgetting) Working set. Process behavior When a page fault occurs Page replacement algorithms OS 23 32 OS has to choose a page to evict from memory If the page has been modified, the OS has to schedule a disk write of the page The page just read

More information

Virtual Memory. Chapter 8

Virtual Memory. Chapter 8 Virtual Memory 1 Chapter 8 Characteristics of Paging and Segmentation Memory references are dynamically translated into physical addresses at run time E.g., process may be swapped in and out of main memory

More information

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019 MEMORY: SWAPPING Shivaram Venkataraman CS 537, Spring 2019 ADMINISTRIVIA - Project 2b is out. Due Feb 27 th, 11:59 - Project 1b grades are out Lessons from p2a? 1. Start early! 2. Sketch out a design?

More information

Virtual memory. Virtual memory - Swapping. Large virtual memory. Processes

Virtual memory. Virtual memory - Swapping. Large virtual memory. Processes Virtual memory Virtual memory - Swapping Johan Montelius KTH 2017 1: Allowing two or more processes to use main memory, given them an illusion of private memory. 2: Provide the illusion of a much larger

More information

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

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1 Memory Allocation Copyright : University of Illinois CS 241 Staff 1 Allocation of Page Frames Scenario Several physical pages allocated to processes A, B, and C. Process B page faults. Which page should

More information

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems Course Outline Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems 1 Today: Memory Management Terminology Uniprogramming Multiprogramming Contiguous

More information

Perform page replacement. (Fig 8.8 [Stal05])

Perform page replacement. (Fig 8.8 [Stal05]) Virtual memory Operations and policies Chapters 3.4. 3.7 1 Policies and methods Fetch policy (Noutopolitiikka) When to load page to memory? Placement policy (Sijoituspolitiikka ) Where to place the new

More information

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

Demand Paging. Valid-Invalid Bit. Steps in Handling a Page Fault. Page Fault. Transfer of a Paged Memory to Contiguous Disk Space Demand Paging Transfer of a Paged Memory to Contiguous Disk Space Bring a page into memory only when it is needed. Less I/O needed Less memory needed Faster response More users Page is needed reference

More information

Operating System Concepts

Operating System Concepts Chapter 9: Virtual-Memory Management 9.1 Silberschatz, Galvin and Gagne 2005 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped

More information

Memory: Paging System

Memory: Paging System Memory: Paging System Instructor: Hengming Zou, Ph.D. In Pursuit of Absolute Simplicity 求于至简, 归于永恒 Content Paging Page table Multi-level translation Page replacement 2 Paging Allocate physical memory in

More information

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

Virtual Memory. Reading: Silberschatz chapter 10 Reading: Stallings. chapter 8 EEL 358 Virtual Memory Reading: Silberschatz chapter 10 Reading: Stallings chapter 8 1 Outline Introduction Advantages Thrashing Principal of Locality VM based on Paging/Segmentation Combined Paging and Segmentation

More information

Virtual Memory Outline

Virtual Memory Outline Virtual Memory Outline Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations Operating-System Examples

More information

Lecture 14: Cache & Virtual Memory

Lecture 14: Cache & Virtual Memory CS 422/522 Design & Implementation of Operating Systems Lecture 14: Cache & Virtual Memory Zhong Shao Dept. of Computer Science Yale University Acknowledgement: some slides are taken from previous versions

More information

CS450/550 Operating Systems

CS450/550 Operating Systems CS450/550 Operating Systems Lecture 4 memory Palden Lama Department of Computer Science CS450/550 Memory.1 Review: Summary of Chapter 3 Deadlocks and its modeling Deadlock detection Deadlock recovery Deadlock

More information

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

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani Memory Management Virtual Memory By : Kaushik Vaghani Virtual Memory Background Page Fault Dirty Page / Dirty Bit Demand Paging Copy-on-Write Page Replacement Objectives To describe the benefits of a virtual

More information

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

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access) Virtual Memory - programmer views memory as large address space without concerns about the amount of physical memory or memory management. (What do the terms 3-bit (or 6-bit) operating system or overlays

More information

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018 CS 31: Intro to Systems Virtual Memory Kevin Webb Swarthmore College November 15, 2018 Reading Quiz Memory Abstraction goal: make every process think it has the same memory layout. MUCH simpler for compiler

More information

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

Memory Management. Memory Management. G53OPS: Operating Systems. Memory Management Monoprogramming 11/27/2008. Graham Kendall. Memory Management Memory Management Introduction Graham Kendall Memory Management consists of many tasks, including Being aware of what parts of the memory are in use and which parts are not Allocating

More information

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Memory Management Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Topics Why is memory management difficult? Old memory management techniques: Fixed

More information

CS 153 Design of Operating Systems Spring 18

CS 153 Design of Operating Systems Spring 18 CS 53 Design of Operating Systems Spring 8 Lectre 2: Virtal Memory Instrctor: Chengy Song Slide contribtions from Nael Ab-Ghazaleh, Harsha Madhyvasta and Zhiyn Qian Recap: cache Well-written programs exhibit

More information

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory Chapter 9: Virtual Memory Chapter 9: Virtual Memory 9.1 Background 9.2 Demand Paging 9.3 Copy-on-Write 9.4 Page Replacement 9.5 Allocation of Frames 9.6 Thrashing 9.7 Memory-Mapped Files 9.8 Allocating

More information

CS420: Operating Systems

CS420: Operating Systems Virtual Memory James Moscola Department of Physical Sciences York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne Background Code needs to be in memory

More information

Memory Management Virtual Memory

Memory Management Virtual Memory Memory Management Virtual Memory Part of A3 course (by Theo Schouten) Biniam Gebremichael http://www.cs.ru.nl/~biniam/ Office: A6004 April 4 2005 Content Virtual memory Definition Advantage and challenges

More information