CS 3204 Operating Systems Godmar Back Lecture 18.

Slides:



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

9.4 Page Replacement What if there is no free frame?
4.4 Page replacement algorithms
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.
Virtual Memory: Page Replacement
Page Replacement Algorithms
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Virtual Memory. 2 What is virtual memory? Each process has illusion of large address space –2 32 for 32-bit addressing However, physical memory is much.
Virtual Memory.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
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.
Advanced Operating Systems - Spring 2009 Lecture 17 – March 23, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Virtual Memory Introduction to Operating Systems: Module 9.
Virtual-Memory Management
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management – 4 Page Replacement Algorithms CS 342 – Operating Systems.
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
CS 333 Introduction to Operating Systems Class 14 – Page Replacement Jonathan Walpole Computer Science Portland State University.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Virtual Memory.
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
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.
Operating Systems Unit 8: – Virtual Memory management Operating Systems.
Subject: Operating System.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
Lecture 11 Page 1 CS 111 Online Virtual Memory A generalization of what demand paging allows A form of memory where the system provides a useful abstraction.
Demand Paging Reference Reference on UNIX memory management
Virtual Memory – Managing Physical Memory
1 Lecture 8: Virtual Memory Operating System Fall 2006.
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.
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
Chapter 9: Virtual Memory – Part II
Chapter 9: Virtual Memory – Part I
Demand Paging Reference Reference on UNIX memory management
Lecture 10: Virtual Memory
CSE 120 Principles of Operating
Module 9: Virtual Memory
Demand Paging Reference Reference on UNIX memory management
EECE.4810/EECE.5730 Operating Systems
Chapter 9: Virtual-Memory Management
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Demand Paged Virtual Memory
Lecture 30: Virtual Memory-Page Replacement Algorithms
Chapter 4: Memory Management
Contents Memory types & memory hierarchy Virtual memory (VM)
Practical Session 8, Memory Management 2
Operating Systems CMPSC 473
Lecture 9: Caching and Demand-Paged Virtual Memory
Virtual Memory – Page Replacement
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
Chapter 9: Virtual Memory CSS503 Systems Programming
Practical Session 9, Memory Management continues
Chapter 8 & 9 Main Memory and Virtual Memory
Virtual Memory – Page Replacement
Presentation transcript:

CS 3204 Operating Systems Godmar Back Lecture 18

Physical Memory Management

7/13/2016CS 3204 Fall Physical Memory Management Aka frame table management Task: keep efficiently track of which physical frames are used Allocate a frame when paging in, or eager loading Deallocate a frame when process exits or when page is evicted (later) 0 MAX_PHYSICAL frames

7/13/2016CS 3204 Fall Approach 1: Bitmaps Use bitmap to represent free, used pages Sometimes division in user & kernel pool Pintos (palloc.c) does that: keeps two bitmaps –Kernel pool: –User pool: You will manage user pool only 0 MAX_PHYSICAL frames user pool kernel pool

7/13/2016CS 3204 Fall Approach 2: Buddy Allocator Logically subdivide memory in power-of-two blocks Round up on allocation to next power of 2 Split block on allocation (if necessary) Coalesce on deallocation (if possible) –Coalescing can be delayed Used in Linux: allocation requests are always multiple of pages, max blocksize is 4MB

7/13/2016CS 3204 Fall Buddy Allocator Freelists Note: tree view is conceptual, not tree is actually built in implementation Implementation uses n freelists for free blocks of order k, representing allocation sizes of 2^(k+B) bytes. –E.g., Linux uses orders 0-10 for 4KB, 8KB, … 4MB or 2^(0+12) … 2^(10+12) bytes. –Note that free list is kept entirely inside unused pages – unlike bitmaps, no additional memory is needed

7/13/2016CS 3204 Fall Buddy Example - Allocation 64 KB 16KB 32KB 16KB 32KB 4KB 8KB16KB32KB 4KB 8KB16KB32KB 4KB 16KB32KB4KB Alloc (16KB) Alloc (32KB) Alloc (4KB)

7/13/2016CS 3204 Fall Buddy Example - Deallocation 64 KB 16KB 32KB 16KB 32KB 16KB32KB 4KB 16KB32KB4KB Free() 32KB4KB 8KB4KB

7/13/2016CS 3204 Fall Fragmentation Def: The inability to use memory that is unused. Internal fragmentation: –Not all memory inside an allocated unit is used; rest can’t be allocated to other users External fragmentation: –Impossible to satisfy allocation request even though total amount of memory > size requested

7/13/2016CS 3204 Fall Internal Fragmentation 64 KB 16KB12KB32KB 16KB24KB 4KB 8KB 4KB 8KB 4KB 3KB Alloc (12KB) Alloc (24KB) Alloc (4KB) Alloc (3KB) 12KB 24KB

