Virtual Memory (Chapter 4.3)

Slides:



Advertisements
Similar presentations
9.4 Page Replacement What if there is no free frame?
Advertisements

Module 10: Virtual Memory
Chapter 10: Virtual Memory
Page Replacement Algorithms (Virtual Memory)
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Chapter 9: Virtual Memory
Virtual Memory Why? The need of memory more than the available physical memory. Process 3 Physical Memory Process 2 Process 1 Process 4.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Chapter 10: Virtual Memory
國立台灣大學 資訊工程學系 Chapter 9: Virtual Memory. 資工系網媒所 NEWS 實驗室 Objectives To describe the benefits of a virtual memory system To explain the concepts of demand.
Virtual Memory Management G. Anuradha Ref:- Galvin.
Page 15/4/2015 CSE 30341: Operating Systems Principles Allocation of Frames  How should the OS distribute the frames among the various processes?  Each.
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.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 15: Background Information for the VMWare ESX Memory Management.
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.
Gordon College Stephen Brinton
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
Operating Systems I Virtual Memory. Swap out OS P1 P2 Backing Store (Swap Space) Main Memory Address Binding can be fixed or relocatable at runtime Swapping.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
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.
Operating Systems Virtual Memory (Chapter 9). Memory Management Outline Processes (done) Memory Management –Basic(done) –Paging(done) –Virtual memory.
Operating Systems Virtual Memory. Memory Management Outline F Processes  F Memory Management –Basic  –Paging  –Virtual memory 
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
Operating Systems Virtual Memory (Ch 10). Memory Management Outline Processes (done) Memory Management –Basic(done) –Paging(done) –Virtual memory 
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
CSS430 Virtual Memory Textbook Ch9
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.
Part 8: Virtual Memory. Silberschatz, Galvin and Gagne ©2005 Virtual vs. Physical Address Space Each process has its own virtual address space, which.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples Operating.
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.
9.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts Chapter 9: Virtual-Memory Management Background Demand Paging Page Replacement Allocation.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
CSC 360, Instructor: Kui Wu Memory Management II: Virtual Memory.
CS307 Operating Systems Virtual Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 9: Virtual-Memory Management 9.1 Background.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 9: Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
5: Virtual Memory Background Demand Paging
Chapter 6 Virtual Memory
Chapter 9: Virtual Memory
Operating Systems CMPSC 473
Module 9: Virtual Memory
Chapter 9: Virtual Memory CSS503 Systems Programming
Chapter 9: Virtual Memory
Virtual Memory.
Presentation transcript:

Virtual Memory (Chapter 4.3) Operating Systems Virtual Memory (Chapter 4.3)

Memory Management Outline Processes (done) Memory Management Basic (done) Paging (done) Virtual memory 

Motivation Logical address space larger than physical memory 232 about 4 GB in size “Virtual Memory” on special disk Abstraction for programmer Performance ok? Examples: Unused libraries Error handling not used Maximum arrays

Paging Implementation Validation Bit 3 1 2 1 v Page 0 1 i Page 1 1 Page 0 Page 2 2 3 v 2 i Page 3 3 3 Page 2 Logical Memory Page Table Physical Memory “What happens when access invalid page?”

Accessing Invalid Pages Page not in memory interrupt OS => page fault OS looks in table: invalid reference? => abort not in memory? => bring it in Get empty frame (from list) Write page from disk into frame Reset tables (set valid bit = 1) Restart instruction

Performance of Demand Paging Page Fault Rate (p) 0 < p < 1.0 (no page faults to every ref is a fault) Page Fault Overhead = write page in + update + restart Dominated by time to write page in Effective Access Time = (1-p) (memory access) + p (page fault overhead)

Performance Example Memory access time = 100 nanoseconds Page fault overhead = 25 msec Page fault rate = 1/1000 EAT = (1-p) * 100 + p * (25 msec) = (1-p) * 100 + p * 25,000,000 = 100 + 24,999,900 * p = 100 + 24,999,900 * 1/1000 = 25 microseconds! Want less than 10% degradation 110 > 100 + 24,999,900 * p 10 > 24,999,9000 * p p < .0000004 or 1 fault in 2,500,000 accesses!

