Memory Management Virtual Memory Page replacement algorithms

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Advertisements

Chapter 4 Memory Management Basic memory management Swapping
9.4 Page Replacement What if there is no free frame?
Page Replacement Algorithms
4.4 Page replacement algorithms
Page Replacement Algorithms
Chapter 3.3 : OS Policies for Virtual Memory
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Memory Management.
Page Replacement Algorithms
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
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  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)
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.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
1 Memory Management Managing memory hierarchies. 2 Memory Management Ideally programmers want memory that is –large –fast –non volatile –transparent Memory.
Virtual Memory Today Virtual memory Page replacement algorithms
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set.
1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set.
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.
Introduction to Systems Programming Lecture 7
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement Jonathan Walpole Computer Science Portland State University.
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Memory Management 2 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
CS 333 Introduction to Operating Systems Class 14 – Page Replacement Jonathan Walpole Computer Science Portland State University.
CSC 322 Operating Systems Concepts Lecture - 15: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
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
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.
Memory Management From Chapter 4, Modern Operating Systems, Andrew S. Tanenbaum.
1 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.
Page Replacement Algorithms Memory Management. Optimal Page Replacement ▪The label for each page in memory is labeled with the number of instructions.
© 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.
“ Memory Management Function ” Presented By Lect. Rimple Bala GPC,Amritsar 1.
Demand Paging Reference Reference on UNIX memory management
Virtual Memory The address used by a programmer will be called a virtual address or logical address. An address in main memory is called a physical address.
CSE Four Fiddy One Section 7 Kurtis Heimerl Aaron Kimball
1 Memory Management Chapter Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement.
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
Demand Paging Reference Reference on UNIX memory management
Module 9: Virtual Memory
Demand Paging Reference Reference on UNIX memory management
Chapter 9: Virtual-Memory Management
5: Virtual Memory Background Demand Paging
Practical Session 8, Memory Management 2
Page Replacement FIFO, LIFO, LRU, NUR, Second chance
Operating Systems CMPSC 473
Module 9: Virtual Memory
Chapter 9: Virtual Memory CSS503 Systems Programming
Practical Session 9, Memory Management continues
Virtual Memory.
Presentation transcript:

Memory Management Virtual Memory Page replacement algorithms Chapter 4 Sec. 4.4

Structure of a page table entry

Issues with page tables They can be very large It takes more time to access a memory location Virtual page first has to be mapped to its corresponding physical frame The spectrum of solutions High speed registers to implement the table Put entire page table in main memory

Page swapping What to do if the memory reference is to a page that is not in main memory? This is called a page fault “Swap” a page out of main memory and “swap” the needed page in its place The decision about which page to swap out is made by a page replacement algorithm

When a page fault occurs… Page fault forces choice about which page should be overwritten Modified page may first have to be saved to the hard drive But if is unmodified, it can just be overwritten Best not to choose “popular” page It will probably need to be brought back in soon

Page replacement algorithms Choosing the page that gets swapped out Optimal NRU FIFO Second Chance Clock LRU NFU Working Set WSClock

Optimal Page Replacement Algorithm Replace page that will be needed at the farthest point in future Optimal but unrealizable Can estimate by logging page use on previous runs of a given process Impractical

Optimal algorithm example Using 3 page frames 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 7 7 7 2 2 2 2 2 7 0 0 0 0 4 0 0 0 1 1 3 3 3 1 1 Total number of page faults is ___ . This algorithm (although the best) is implausible to implement since it requires future knowledge. It is used mainly for comparison studies.

Not Recently Used (NRU) Each page has reference and modified bits bits are set when page is referenced, modified Pages are classified not referenced, not modified: 0 0 not referenced, modified: 0 1 how can it be? referenced, not modified: 1 0 referenced, modified: 1 1 Removes page at random from the lowest numbered non-empty class

FIFO Maintain a linked list of all pages in order in which they came into memory The page at the head of the list swapped out Disadvantage? Advantage?

FIFO example Using 3 frames 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 7 7 7 2 2 2 4 4 4 0 0 0 7 7 7 0 0 0 3 3 3 2 2 2 1 1 1 0 0 1 1 1 0 0 0 3 3 3 2 2 2 1 Total of ___ faults. Suppose we had 4 frames instead of 3, would there be fewer page faults?

Another FIFO example Consider the reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 With three frames there are faults With four frames there are faults. This is an example of Belady's Anomaly.

P's show which page references show page faults Belady's Anomaly?!? FIFO with 3 page frames FIFO with 4 page frames P's show which page references show page faults

Second Chance FIFO modification A FIFO linked list is maintained, as before. The page at the head of the list is chosen to be swapped out unless its R bit is 0 In that case, it goes to the end of the list And the next process on the list is examined for swapping…

Clock Variation of second chance

Least Recently Used (LRU) Rationale is that pages used recently will be used again soon replace pages that have been unused for longest time If implemented with a linked list of pages the list must be updated with every memory reference Other techniques require hardware support Counter is maintained When a page is referenced, it receives the counter’s value LRU matrix

LRU using a matrix – pages referenced in order 0,1,2,3,2,1,0,3,2,3 LRU matrix LRU using a matrix – pages referenced in order 0,1,2,3,2,1,0,3,2,3

LRU example 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 7 7 7 2 2 4 4 4 0 1 1 1 0 0 0 0 0 0 3 3 3 0 0 1 1 3 3 2 2 2 2 2 7 Total number of page faults is _____. This is often the best page-replacement algorithm that we can use.

Additional reference bits (LRU enhancement ) Instead of just clearing the bits every so often, we can keep extra information by having a reference byte At regular intervals (100 ms, e.g.) a clock interrupt occurs OS shifts the reference bit into the high order position of the reference byte, and shifts all other bits down to the right

Additional reference bits example For example, the reference byte is 01101101 and the reference bit is 1 when the timer expires. The reference byte now becomes 10110110, and the reference bit is set back to 0 Interpreting these bytes as unsigned integers, the least recently referenced page is the one with the smallest reference byte.

Not frequently used (NFU) Counter in each page table entry is initialized to 0 At each clock interrupt, the value of the reference bit is added to the counter, and then set back to 0. At a page fault, the page with the smallest counter is swapped out. Not very useful, but a variation of it accounts for the aging of pages. This is a simulation of LRU See pp. 220-221

Working Set / Locality Model The working-set strategy starts by looking at how many frames a process is actually using. This approach defines the locality model of process execution As a process executes, it moves from one locality to another. A locality is a set of pages actively used together A program is composed of several (possibly overlapping) localities

What is locality? For example, when a procedure is called, it defines a new locality. When the procedure is exited, the locality changes If we allocate enough frames to accommodate the process’ current locality it will fault for the pages in its current locality until they are all in memory. it will not fault again until it changes its locality.

Working-Set Model This model uses a parameter, kto define the working-set window The idea is to examine the most recent kpage references. The set of pages in the most recent kpage references is the working set If a page is in active use, it will be in the working set If it is no longer being used, it will drop from the working set kunits after its last reference

Example A page reference string, withk= 10 2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3 4 4 4 t1 t2 At time t1 the working set is {1,2,5,6,7} At time t2 the working set is {3, 4} The accuracy of the working set depends upon the selection of k. if it is too small, it may not encompass the working set if it is too large, it may overlap several localities

Implementation The OS monitors the working-set of each process and allocates to that working-set enough frames to provide it with its working-set size If there are any extra frames, another process can be started. If the sum of the working-sets increases, exceeding the total number of frames, a process is suspended. That process’ pages are written out and its frames reallocated.

Working Set

WSClock

Summary