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

Similar documents
Page replacement algorithms OS

Operating Systems Lecture 6: Memory Management II

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

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

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Memory Management Ch. 3

CS510 Operating System Foundations. Jonathan Walpole

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

Virtual Memory Design and Implementation

CS 550 Operating Systems Spring Memory Management: Page Replacement

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

Paging and Page Replacement Algorithms

Memory management, part 2: outline

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

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

CS450/550 Operating Systems

Virtual Memory Design and Implementation

Lecture 14 Page Replacement Policies

Chapter 4 Memory Management

Chapter 4 Memory Management. Memory Management

Virtual Memory Management

Week 2: Tiina Niklander

Operating Systems, Fall

Perform page replacement. (Fig 8.8 [Stal05])

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

CS370 Operating Systems

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

Virtual Memory Design and Implementation

Chapter 3 - Memory Management

Operating Systems. Operating Systems Sina Meraji U of T

Chapter 8 Virtual Memory

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

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

Basic Memory Management

Virtual Memory III. Jo, Heeseung

Memory management, part 3: outline

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

10: Virtual Memory Management

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

MEMORY MANAGEMENT. Term Paper. Operating Systems CS-384

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD

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

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

CS399 New Beginnings. Jonathan Walpole

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

CS370 Operating Systems

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

Memory Management Prof. James L. Frankel Harvard University

MODERN OPERATING SYSTEMS. Chapter 3 Memory Management

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

OPERATING SYSTEM. Chapter 9: Virtual Memory

Memory management, part 3: outline

Lecture 12: Demand Paging

Chapter 9: Virtual Memory

CS 153 Design of Operating Systems Winter 2016

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

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Chapter 9: Virtual-Memory

1. Background. 2. Demand Paging

CS370 Operating Systems

CS 4284 Systems Capstone

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

Virtual Memory COMPSCI 386

Chapter 8: Virtual Memory. Operating System Concepts

Operating System Concepts

Chapter 9: Virtual Memory

Memory: Paging System

CSE 380 Computer Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

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

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Motivation. Memory Management. Memory Management. Computer Hardware Review

Last Class: Demand Paged Virtual Memory

Operating Systems, Fall Lecture 5, Tiina Niklander 1

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Operating Systems. User OS. Kernel & Device Drivers. Interface Programs. Memory Management

Virtual Memory Outline

The Operating System. Chapter 6

Operating System Concepts 9 th Edition

Chapter 9: Virtual Memory

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Memory Management Virtual Memory

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

Chapter 10: 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

Operating Systems (1DT020 & 1TT802) Lecture 9 Memory Management : Demand paging & page replacement. Léon Mugwaneza

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory CS 111. Operating Systems Peter Reiher

Memory Management: Virtual Memory and Paging CS 111. Operating Systems Peter Reiher

Chapter 9: Virtual Memory. Chapter 9: Virtual Memory. Objectives. Background. Virtual-address address Space

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

CSE 153 Design of Operating Systems

Chapter 8 Virtual Memory

CS307: Operating Systems

Transcription:

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 overwrites a page in memory (e.g. 4Kbytes) Clearly, it s better not to pick a page at random Same problem applies to memory caches OS 23 33 Optimal page replacement At the moment of page fault: Label each page in memory is labeled with the number of instructions that will be executed before that page is first referenced Replace the page with the highest number: i.e. postpone as much as possible the next page fault Nice, optimal, but unrealizable The OS can t look into the future to know how long it ll take to reference every page again OS 23 34 Not recently used algorithm Use Referenced and Modified bits R&M are in hardware, potentially changed at each reference to memory R&M are zero when process is started On clock interrupt the R bit is cleared On page fault, to decide which page to evict: Classify: Class R=,M= Class R=,M= Class 2 R=,M= Class 3 R=,M= Replace a page at random from the lowest class OS 23 35 FIFO replacement FIFO, first in first out for pages Clearly not particularly optimal It might end up removing a page that is still referenced since it only looks at the page s age Rarely used in pure form Next removal 8 3 7 2 Latest load OS 23 36 Second chance algorithm Like FIFO but Before throwing out a page checks the R bit: If remove it If clear it and move the page to the end of the list (as it were just been loaded) If all pages have R=, eventually the algorithm degenerates to FIFO (why?) 8 3 7 2 Latest load OS 23 37

Clock page algorithm Like second chance but implemented differently: Check starting from the latest visited page a b More efficient h c g f e d Least recently used (LRU) Pages recently used tend to be used again soon (on average) Idea! Get a counter, maybe a 64bit counter Store the value of the counter in each entry of the page table When is time to remove a page, find the lowest counter value (this is the LRU page) OS 23 38 OS 23 39 NFU algorithm Since LRU is expensive NFU: Not Frequently Used algorithm At each clock interrupt add the R bit to a counter for each page: i.e. count how often a page is referenced Remove page with lowest counter value Unfortunately, this version tends not to forget anything Aging (NFU + forgetting) Take NFU but At each clock interrupt: Right shift the counters (divide by 2) Add the R bit to the left (MSB) As for NFU remove pages with lowest counter Note: this is different from LRU since the time granularity is a clock tick and not every memory reference! OS 23 4 OS 23 4 Process behavior Working set Locality of reference: most of the time the last k references are within a finite set of pages < a large address space The set of pages a process is currently using is called the working set of the process Knowing the working set of processes we can do very sophisticate things (e.g. prepaging) Working set k-most-recent memory references OS 23 42 OS 23 43 2