No Free Frames Page fault => What if no free frames? terminate process (out of memory) swap out process (reduces degree of multiprog) replace another page with needed page Page replacement Page fault with page replacement: if free frame, use it else use algorithm to select victim frame write page to disk read in new page change page tables restart process

Page Replacement 1 v i 3 1 2 (0) 1 2 v (3) Page 0 3 v 2 Page 1 i (1) i 3 1 2 (0) 1 2 v (3) Page 0 3 v 2 Page 1 i (1) (4) 3 Page 0 1 Page 2 Page Table victim 2 Page 3 (2) 1 v Page 2 i 3 (3) Logical Memory i 1 Physical Memory Page Table

Page Replacement Algorithms Every system has its own Want lowest page fault rate Evaluate by running it on a particular string of memory references (reference string) and computing number of page faults Example: 1,2,3,4,1,2,5,1,2,3,4,5

First-In-First-Out (FIFO) 1,2,3,4,1,2,5,1,2,3,4,5 1 3 Frames / Process 2 3

First-In-First-Out (FIFO) 1,2,3,4,1,2,5,1,2,3,4,5 1 4 5 3 Frames / Process 9 Page Faults 2 1 3 3 2 4 How could we reduce the number of page faults?

Optimal vs. Replace the page that will not be used for the longest period of time 1,2,3,4,1,2,5,1,2,3,4,5 1 4 Frames / Process 2 3 4

Optimal vs. Replace the page that will not be used for the longest period of time 1,2,3,4,1,2,5,1,2,3,4,5 1 4 4 Frames / Process 2 6 Page Faults 3 4 How do we know this? Use as benchmark 5

Least Recently Used Replace the page that has not been used for the longest period of time 1,2,3,4,1,2,5,1,2,3,4,5 1 2 3 4

Least Recently Used Replace the page that has not been used for the longest period of time 1,2,3,4,1,2,5,1,2,3,4,5 1 5 2 8 Page Faults 3 5 4 4 3

LRU Implementation Counter implementation Stack implementation every page has a counter; every time page is referenced, copy clock to counter when a page needs to be changed, compare the counters to determine which to change Stack implementation keep a stack of page numbers page referenced: move to top no search needed for replacement (Can we do this in software?)

LRU Approximations LRU good, but hardware support expensive Some hardware support by reference bit with each page, initially = 0 when page is referenced, set = 1 replace the one which is 0 (no order) Enhance by having 8 bits and shifting approximate LRU

Second-Chance FIFO replacement, but … Get first in FIFO Look at reference bit bit == 0 then replace bit == 1 then set bit = 0, get next in FIFO If page referenced enough, never replaced Implement with circular queue

Second-Chance If all 1, degenerates to FIFO (a) (b) 1 1 1 2 2 Next 2 2 Next Vicitm 3 3 1 4 4 1 If all 1, degenerates to FIFO

Enhanced Second-Chance 2-bits, reference bit and modify bit (0,0) neither recently used nor modified best page to replace (0,1) not recently used but modified needs write-out (“dirty” page) (1,0) recently used but “clean” probably used again soon (1,1) recently used and modified used soon, needs write-out Circular queue in each class -- (Macintosh)

Page Buffering Pool of frames start new process immediately, before writing old write out when system idle list of modified pages pool of free frames, remember content page fault => check pool

Thrashing If a process does not have “enough” pages, the page-fault rate is very high low CPU utilization OS thinks it needs increased multiprogramming adds another process to system Thrashing is when a process is busy swapping pages in and out

Thrashing utilization CPU degree of muliprogramming

Cause of Thrashing Why does paging work? Why does thrashing occur? Locality model process migrates from one locality to another localities may overlap Why does thrashing occur? sum of localities > total memory size How do we fix thrashing? Working Set Model Page Fault Frequency

Working-Set Model Working set window W = a fixed number of page references total number of pages references in time T Total = sum of size of W’s m = number of frames

