CS Introduction to Operating Systems

Slides:



Advertisements
Similar presentations
9.4 Page Replacement What if there is no free frame?
Advertisements

CS 241 Spring 2007 System Programming 1 Memory Replacement Policies Lecture 32 Klara Nahrstedt.
Page Replacement Algorithms
4.4 Page replacement algorithms
Page Replacement Algorithms
Virtual Memory (Chapter 4.3)
Chapter 101 The LRU Policy Replaces the page that has not been referenced for the longest time in the past By the principle of locality, this would be.
Chapter 3.3 : OS Policies for Virtual Memory
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory 3 Fred Kuhns
Module 10: Virtual Memory
Chapter 10: Virtual Memory
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Virtual Memory: Page Replacement
Page Replacement Algorithms
Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023.
Virtual Memory Management G. Anuradha Ref:- Galvin.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management – 4 Page Replacement Algorithms CS 342 – Operating Systems.
Introduction to Systems Programming Lecture 7
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Page Replacement Algorithms
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
CSC 322 Operating Systems Concepts Lecture - 15: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Virtual Memory.
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Paging.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
CS307 Operating Systems Virtual Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
Virtual Memory Questions answered in this lecture: How to run process when not enough physical memory? When should a page be moved from disk to memory?
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 9: Virtual-Memory Management 9.1 Background.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
1 Contents Memory types & memory hierarchy Virtual memory (VM) Page replacement algorithms in case of VM.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
Page Replacement FIFO, LIFO, LRU, NUR, Second chance
COS 318: Operating Systems Virtual Memory Paging.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory What if program is bigger than available memory?
Chapter 9: Virtual Memory – Part I
Operating Systems Virtual Memory Alok Kumar Jagadev.
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Lecture 39 Syed Mansoor Sarwar
5: Virtual Memory Background Demand Paging
Demand Paged Virtual Memory
Chapter 6 Virtual Memory
Practical Session 8, Memory Management 2
Operating Systems CMPSC 473
Module 9: Virtual Memory
Practical Session 9, Memory Management continues
Virtual Memory.
Module IV Memory Organization.
Presentation transcript:

CS 537 - Introduction to Operating Systems Page Replacement CS 537 - Introduction to Operating Systems

Paging Revisitted If a page is not in physical memory find the page on disk find a free frame bring the page into memory What if there is no free frame in memory?

Page Replacement Basic idea if there is a free page in memory, use it if not, select a victim frame write the victim out to disk read the desired page into the now free frame update page tables restart the process

Page Replacement Main objective of a good replacement algorithm is to achieve a low page fault rate insure that heavily used pages stay in memory the replaced page should not be needed for some time Secondary objective is to reduce latency of a page fault efficient code replace pages that do not need to be written out

Reference String Reference string is the sequence of pages being referenced If user has the following sequence of addresses 123, 215, 600, 1234, 76, 96 If the page size is 100, then the reference string is 1, 2, 6, 12, 0, 0

First-In, First-Out (FIFO) The oldest page in physical memory is the one selected for replacement Very simple to implement keep a list victims are chosen from the tail new pages in are placed at the head

FIFO Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 x x x x x x x x x Compulsory Misses 4 4 4 4 2 4 3 1 2 2 2 1 1 1 3 3 3 6 6 6 6 1 1 Fault Rate = 9 / 12 = 0.75

FIFO Issues Poor replacement policy Evicts the oldest page in the system usually a heavily used variable should be around for a long time FIFO replaces the oldest page - perhaps the one with the heavily used variable FIFO does not consider page usage

Optimal Page Replacement Often called Balady’s Min Basic idea replace the page that will not be referenced for the longest time This gives the lowest possible fault rate Impossible to implement Does provide a good measure for other techniques

Optimal Page Replacement Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 x x x x x x Compulsory Misses 3 4 3 2 2 2 1 1 1 6 4 4 Fault Rate = 6 / 12 = 0.50 With the above reference string, this is the best we can hope to do

Least Recently Used (LRU) Basic idea replace the page in memory that has not been accessed for the longest time Optimal policy looking back in time as opposed to forward in time fortunately, programs tend to follow similar behavior

LRU Consider the following reference string: 0, 2, 1, 6, 4, 0, 1, 0, 3, 1, 2, 1 x x x x x x x x Compulsory Misses 4 4 4 2 4 3 2 2 2 1 1 1 1 1 6 6 6 3 3 Fault Rate = 8 / 12 = 0.67

LRU Issues How to keep track of last page access? 2 major solutions requires special hardware support 2 major solutions counters hardware clock “ticks” on every memory reference the page referenced is marked with this “time” the page with the smallest “time” value is replaced stack keep a stack of references on every reference to a page, move it to top of stack page at bottom of stack is next one to be replaced

LRU Issues Both techniques just listed require additional hardware remember, memory reference are very common impractical to invoke software on every memory reference LRU is not used very often Instead, we will try to approximate LRU

Replacement Hardware Support Most system will simply provide a reference bit in PT for each page On a reference to a page, this bit is set to 1 This bit can be cleared by the OS This simple hardware has lead to a variety of algorithms to approximate LRU

Sampled LRU Keep a reference byte for each page At set time intervals, take an interrupt and get the OS involved OS reads the reference bit for each page reference bit is stuffed into the beginning byte for page all the reference bits are then cleared On page fault, replace the page with the smallest reference byte

Sampled LRU Page Table Reference Bytes Interrupt page to replace 1 01100110 1 10001001 2 10000000 3 1 01010101 4 1 00001101 Interrupt R 10110011 1 01000100 2 page to replace on next page fault 01000000 3 10101010 4 10000110

Clock Algorithm (Second Chance) On page fault, search through pages If a page’s reference bit is set to 1 set its reference bit to zero and skip it (give it a second chance) If a page’s reference bit is set to 0 select this page for replacement Always start the search from where the last search left off

Clock Algorithm P0 P6 P9 P1 P7 P3 P4 R R 1 R 1 R 1 P0 R 1 P6 Pointer to first page to check R 1 P9 R 1 P1 user refs P4 - not currently paged start at P6 check P6, P1, P7 and set their reference bits to zero (give them a second chance) check P3 and notice its ref bit is 0 Select P3 for replacement Set pointer to P9 for next search R 1 P7 R P3 R 1 P4

Dirty Pages If a page has been written to, it is dirty Before a dirty page can be replaced it must be written to disk A clean page does not need to be written to disk the copy on disk is already up-to-date We would rather replace an old, clean page than and old, dirty page

Modified Clock Algorithm Very similar to Clock Algorithm Instead of 2 states (ref’d and not ref’d) we will have 4 states (0, 0) - not referenced clean (0, 1) - not referenced dirty (1, 0) - referenced but clean (1, 1) - referenced and dirty Order of preference for replacement goes in the order listed above

Modified Clock Algorithm Add a second bit to PT - dirty bit Hardware sets this bit on write to a page OS can clear this bit Now just do clock algorithm and look for best page to replace This method may require multiple passes through the list

Page Buffering It is expensive to wait for a dirty page to be written out To get process started quickly, always keep a pool of free frames (buffers) On a page fault select a page to replace write new page into a frame in the free pool mark page table restart the process now write the dirty page out to disk place frame holding replaced page in the free pool