WS based algorithm Store time information in the table entries At clock interrupt handle R bits as usual (clear them) At page fault, scan entries: If R= just store current time in the entry If R= compute current-last time page was referenced and if > threshold the page can be removed since it s no longer in the working set (not used for threshold time) Note: we re using time rather than actual memory references WSClock algorithm Use the circular structure (as seen earlier) R=, page in the WS don t remove it R=, M= no problem (as before) M=, schedule disk write appropriately to procrastinate as long as possible a process switch No write is schedulable (R= always), just choose a clean page OS 23 44 OS 23 45 Summary Algorithm Optimal NRU (Not recently used) FIFO Second chance Clock LRU (Least Recently Used) NFU Aging Working set WSClock Very crude Comment Not implementable, useful for benchmarking Might throw out important pages Big improvement over FIFO Realistic (better implementation) Excellent but difficult to implement Crude approx to LRU Efficient in approximating LRU Expensive to implement Good and efficient Design issues OS 23 46 OS 23 47 Design issues Local vs. global allocation policy When a page fault occurs, whose page should the OS evict? Which process should get more or less pages? Monitor the number of page faults for every process (PFF page fault frequency) For many page replacement algorithms, the more pages the less page faults OS 23 48 Page faults/sec Page fault behavior Thrashing Optimal (fair to others) Too many pages Number of page frames assigned OS 23 49 3

Load control If the WS of all processes > memory, there s thrashing E.g. the PFF says a process requires more memory but none require less Solution: swapping swap a process out of memory and re-assign its pages to others OS 23 5 Page size Page size p, n pages of memory Average process size s, in pages s/p Each entry in the page table requires e bytes On average p/2 is lost (fragmentation) Internal fragmentation: how much memory is not used within pages Wasted memory: p/2 + se/p Minimizing it yields the optimal page size (under simplifying assumptions) OS 23 5 Two memories Separate data and program address spaces Two independent spaces, two paging systems The linker must know about the two address spaces Other issues Shared pages, handle shared pages (e.g. program code) Sharing data (e.g. shared memory) Cleaning policy Paging algorithms work better if there are a lot of free pages available Pages need to be swapped out to disk Paging daemon (write pages to disk during spare time and evict pages if there are to few) OS 23 52 OS 23 53 Page fault handling. Page fault, the HW traps to the kernel. Perhaps registers are saved (e.g. stack) 2. Save general purpose microprocessor information (registers, PC, PSW, etc.) 3. The OS looks for which page caused the fault (sometimes this information is already somewhere within the MMU) 4. The system checks whether the process has access to the page (otherwise a protection fault is generated, and the process killed) 5. The OS looks for a free page frame, if none is found then the replacement algorithm is run 6. If the selected page is dirty (M=) a disk write is scheduled (suspending the calling process) 7. When the page frame is clean, the OS schedules another transfer to read in the required page from disk 8. When the load is completed, the page table is updated consequently 9. The faulting instruction is backed up, the situation before the fault is restored, the process resumes execution Segmentation OS 23 54 OS 23 55 4

Why? Many separate address spaces (segments) (e.g. data, stack, code, and many others if needed) Each segment is separate (e.g. addresses from to some MAX) Segments might have different lengths Segment number + address within segment Linking is simplified (libraries within different segments can assume addresses starting from ) e.g. if a part of the libraries is recompiled the remainder of the code is unaffected Shared library (DLL s) implementation is simpler (the sharing is simpler) OS 23 56 Comparing paging and segmentation Consideration Paging Segmentation Need the programmer be No aware that this technique is being used? How many linear address Many spaces are there? Can the total address space exceed the size of physical memory Can procedures and data No be distinguished and separately protected? Can tables whose size No fluctuate be accommodated easily? Is sharing of procedures No between users facilitated? Why was this technique To get a large linear To allow programs and invented? address space without data to be broken up into having to buy more logically independent physical memory address spaces and to aid sharing and protection OS 23 57 Pure segmentations Fragmentation B C B C B External fragmentation: Memory fragments not used (we ve already seen this) Memory wasted in unused holes A A A D OS 23 58 OS 23 59 Segmentation + paging (Pentium) 6K segments G 32bit words (DoubleWords) Two tables: LDT, GDT Local (to the process) and global (to the processor) descriptor table To work with a segment the machine loads the segment number into a special register (CS, DS, etc.) CS, DS are 6 bit registers The descriptor of the segment (see next slide) The segment descriptor This is used by the microcode within the Pentium to work with segments Limit in pages/bytes Base 24-3 Page size is 4K G D Base -5 6/32 bit segment Limit 6-9 Limit (2 bits) P DPL S Privilege level Type Limit -5 Base 6-23 System/application Segment present in memory Segment type protection 8 bytes OS 23 6 CS/DS Index G/L Privilege Selector OS 23 6 5

Getting the address Paging on the Pentium 2-level page table in memory Selector Offset bits bits 2 bits Dir Page Offset Base address Limit Other fields Descriptor + 32-bit linear address Dir 23 5 4 3 2 Page Address to the page 23 23 23 5 23 5 23 4 5 4 3 5 4 3 5 2 4 3 Offset 2 4 3 2 3 2 2 Each points to 4Mbytes of pages OS 23 62 OS 23 63 More on the Pentiums TLB, to avoid repeated accesses to memory The whole thing can be used with just a single segment to obtain a linear 32bit address space Set base and limit appropriately Protection (a few bits) OS 23 64 6