O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.

Slides:



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

CS Introduction to Operating Systems
9.4 Page Replacement What if there is no free frame?
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
Page-replacement policies On some standard algorithms for the management of resident virtual memory pages.
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Page Replacement Algorithms
Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023.
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.
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
Day 23 Virtual Memory. Operating system’s role in VM Hardware-support Use VM or not Use paging or segmentation or both Software domain Algorithms for.
Memory/Storage Architecture Lab Computer Architecture Virtual Memory.
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.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Paging Algorithms Vivek Pai / Kai Li Princeton University.
Introduction to Systems Programming Lecture 7
Memory Management Virtual Memory Page replacement algorithms
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
Demand Paging Virtual memory = indirect addressing + demand paging –Without demand paging, indirect addressing by itself is valuable because it reduces.
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.
Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p
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.
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
Page Replacement Algorithms Memory Management. Optimal Page Replacement ▪The label for each page in memory is labeled with the number of instructions.
1 First-in, First-out Remove the oldest page Determine the age based on the loading time, not on the time being referenced Old pages may be heavily used.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Paging.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
CPS110: Page replacement Landon Cox. Replacement  Think of physical memory as a cache  What happens on a cache miss?  Page fault  Must decide what.
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.
CS 149: Operating Systems March 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Page Buffering, I. Pages to be replaced are kept in main memory for a while to guard against poorly performing replacement algorithms such as FIFO Two.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
PAGE REPLACEMNT ALGORITHMS FUNDAMENTAL OF ALGORITHMS.
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?
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Memory Management (2).
ITEC 202 Operating Systems
Day 22 Virtual Memory.
Demand Paging Reference Reference on UNIX memory management
Demand Paging Reference Reference on UNIX memory management
Lecture 39 Syed Mansoor Sarwar
Demand Paged Virtual Memory
Practical Session 8, Memory Management 2
Computer Architecture
Page Replacement FIFO, LIFO, LRU, NUR, Second chance
Operating Systems CMPSC 473
Lecture 9: Caching and Demand-Paged Virtual Memory
Practical Session 9, Memory Management continues
Presentation transcript:

O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1

PAGE REPLACMENT ALGORITHMS When a page fault occurs, the operating system has to choose a page to remove from memory so that making a room for the page that has to be brought in. If the removed page has been modified while in memory, it must be rewritten to the disk. If the page has not been changed, the disk copy is already up to date, so no rewrite is needed. 2

System performance is much better if a page that is not heavily used is chosen to evict at each page fault. The problem of “page replacement” occurs in other areas of computer design as well. For example, memory caches… When the cache is full, some block has to be chosen for removal. This problem is precisely the same as page replacement except on a shorter time scale. It has to be done in a few nanoseconds, not milliseconds as with page replacement. 3

T HE O PTıMAL P AGE R EPLACEMENT A LGORıTHM The best possible page replacement algorithm is easy to describe but impossible to implement. At the moment that a page fault occurs, some set of pages is in memory. One of these pages will be referenced on the very next instruction (the page containing that instruction). Other pages may not be referenced until 10, 100, or perhaps 1000 instructions later. Each page can be labeled with the number of instructions that will be executed before that page is first referenced. The optimal page algorithm simply says that the page with the highest label should be removed. Although this method is useful for evaluating page replacement algorithms, it is of no use in practical systems. 4

T HE N OT R ECENTLY U SED (NRU) P AGE R EPLACEMENT A LGORıTHM Most computers with virtual memory have two status bits associated with each page. R is set whenever the page is referenced (read or written). M is set when the page is written to (i.e., modified). 5

When a page fault occurs, the operating system inspects all the pages and divides them into four categories based on the current values of their R and M bits: Class 0: not referenced, not modified. Class 1: not referenced, modified. Class 2: referenced, not modified. Class 3: referenced, modified. The NRU (Not Recently Used) algorithm removes a page at random from the lowest numbered nonempty class. Implicit in this algorithm is that it is better to remove a modified page that has not been referenced in at least one dock tick (typically 20 msec) than a clean page that is in heavy use. 6

T HE F IRST -I N, F IRST -O UT (FIFO) P AGE R EPLACEMENT A LGORITHM The operating system maintains a list of all pages currently in memory. The oldest page is kept at the head of list and the most recent arrival page is kept at the tail of list. On a page fault, the page at the head is removed and the new page added to the tail of the list. FIFO in its pure form is rarely used since it removes some of the most used pages. 7

T HE S ECOND C HANCE P AGE R EPLACEMENT A LGORıTHM A simple modification to FIFO is made by checking the R bit of the oldest page. If R bit is 0, the page is both old and unused, so it is replaced immediately. If the R bit is 1, the bit is cleared, the page is put onto the end of the list of pages, and its load time is updated as though it had just arrived in memory. Then the search continues. The operation of this algorithm, called second chance. We see pages A through H kept on a linked list and sorted by the time they arrived in memory. 8

T HE C LOCK P AGE R EPLACEMENT A LGORITHM Although second chance is a reasonable algorithm, a better approach is to keep all the page frames on a circular list in the form of a clock. A hand points to the oldest page 9

T HE L EAST R ECENTLY U SED (LRU) P AGE R EPLACEMENT A LGORıTHM A good approximation to the optimal algorithm is based on the observation the pages that have been heavily used in the last few instructions will probably be heavily used again in the next few. Conversely, pages that have not been used for ages will probably remain unused for a long time. This idea suggests a realizable algorithm: when a page fault occurs, throw out the page that has been unused for the longest time. This strategy is called LRU (Least Recently Used) paging. 10

This method requires equipping the special hardware with a 64-bit counter, C, that is automatically incremented after each instruction. Furthermore, each page table entry must also have a field large enough to contain the counter. After each memory reference, the current value of C is stored in the page table entry for the page just referenced. When a page fault occurs, the operating system examines all the counters in the page table to find the lowest one. That page is the least recently used. 11

S ıMULATıNG LRU ıN S OFTWARE Instead of using a special hardware for page replacement, a solution that can be implemented in software is needed. One possibility is called the NFU (Not Frequently Used) algorithm. It requires a software counter associated with each page, initially zero. At each clock interrupt, the operating system scans all the pages in memory. For each page, the R bit, if it is 1, is added to the counter. In effect, the counters are an attempt to keep track of how often each page has been referenced. When a page fault occurs, the page with the lowest counter is chosen for replacement. 12

T HE W ORKıNG S ET P AGE R EPLACEMENT A LGORITHM The set of pages that a process is currently using is called its working set. If the entire working set is in memory, the process will run without causing many faults until it moves into another execution phase (e.g., the next pass of the compiler). Therefore, many paging systems try to keep track of each process‘ working set and make sure that it is in memory before letting the process run. This approach is called the working set model. It is designed to greatly reduce the page fault rate. Loading the pages before letting processes run is also called prepaging. Note that the working set changes over time. 13

14

S UMMARY OF P AGE R EPLACEMENT A LGORITHMS 15