Lecture 40 Syed Mansoor Sarwar

Slides:



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

Page Replacement Algorithms
Page Replacement Algorithms
Module 10: Virtual Memory
Chapter 10: Virtual Memory
Page Replacement Algorithms (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.
Chapter 9: Virtual Memory
Virtual Memory Why? The need of memory more than the available physical memory. Process 3 Physical Memory Process 2 Process 1 Process 4.
Page 15/4/2015 CSE 30341: Operating Systems Principles Allocation of Frames  How should the OS distribute the frames among the various processes?  Each.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 38 Frame Allocation Read.
03/31/2004CSCI 315 Operating Systems Design1 Allocation of Frames & Thrashing (Virtual Memory)
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 15: Background Information for the VMWare ESX Memory Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Virtual-Memory Management
Gordon College Stephen Brinton
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Chapter 10: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 10: Virtual Memory.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
CSS430 Virtual Memory Textbook Ch9
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Page 19/17/2015 CSE 30341: Operating Systems Principles Optimal Algorithm  Replace page that will not be used for longest period of time  Used for measuring.
Part 8: Virtual Memory. Silberschatz, Galvin and Gagne ©2005 Virtual vs. Physical Address Space Each process has its own virtual address space, which.
Second-Chance Algorithm Basically, it’s a FIFO algorithm When a page has been selected, we inspect its reference bit. If the value is 0, we proceed to.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples Operating.
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.
CSC 360, Instructor: Kui Wu Memory Management II: Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical 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.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Virtual Memory. 2 Last Week Memory Management Increase degree of multiprogramming –Entire process needs to fit into memory Dynamic Linking and Loading.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 9: Virtual Memory – Part II
Chapter 9: Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Virtual Memory.
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Lecture 39 Syed Mansoor Sarwar
5: Virtual Memory Background Demand Paging
Kai Bu 09 Virtual Memory In today’s lecture, let’s continue with virtual memory. Previously, we have.
Chapter 9: Virtual Memory
Chapter 6 Virtual Memory
Chapter 9: Virtual Memory
Operating Systems CMPSC 473
Lecture 41 Syed Mansoor Sarwar
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Virtual Memory.
Presentation transcript:

Lecture 40 Syed Mansoor Sarwar Operating Systems Lecture 40 Syed Mansoor Sarwar

© Copyright Virtual University of Pakistan Agenda for Today Review of the previous lecture Belady’s Anomaly Page Replacement Algorithms Least Frequently Used (LFU) Most Frequently Used (MFU) Page Buffering Algorithm Allocation of Frames Minimum Number of Frames Thrashing 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Review of Lecture 39 Page Replacement Page Replacement Algorithms First-In-First-Out (FIFO) Optimal Replacement Least Recently Used (LRU) 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Page Replacement 30 November 2018 © Copyright Virtual University of Pakistan

Page Replacement Algorithms First-In-First-Out (FIFO) Optimal Least Recently Used (LRU) Counter-based implementation Stack-based implementation 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan FIFO Algorithm Number of frames allocated = 3 Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Number of page faults = 9 1 4 5 2 3 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan FIFO Algorithm Number of frames allocated = 4 Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Number of page faults = 10 1 5 4 2 3 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan FIFO Algorithm Belady’s Anomaly “For some page replacement algorithms, the page fault rate may increase as the number of allocated frames increases.” 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Belady’s Anomaly 30 November 2018 © Copyright Virtual University of Pakistan

Stack Replacement Algorithms A class of page replacement algorithms with the following property: Set of pages in the main memory with n frames is a subset of the set of pages in memory with n+1 frames Do not suffer from Belady’s Anomaly Example: LRU 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan LRU Algorithm Number of frames allocated = 3 Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Number of page faults = 10 1 4 5 3 2 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan LRU Algorithm Number of frames allocated = 4 Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Number of page faults = 8 1 5 2 3 4 30 November 2018 © Copyright Virtual University of Pakistan

LRU Approximation Algorithm Use of reference bit With each page associate a bit, initially = 0 When page is referenced bit set to 1. Replace the one which is 0 (if one exists). We do not know the order, however. 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Least Frequently Used Least Frequently Used (LFU) Replace the page with the smallest reference count. Based on the locality of reference concept—least frequently used page is not in the current locality 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Most Frequently Used Most Frequently Used (MFU) The page with the smallest count was probably just brought in and has yet to be used; it will be in the locality that has just started. 30 November 2018 © Copyright Virtual University of Pakistan

Page Buffering Algorithm OS may keep a pool of free frames A process in need can be given a frame quickly Victims are selected and free frames are added to the pool in the background 30 November 2018 © Copyright Virtual University of Pakistan

Page Buffering Algorithm OS may keep a list of modified pages In the background, the modified pages are written to disk Less dirty pages in the system at page replacements Used together with FIFO replacement in the VAX/VMS operating system 30 November 2018 © Copyright Virtual University of Pakistan

Local vs Global Replacement If process P generates a page fault Select for replacement one of its frames. Select for replacement a frame from a process with lower priority number. 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Allocation of Frames Each process needs a minimum number of frames so that its execution may be guaranteed on a given machine . Example: MOV X,Y Instruction is 6 bytes long (16-bit offsets) and might span 2 pages. 2 pages to handle from. 2 pages to handle to. 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Allocation of Frames 1 2 3 4 5 6 7 8 9 Instruction X Y 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Allocation of Frames Three major allocation schemes: Fixed allocation Free frames are equally divided among processes Proportional Allocation Number of frames allocated to a process is proportional to its size Priority allocation Priority-based proportional allocation 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Frame Allocation Number of free frames = 64 Number of processes = 3 Process sizes P1 = 10 pages P2 = 40 pages P3 = 127 pages Fixed allocation 64/3 = 21 frames per process and one put in the free frames list 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Frame Allocation Proportional Allocation si = Size of process Pi S = ∑ si m = Number of free frames ai = Allocation for Pi = (si / S) * m a1 = (10 / 177) * 64 = 3 frames a2 = (40 / 177) * 64 = 14 frames a3 = (127 / 177) * 64 = 45 frames Two free frames are put in the list of free frames 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Thrashing If a process does not have “enough” pages, the page-fault rate is very high. This leads to: Low CPU utilization Operating system thinks that it needs to increase the degree of multiprogramming. Another process added to the system—serious problem! 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Thrashing A process is thrashing if it is spending more time paging (i.e., swapping pages in and out) than executing Thrashing results in severe performance problems Low CPU utilization High disk utilization Low utilization of other I/O devices 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Thrashing 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Thrashing To stop thrashing, the degree of multiprogramming needs to be reduced Local page replacement prevents thrashing to spread among several processes However, a thrashing process consumes more resources 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Recap of Lecture Belady’s Anomaly Page Replacement Algorithms Least Frequently Used (LFU) Most Frequently Used (MFU) Page Buffering Algorithm Allocation of Frames Minimum Number of Frames Thrashing 30 November 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Operating Systems Lecture 40 Syed Mansoor Sarwar 30 November 2018 © Copyright Virtual University of Pakistan