Working Set Example T = 5 1 2 3 2 3 1 2 4 3 4 7 4 3 3 4 1 1 2 2 2 1 W={1,2,3} W={3,4,7} W={1,2} if T too small, will not encompass locality if T too large, will encompass several localities if T => infinity, will encompass entire program if Total > m => thrashing, so suspend a process Modify LRU appx to include Working Set

Page Fault Frequency Establish “acceptable” page-fault rate increase number of frames upper bound Page Fault Rate lower bound decrease number of frames Number of Frames Establish “acceptable” page-fault rate If rate too low, process loses frame If rate too high, process gains frame

Outline Demand Paging Intro (done) Page Replacement Algorithms (done) Thrashing (done) Misc Paging WinNT Linux “Application Performance Studies”

Prepaging Pure demand paging has many page faults initially use working set does cost of prepaging unused frames outweigh cost of page-faulting?

Page Size Old - Page size fixed, New -choose page size How do we pick the right page size? Tradeoffs: Fragmentation Table size Minimize I/O transfer small (.1ms), latency + seek time large (10ms) Locality small finer resolution, but more faults ex: 200K process (1/2 used), 1 fault / 200k, 100K faults/1 byte Historical trend towards larger page sizes CPU, mem faster proportionally than disks

Program Structure consider: suppose: int A[1024][1024]; for (j=0; j<1024; j++) for (i=0; i<1024; i++) A[i][j] = 0; suppose: process has 1 frame 1 row per page => 1024x1024 page faults!

Program Structure 1024 page faults Stack vs. Hash table Compiler int A[1024][1024]; for (i=0; i<1024; i++) for (j=0; j<1024; j++) A[i][j] = 0; 1024 page faults Stack vs. Hash table Compiler separate code from data keep routines that call each other together LISP (pointers) vs. Pascal (no-pointers)

Priority Processes Consider Lock-bit (like for I/O) until used once low priority process faults, bring page in low priority process in ready queue for awhile, waiting while high priority process runs high priority process faults low priority page clean, not used in a while => perfect! Lock-bit (like for I/O) until used once

Real-Time Processes Real-time Paging adds unexpected delays bounds on delay hard-real time: systems crash, lives lost air-traffic control, factor automation soft-real time: application sucks audio, video Paging adds unexpected delays don’t do it lock bits for real-time processes

Virtual Memory and WinNT/2000 Page Replacement Algorithm FIFO Missing page, plus adjacent pages Working set default is 30 take victim frame periodically if no fault, reduce set size by 1 Reserve pool hard page faults soft page faults

Virtual Memory and WinNT/2000 Shared pages level of indirection for easier updates same virtual entry Page File stores only modified logical pages code and memory mapped files on disk already

Virtual Memory and Linux Regions of virtual memory paging disk (normal) file (text segment, memory mapped file) Re-Examine fork() and exec() exec() creates new page table fork() copies page table reference to common pages if written, then copied

Virtual Memory and Linux Page Replacement Algorithm look in reserve pool for free frames reserves for block devices (disk cache) reserves for shared memory user-space blocks enhanced second chance (with more bits) “dirty” pages not taken first

Application Performance Studies and Demand Paging in Windows NT Mikhail Mikhailov Ganga Kannan Mark Claypool David Finkel WPI Saqib Syed Divya Prakash Sujit Kumar BMC Software, Inc.

Capacity Planning Then and Now Capacity Planning in the good old days used to be just mainframes simple CPU-load based queuing theory Unix Capacity Planning today distributed systems networks of workstations Windows NT MS Exchange, Lotus Notes

Does NT have more hard page faults or soft page faults? Experiment Design Does NT have more hard page faults or soft page faults? System Pentium 133 MHz NT Server 4.0 64 MB RAM IDE NTFS NT v 4.0 clearmem Experiments Page Faults Caching Analysis perfmon

Page Fault Method “Work hard” Run lots of applications, open and close All local access, not over network

Soft or Hard Page Faults?

Caching and Prefetching Start process wait for “Enter” Start perfmon Hit “Enter” Read 1 4-K page Exit Repeat

Page Metrics with Caching On