Swapping. Operating Systems I. Swapping. Motivation. Paging Implementation. Demand Paging. Active processes use more physical memory than system has

Similar documents
Memory Management Outline. Operating Systems. Motivation. Paging Implementation. Accessing Invalid Pages. Performance of Demand Paging

Module 9: Virtual Memory

Module 9: Virtual Memory

Chapter 9: Virtual-Memory

Operating System Concepts

Chapter 10: Virtual Memory. Background

Page Replacement. 3/9/07 CSE 30341: Operating Systems Principles

Chapter 10: Virtual Memory. Background. Demand Paging. Valid-Invalid Bit. Virtual Memory That is Larger Than Physical Memory

Virtual Memory COMPSCI 386

Background. Virtual Memory (2/2) Demand Paging Example. First-In-First-Out (FIFO) Algorithm. Page Replacement Algorithms. Performance of Demand Paging

Virtual Memory - Overview. Programmers View. Virtual Physical. Virtual Physical. Program has its own virtual memory space.

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical Memory

Principles of Operating Systems

Chapter 9: Virtual Memory

Virtual Memory Outline

Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

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

Where are we in the course?

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 9: Virtual Memory

Page Replacement Algorithms

Optimal Algorithm. Replace page that will not be used for longest period of time Used for measuring how well your algorithm performs

CS370 Operating Systems

Chapter 9: Virtual Memory

Demand Paging. Valid-Invalid Bit. Steps in Handling a Page Fault. Page Fault. Transfer of a Paged Memory to Contiguous Disk Space

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

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

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 9: Virtual Memory

Chapters 9 & 10: Memory Management and Virtual Memory

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

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

OPERATING SYSTEM. Chapter 9: Virtual Memory

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory

CS370 Operating Systems

Chapter 9: Virtual Memory

Lecture 17. Edited from slides for Operating System Concepts by Silberschatz, Galvin, Gagne

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

CS370 Operating Systems

Chapter 10: Virtual Memory

CS307: Operating Systems

Chapter 6: Demand Paging

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

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

Operating System Concepts 9 th Edition

Chapter 3: Virtual Memory ว ตถ ประสงค. Background สามารถอธ บายข อด ในการท ระบบใช ว ธ การจ ดการหน วยความจ าแบบเสม อนได

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced?

Chapter 9: Virtual-Memory Management. Operating System Concepts 8 th Edition,

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Basic Page Replacement

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

First-In-First-Out (FIFO) Algorithm

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Memory management, part 2: outline

ECE7995 Caching and Prefetching Techniques in Computer Systems. Lecture 8: Buffer Cache in Main Memory (I)

1. Background. 2. Demand Paging

Today. Adding Memory Does adding memory always reduce the number of page faults? FIFO: Adding Memory with LRU. Last Class: Demand Paged Virtual Memory

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

Virtual Memory Management

Virtual Memory. Reading: Silberschatz chapter 10 Reading: Stallings. chapter 8 EEL 358

Last Class: Demand Paged Virtual Memory

VIRTUAL MEMORY READING: CHAPTER 9

UNIT - IV. What is virtual memory?

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Virtual Memory: Page Replacement. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani

CS420: Operating Systems

Practice Exercises 449

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

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

Chapter 9: Virtual Memory

CSC Operating Systems Spring Lecture - XIV Virtual Memory - II. Tevfik Ko!ar. Louisiana State University. March 27 th, 2008.

Basic Memory Management

CS370 Operating Systems

Virtual Memory - II. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XVI. University at Buffalo.

Chapter 4 Memory Management

CS450/550 Operating Systems

CSE325 Principles of Operating Systems. Virtual Memory. David P. Duggan. March 7, 2013

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Virtual Memory III. Jo, Heeseung

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

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

Operating Systems. Operating Systems Sina Meraji U of T

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

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

VII. Memory Management

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Memory Management Virtual Memory

CS 5523 Operating Systems: Memory Management (SGG-8)

Chapter 4 Memory Management. Memory Management

Topics: Virtual Memory (SGG, Chapter 09) CS 3733 Operating Systems

Chapter 8 Virtual Memory

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

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

Lecture 14 Page Replacement Policies

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

Transcription:

Swapping Active processes use more physical memory than system has Operating Systems I Address Binding can be fixed or relocatable at runtime Swap out P P Virtual Memory OS Backing Store (Swap Space) Main Memory Swapping Consider K proc, MB/s disk, 8ms seek 8 ms * = 6 ms If used for context switch, want large quantum! Small processes faster Pending I/O (DMA) don t swap DMA to OS buffers Unix uses swapping variant Each process has too large address space Demand Paging Motivation Logical address space larger than physical memory Virtual Memory on special disk Abstraction for programmer Performance ok? Error handling not used Maximum arrays Demand Paging Paging Implementation Less I/O needed Less memory needed Faster response More users No pages in memory initially Pure demand paging Page out A A B Main Memory A A A B B Page Page Page Page Logical Memory v i v i Page Table Validation Bit Page Page Physical Memory

