Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p. 201 - 247 Silberschatz, ch. 8, 9 p. 302 - 340.

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?
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
Virtual Memory 3 Fred Kuhns
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Chapter 3 Memory Management
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 补充:什么叫页面抖动?
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Memory Management Paging &Segmentation CS311, CS350 & CS550.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
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
Memory management, part 2: outline
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.
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.
1 Virtual Memory Sample Questions Project 3 – Build Pthread Lib Extra Office Hour: Wed 4pm-5pm HILL 367 Recitation 6.
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
Page Replacement Algorithms
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
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.
Caching and Virtual Memory. Main Points Cache concept – Hardware vs. software caches When caches work and when they don’t – Spatial/temporal locality.
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
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.
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.
“ Memory Management Function ” Presented By Lect. Rimple Bala GPC,Amritsar 1.
Demand Paging Reference Reference on UNIX memory management
操作系统原理 OPERATING SYSTEM Chapter 3 Memory Management 内存管理.
1 Lecture 8: Virtual Memory Operating System Fall 2006.
1 Memory Management Chapter Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement.
1 Memory Management Adapted From Modern Operating Systems, Andrew S. Tanenbaum.
PAGE REPLACEMNT ALGORITHMS FUNDAMENTAL OF ALGORITHMS.
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?
Memory Management Chapter 3
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Memory Management Paging (continued) Segmentation
Demand Paging Reference Reference on UNIX memory management
Lecture 10: Virtual Memory
Demand Paging Reference Reference on UNIX memory management
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Page Replacement.
Memory Management Paging (continued) Segmentation
Chapter 4: Memory Management
Practical Session 8, Memory Management 2
Lecture 9: Caching and Demand-Paged Virtual Memory
Memory Management Paging (continued) Segmentation
Practical Session 9, Memory Management continues
Presentation transcript:

Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Virtual Memory & Paging  The relation between virtual addresses and physical memory addresses given by page table  One page table per process is needed (per thread?)  Page table needs to be reloaded at context switch

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Page Replacement  So we know how to find a page table entry  If it is not in the page table  Get it from disk  What if the physical memory is full?  Throw some page out!  Remember cache replacement policies?

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Page Replacement Algorithms  Page fault forces choice  Which page must be removed  Make room for incoming page(s)  Modified page must first be saved  Unmodified just overwritten  Better not to choose an often used page  Will probably need to be brought back in soon

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Optimal Page Replacement Algorithm  Replace page needed at the farthest point in future  Optimal but unrealizable  Estimate by …  Logging page use on previous runs of process  Although this is impractical

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Page Replacement Algorithms 1.Not Recently Used (NRU) 2.FIFO 3.Second Chance FIFO / Clock 4.Least Recently Used (LRU) 5.Not Frequently Used (NFU) / Aging

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) 1. Not Recently Used (NRU)  Each page has Reference bit, Modified bit  Bits are set by HW when page is referenced, modified  Reference bit is periodically unset (at clock ticks)  Pages are classified  Class 0: not referenced, not modified  Class 1: not referenced, modified  Class 2: referenced, not modified  Class 3: referenced, modified  NRU removes page at random  From lowest numbered non empty class  NRU is simple and gives decent performance

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) 2. FIFO Page Replacement  Maintain a linked list of all pages  In the order they came into memory  Page at beginning of list replaced  Disadvantage  Page in memory the longest may be used often

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) 3. Second Chance FIFO  Operation of a second chance  Pages sorted in FIFO order  Inspect the R bit, give the page a second chance if R=1  Put the page at the end of the list (like a new page)  Eventually the page might be selected anyway (how?) Example: Page 20, A has R bit set  2 nd Chance moves pages around in the list …

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) The Clock Page Replacement Algorithm How does this compare with second chance? Hand points to oldest page

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) 4. Least Recently Used (LRU)  Locality: pages used recently will be used soon  Throw out the page that has been unused longest  Must keep a linked list of pages  Most recently used at front, least at rear  Update this list every memory reference !!  Alternative: counter (64 bit) in the page table entry  Increment counter on every instruction  Update in page table only on memory reference  Choose page with lowest value counter

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Least Recently Used LRU using a matrix – pages referenced in order 0,1,2,3,2,1,0,3,2,3 1.Set row k to 1 2.Set column k to 0

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Simulating LRU in Software: NFU  Both solutions (counter, matrix) require extra hardware  And they don’t scale very well with large page tables …  Approximations of LRU can be done in SW NFU (Not Frequently Used)  A counter is associated with each page  At each clock interrupt add R to the counter  Problems?

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) 5. NFU  NFU tends to have a long memory!  Pages frequently used in some phase may still be hot in later phases, even though they are not used!  Solution: instead of adding R, shift R from the left (R=1, c=010  c’=101)  This algorithm is called aging

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Aging  The aging algorithm simulates LRU in software  Note 6 pages for 5 clock ticks, (a) – (e)

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Aging  This algorithm works fine, but consider  Granularity Page accesses between ticks?  Memory How long is the memory?  Tanenbaum: 8 20ms ticks works ok

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2)  The working set is the set of pages used by the k most recent memory references  w(k,t) is the size of the working set at time t  Note: after initial fast increase we see asymptotic behavior (many values of k give roughly the same working set size) k w(k,t) The Working Set Model

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Operation of the WSClock algorithm All pages form a ring (circular list) Each entry holds (time, R, M) R & M are updated by the HW Start where the hand points if R==1 Set R = 0 (& update virt. time) Move to next page if R==0 if age > τ && M==0: reclaim if age > τ && M==1: schedule write When you get back to the start, either: Some writes are scheduled Search until one write finished No writes are scheduled Take first clean page Take the page you’re at The WSClock Page Replacement Algorithm

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Review of Page Replacement Algorithms

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Implementation Issues Operating System Involvement with Paging Four times when OS involved with paging 1. Process creation  Determine program size  Create page table  Create swap space? 2. Process execution  MMU reset for new process  TLB (Translation Lookaside Buffer) flushed 3. Page fault time  Determine virtual address causing fault  Swap target page out, needed page in 4. Process termination time  Release page table, pages

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Locking Pages in Memory  Virtual memory and I/O occasionally interact  Process issues call for read from device into buffer  While waiting for I/O, another process starts up  Has a page fault  Buffer for the first process may be chosen to be paged out  Need to specify some pages locked  Exempted from being target pages

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2)  One-dimensional address space with growing tables  One table may bump into another Segmentation (1)

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Allows each table to grow or shrink, independently Segmentation (2)

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) Segmentation (3) Comparison of paging and segmentation

© DEEDS – OS Course WS11/12 Lecture 5 – Memory Management (2) (a)-(d) Development of checkerboarding (e) Removal of the checkerboarding by compaction Implementation of Pure Segmentation