7/13/2016CS 3204 Fall External Fragmentation 64 KB 16KB 32KB 16KB 32KB 16KB32KB 4KB 16KB32KB4KB Free() 32KB4KB 8KB4KB Have 8 KB free, but can‘t Alloc(8KB) Have 12 KB free, but can‘t Alloc(12KB) No external fragmentation

7/13/2016CS 3204 Fall Buddy Allocator & Fragmentation Q.: what is the average internal fragmentation (per allocated object) for –buddy allocator with size 2^n? –in bitmap allocator for objects of size n*s, where each bit represents a unit of size s? –in first-fit allocator from project 0? Q.: what external fragmentation can you expect from buddy allocator scheme? Q.: what’s a good way to measure fragmentation in general?

7/13/2016CS 3204 Fall Page Size & Fragmentation How should a system’s architect choose the page size? – Trade-Off Large pages: –Larger internal fragmentation –(not an issue if most pages are full…) –Page-in & write-back cost larger Small pages: –Higher overhead to store page table (more entries to maintain) Modern architectures provide support for “super pages” – 2MB or 4MB

7/13/2016CS 3204 Fall Page Replacement

7/13/2016CS 3204 Fall /13/ Page Replacement Policies Goal: want to minimize number of (major) page faults (situations where a page must be brought in from disk.) –Also: want to reduce their cost (ideally, evict those pages from their frames that are already on disk – save writeback time) Possible scopes in which replacement is done: –Global replacement policies Treat frames used by all processes equally –Local replacement polices Pool frames according to user or process when considering replacement –Hybrids Algorithms can be applied in these scopes

7/13/2016CS 3204 Fall /13/ Replacement Algorithms Optimal: –“know the future” –Obviously impractical, just a benchmark for comparison/analysis FIFO – evict oldest page LRU – evict least recently used page Clock algorithm (“NRU”) –Enhanced versions of clock

7/13/2016CS 3204 Fall /13/ Optimal or MIN Replacement To analyze algorithms, consider stream of accesses; each access falls into a given page, e.g Optimal (also known as MIN, or Belady’s algorithm) –Replace the page that is accessed the farthest in the future, e.g. that won’t be accessed for the longest time Problem: don’t know what the future holds

7/13/2016CS 3204 Fall /13/ FIFO Evict oldest page: –Problem: completely ignores usage pattern – first pages loaded are often frequently accessed

7/13/2016CS 3204 Fall /13/ LRU Evict least-recently-used page Great if past = future: becomes MIN! Major problem: would have to keep track of “recency” on every access, either by timestamping, or move to front of a list –Infeasible to do that at pipeline speed

7/13/2016CS 3204 Fall /13/ Clock Also known as NRU (Not Recently Used) or 2 nd Chance Use access (or reference bit) –R=1 was accessed –R=0 was not accessed Hand moves & clears R Hand stops when it finds R==0 Two ways to look at it: –Approximation of LRU –FIFO, but keep recently used pages R=1 R=0 R=1 R=0 R=1

7/13/2016CS 3204 Fall /13/ Clock Example In this example, assume hand advances only when allocation requires eviction (as you can do for Pintos P3) To avoid running out of frames, one could use clock daemon that periodically scans pages and resets their access bits (done in Solaris) –Q.: what if clock daemon scans too fast? – all pages appear unused –Q.: what if too slow? – many pages appear used Or start scanning when #free pages falls below some watermark (as done by kswapd in Linux) *2* 2*2* 2*2* 2*2* 5*5* 5*5* 5*5* 5*5* 3*3* 3*3* 3*3* 3*3* 3*3* 3*3* 3*3* 32*2* 2*2* 2*2* 22*2* 22*2* 1*1* 114*4* 4*4* 445*5* 5*5* * means R=1 (page was accessed since last scan) 1 2 3

7/13/2016CS 3204 Fall /13/ Variations on Clock Algorithm 2-handed Clock –If lots of frames, may need to scan many page frames until one is found – so introduce second hand Leading hand clears ref bits Trailing hand evicts pages Enhanced Clock: exploit modified (or “dirty”) bit –First find unreferenced & unmodified frames to evict –Only if out of those, consider unreferenced & modified frames –Clear reference bit as usual

7/13/2016CS 3204 Fall /13/ N-bit Clock Algorithm 1-bit says was recently used or wasn’t –But how recently? Idea: associate n-bit counter with page frame –“age” or “act_count” –have R-bit as before (provided by hardware) When hand passes page frame –act_count >>= 1 aging –act_count |= (R << (n-1)) recent access Replace page frame with lowest act_count