Page Fault 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) Swap page into frame Reset tables (valid bit = ) Restart instruction Performance of Demand Paging Page Fault Rate < p <. (no page faults to every is fault) Effective Access Time = (-p) (memory access) + p (page fault overhead) Page Fault Overhead = swap page out + swap page in + restart Performance Example memory access time = nanoseconds swap fault overhead = 5 msec page fault rate = / EAT = (-p) x + p x (5 msec) = (-p) x + p x 5,, = +,999,9 x p = +,999,9 x / = 5 microseconds! Want less than % degradation > +,999,9 x p >,999,9 x p p <. or fault in,5, accesses! Page Replacement Page fault => What if no free frames? terminate user process (ugh!) swap out process (reduces degree of multiprog) replace other page with needed page Page replacement: if free frame, use it use algorithm to select victim frame write page to disk, changing tables read in new page restart process Page Replacement Page Replacement Algorithms Page Page Page Page Logical Memory () v iv () v i Page Table vi () i Page Table Dirty Bit - avoid page out Page victim Page Physical Memory () () 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:,,,,,,5,,,,,5

First-In-First-Out (FIFO),,,,,,5,,,,,5 Frames / Process 5 Frames / Process 5 9 Page Faults 5 Page Faults! Belady s Anomaly Optimal Replace the page that will not be used for the longest period of time Frames / Process 5 vs.,,,,,,5,,,,,5 6 Page Faults How do we know this? Use as benchmark Least Recently Used Replace the page that has not been used for the longest period of time 5 5,,,,,,5,,,,,5 8 Page Faults No Belady s Anomoly - Stack Algorithm - N frames subset of N+ LRU Implementation Counter 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 LRU Approximations LRU good, but hardware support expensive Some hardware support by reference bit with each page, initially = when page is referenced, set = replace the one which is (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 == then replace bit == then set bit =, get next in FIFO If page referenced enough, never replaced Implement with circular queue

Next Vicitm Second-Chance (a) (b) If all, degenerates to FIFO Enhanced Second-Chance -bits, reference bit and modify bit (,) neither recently used nor modified best page to replace (,) not recently used but modified needs write-out (,) recently used but clean probably used again soon (,) recently used and modified used soon, needs write-out Circular queue in each class -- (Macintosh) Counting Algorithms Page Buffering Keep a counter of number of references LFU - replace page with smallest count if does all in beginning, won t be replaced decay values by shift MFU - smallest count just brought in and will probably be used Not too common (expensive) and not too good Pool of frames start new process immediately, before writing old write out when system idle list of modified pages write out when system idle pool of free frames, remember content page fault => check pool Allocation of Frames How many fixed frames per process? Two allocation schemes: fixed allocation priority allocation Fixed Allocation Equal allocation ex: 9 frames, 5 procs = 8 per proc ( in pool) Proportional Allocation number of frames proportional to size ex: 6 frames, s =, s = 7 f = / 7 x 6 = 5 f = 7 / 7 x 6 = 59 Treat processes equal

Priority Allocation Use a proportional scheme based on priority If process generates a page fault select replacement a process with lower priority Global versus Local replacement local consistent (not influenced by others) global more efficient (used more often) 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 procces to system Thrashing is when a process is busy swapping pages in and out Thrashing Cause of Thrashing CPU utilization degree of muliprogramming Why does paging work? 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 Example Working set window W = a fixed number of page references total number of pages references in time T D = sum of size of W s T = 5 7 W={,,} W={,,7} W={,} if T too small, will not encompass locality if T too large, will encompass several localities if T => infinity, will encompass entire program if D > m => thrashing, so suspend a process Modify LRU appx to include Working Set 5

Page Fault Rate Page Fault Frequency Number of Frames upper bound lower bound increase number of frames decrease number of frames Prepaging Pure demand paging has many page faults initially use working set does cost of prepaging unused frames outweigh cost of page-faulting? Establish acceptable page-fault rate If rate too low, process loses frame If rate too high, process gains frame 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 (.ms), latency + seek time large (ms) Locality small finer resolution, but more faults ex: K process (/ used), fault / k, K faults/ byte Historical trend towards larger page sizes CPU, mem faster proportionally than disks Program Structure consider: int A[][]; for (j=; j<; j++) suppose: for (i=; i<; i++) A[i][j] = ; process has frame row per page => x page faults! Program Structure int A[][]; for (i=; i<; i++) for (j=; j<; j++) A[i][j] = ; 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 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 6

Real-time Real-Time Processes 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 Page Replacement Algorithm FIFO Missing page, plus adjacent pages Working set default is take victim frame periodically if no fault, reduce set size by Reserve pool hard page faults soft page faults Virtual Memory and WinNT 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) New Virtual Memory exec() creates new page table fork() copies page table reference to common pages if written, then copied Page Replacement Algorithm second chance (with more bits) 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 7

Experiment Design Page Fault Method System Pentium MHz NT Server. 6 MB RAM IDE NTFS clearmem Experiments Page Faults Caching Analysis perfmon 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 -K page Exit Repeat Page Metrics with Caching On Hit Return button Read KB Exit Start Read KB Hit Return button Exit 8