Operating Systems: A Modern Perspective, Chapter 12

Slides:



Advertisements
Similar presentations
Chapters 7 & 8 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Advertisements

Chapter 4 Memory Management Basic memory management Swapping
Page Replacement Algorithms
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
§12.4 Static Paging Algorithms
Chapter 8 Virtual Memory
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
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  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.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Virtual Memory Chapter 8.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Virtual Memory. Names, Virtual Addresses & Physical Addresses Source Program Absolute Module Name Space P i ’s Virtual Address Space P i ’s Virtual Address.
Virtual Memory Chapter 8.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
CSI 400/500 Operating Systems Spring 2009 Lecture #9 – Paging and Segmentation in Virtual Memory Monday, March 2 nd and Wednesday, March 4 th, 2009.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Slide 12-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter Virtual Memory.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Chapter 3 Memory Management: Virtual Memory
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
Chapter 10 Memory Management Part_1. 2 Overview Basic Concepts The major tasks of the memory manger are the allocation and deallocation of main memory.
Virtual Memory. 2 Virtual Memory Manager Provides abstraction of physical memory Creates virtual address space in secondary memory and then “automatically”
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Memory Management Techniques
© 2004, D. J. Foreman 1 Virtual Memory. © 2004, D. J. Foreman 2 Objectives  Avoid copy/restore entire address space  Avoid unusable holes in memory.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Memory Management & Virtual Memory © Dr. Aiman Hanna Department of Computer Science Concordia University Montreal, Canada.
Memory Management. Why memory management? n Processes need to be loaded in memory to execute n Multiprogramming n The task of subdividing the user area.
Virtual Memory Chapter 8.
CSE 120 Principles of Operating
UNIT–IV: Memory Management
Chapter 9: Virtual Memory – Part I
ITEC 202 Operating Systems
Operating Systems: A Modern Perspective, Chapter 12
Chapter 8 Virtual Memory
Virtual Memory © 2004, D. J. Foreman.
Operating Systems Virtual Memory Alok Kumar Jagadev.
Virtual Memory Chapter 8.
Lecture 10: Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
You can pick up your graded Homework #3 now or after class
Chapter 9: Virtual-Memory Management
Page Replacement.
5: Virtual Memory Background Demand Paging
Contents Memory types & memory hierarchy Virtual memory (VM)
Memory Management.
Computer Architecture
Virtual Memory © 2004, D. J. Foreman.
CSE 542: Operating Systems
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
CSE 542: Operating Systems
Presentation transcript:

Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Virtual Memory Operating Systems: A Modern Perspective, Chapter 12

Virtual Memory Organization Primary Memory Secondary Memory Memory Image for pi Operating Systems: A Modern Perspective, Chapter 12

Names, Virtual Addresses & Physical Addresses Dynamically Executable Image Physical Address Space Bt: Virtual Address Space  Physical Address Space Source Program Absolute Module Name Space Pi’s Virtual Address Space Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Locality Address Space for pi Address space is logically partitioned Text, data, stack Initialization, main, error handle Different parts have different reference patterns: 30% 20% 35% 15% <1% Execution time Initialization code (used once) Code for 1 Code for 2 Code for 3 Code for error 1 Code for error 2 Code for error 3 Data & stack Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Virtual Memory Every process has code and data locality Code tends to execute in a few fragments at one time Tend to reference same set of data structures Dynamically load/unload currently-used address space fragments as the process executes Uses dynamic address relocation/binding Generalization of base-limit registers Physical address corresponding to a compile-time address is not bound until run time Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Virtual Memory (cont) Since binding changes with time, use a dynamic virtual address map, Bt Virtual Address Space Bt Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Virtual Memory Primary Memory n-1 Physical Address Space Fragments of the virtual address space are dynamically loaded into primary memory at any given time Secondary Memory Each address space is fragmented Virtual Address Space for pi Virtual Address Space for pj Virtual Address Space for pk Complete virtual address space is stored in secondary memory Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Address Formation Translation system creates an address space, but its address are virtual instead of physical A virtual address, x: Is mapped to physical address y = Bt(x) if x is loaded at physical address y Is mapped to W if x is not loaded The map, Bt, changes as the process executes -- it is “time varying” Bt: Virtual Address  Physical Address  {W} Operating Systems: A Modern Perspective, Chapter 12

Size of Blocks of Memory Virtual memory system transfers “blocks” of the address space to/from primary memory Fixed size blocks: System-defined pages are moved back and forth between primary and secondary memory Variable size blocks: Programmer-defined segments – corresponding to logical fragments – are the unit of movement Paging is the commercially dominant form of virtual memory today Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Paging A page is a fixed size, 2h, block of virtual addresses A page frame is a fixed size, 2h, block of physical memory (the same size as a page) When a virtual address, x, in page i is referenced by the CPU If page i is loaded at page frame j, the virtual address is relocated to page frame j If page is not loaded, the OS interrupts the process and loads the page into a page frame Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Addresses Suppose there are G= 2g2h=2g+h virtual addresses and H=2j+h physical addresses assigned to a process Each page/page frame is 2h addresses There are 2g pages in the virtual address space 2j page frames are allocated to the process Rather than map individual addresses Bt maps the 2g pages to the 2j page frames That is, page_framej = Bt(pagei) Address k in pagei corresponds to address k in page_framej Operating Systems: A Modern Perspective, Chapter 12

Page-Based Address Translation Let N = {d0, d1, … dn-1} be the pages Let M = {b0, b1, …, bm-1} be page frames Virtual address, i, satisfies 0i<G= 2g+h Physical address, k = U2h+V (0V<G= 2h ) U is page frame number V is the line number within the page Bt:[0:G-1]  <U, V>  {W} Since every page is size c=2h page number = U = i/c line number = V = i mod c Consider Example – Figurer 12.9 Operating Systems: A Modern Perspective, Chapter 12

Demand Paging Algorithm Page fault occurs Process with missing page is interrupted Memory manager locates the missing page Page frame is unloaded (replacement policy) Page is loaded in the vacated page frame Page table is updated Process is restarted Operating Systems: A Modern Perspective, Chapter 12

Modeling Page Behavior Let R = r1, r2, r3, …, ri, … be a page reference stream ri is the ith page # referenced by the process The subscript is the virtual time for the process Given a page frame allocation of m, the memory state at time t, St(m), is set of pages loaded St(m) = St-1(m)  Xt - Yt Xt is the set of fetched pages at time t Yt is the set of replaced pages at time t Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 More on Demand Paging If rt was loaded at time t-1, St(m) = St-1(m) If rt was not loaded at time t-1 and there were empty page frames St(m) = St-1(m)  {rt} If rt was not loaded at time t-1 and there were no empty page frames St(m) = St-1(m)  {rt} - {y} The alternative is prefetch paging Operating Systems: A Modern Perspective, Chapter 12

Static Allocation, Demand Paging Number of page frames is static over the life of the process Fetch policy is demand Since St(m) = St-1(m)  {rt} - {y}, the replacement policy must choose y -- which uniquely identifies the paging policy Operating Systems: A Modern Perspective, Chapter 12

Address Translation with Paging g bits h bits Virtual Address Page # Line # “page table” Missing Page Bt j bits h bits Physical Address Frame # Line # CPU Memory MAR Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Random Replacement Replaced page, y, is chosen from the m loaded page frames with probability 1/m Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 1 2 2 2 2 3 2 1 3 2 1 3 2 1 3 1 3 1 3 1 2 1 2 3 2 3 2 6 2 4 6 2 4 5 2 7 5 2 No knowledge of R  not perform well Easy to implement 13 page faults Operating Systems: A Modern Perspective, Chapter 12

Belady’s Optimal Algorithm Replace page with maximal forward distance: yt = max xeS t-1(m)FWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 0 0 2 3 Operating Systems: A Modern Perspective, Chapter 12

Belady’s Optimal Algorithm Replace page with maximal forward distance: yt = max xeS t-1(m)FWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 0 0 2 3 FWD4(2) = 1 FWD4(0) = 2 FWD4(3) = 3 Operating Systems: A Modern Perspective, Chapter 12

Belady’s Optimal Algorithm Replace page with maximal forward distance: yt = max xeS t-1(m)FWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 2 1 0 0 0 2 3 1 FWD4(2) = 1 FWD4(0) = 2 FWD4(3) = 3 Operating Systems: A Modern Perspective, Chapter 12

Belady’s Optimal Algorithm Replace page with maximal forward distance: yt = max xeS t-1(m)FWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 2 2 2 1 0 0 0 0 0 2 3 1 1 1 Operating Systems: A Modern Perspective, Chapter 12

Belady’s Optimal Algorithm Replace page with maximal forward distance: yt = max xeS t-1(m)FWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 2 2 2 2 1 0 0 0 0 0 3 2 3 1 1 1 1 FWD7(2) = 2 FWD7(0) = 3 FWD7(1) = 1 Operating Systems: A Modern Perspective, Chapter 12

Belady’s Optimal Algorithm Replace page with maximal forward distance: yt = max xeS t-1(m)FWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 2 2 2 2 2 2 0 1 0 0 0 0 0 3 3 3 3 2 3 1 1 1 1 1 1 1 FWD10(2) =  FWD10(3) = 2 FWD10(1) = 3 Operating Systems: A Modern Perspective, Chapter 12

Belady’s Optimal Algorithm Replace page with maximal forward distance: yt = max xeS t-1(m)FWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 2 2 2 2 2 2 0 0 0 1 0 0 0 0 0 3 3 3 3 3 3 2 3 1 1 1 1 1 1 1 1 1 FWD13(0) =  FWD13(3) =  FWD13(1) =  Operating Systems: A Modern Perspective, Chapter 12

Belady’s Optimal Algorithm Replace page with maximal forward distance: yt = max xeS t-1(m)FWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 2 2 2 2 2 2 0 0 0 0 4 4 4 1 0 0 0 0 0 3 3 3 3 3 3 6 6 6 7 2 3 1 1 1 1 1 1 1 1 1 1 1 5 5 10 page faults Perfect knowledge of R  perfect performance Impossible to implement Operating Systems: A Modern Perspective, Chapter 12

Least Recently Used (LRU) Replace page with maximal backward distance: yt = max xeS t-1(m)BKWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 0 0 2 3 BKWD4(2) = 3 BKWD4(0) = 2 BKWD4(3) = 1 Operating Systems: A Modern Perspective, Chapter 12

Least Recently Used (LRU) Replace page with maximal backward distance: yt = max xeS t-1(m)BKWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 1 0 0 0 2 3 3 BKWD4(2) = 3 BKWD4(0) = 2 BKWD4(3) = 1 Operating Systems: A Modern Perspective, Chapter 12

Least Recently Used (LRU) Replace page with maximal backward distance: yt = max xeS t-1(m)BKWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 1 1 0 0 0 2 2 3 3 3 BKWD5(1) = 1 BKWD5(0) = 3 BKWD5(3) = 2 Operating Systems: A Modern Perspective, Chapter 12

Least Recently Used (LRU) Replace page with maximal backward distance: yt = max xeS t-1(m)BKWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 1 1 1 0 0 0 2 2 2 3 3 3 0 BKWD6(1) = 2 BKWD6(2) = 1 BKWD6(3) = 3 Operating Systems: A Modern Perspective, Chapter 12

Least Recently Used (LRU) Replace page with maximal backward distance: yt = max xeS t-1(m)BKWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 1 1 3 3 3 0 0 0 6 6 6 7 1 0 0 0 2 2 2 1 1 1 3 3 3 4 4 4 2 3 3 3 0 0 0 2 2 2 1 1 1 5 5 Operating Systems: A Modern Perspective, Chapter 12

Least Recently Used (LRU) Replace page with maximal backward distance: yt = max xeS t-1(m)BKWDt(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 2 2 2 2 3 2 2 2 2 6 6 6 6 1 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 2 3 3 3 3 3 3 3 3 3 3 3 3 5 5 3 1 1 1 1 1 1 1 1 1 1 1 1 7 Backward distance is a good predictor of forward distance -- locality Operating Systems: A Modern Perspective, Chapter 12

First In First Out (FIFO) Replace page that has been in memory the longest: yt = max xeS t-1(m)AGE(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 1 0 0 0 2 3 3 Operating Systems: A Modern Perspective, Chapter 12

First In First Out (FIFO) Replace page that has been in memory the longest: yt = max xeS t-1(m)AGE(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 0 0 2 3 AGE4(2) = 3 AGE4(0) = 2 AGE4(3) = 1 Operating Systems: A Modern Perspective, Chapter 12

First In First Out (FIFO) Replace page that has been in memory the longest: yt = max xeS t-1(m)AGE(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 1 0 0 0 2 3 3 AGE4(2) = 3 AGE4(0) = 2 AGE4(3) = 1 Operating Systems: A Modern Perspective, Chapter 12

First In First Out (FIFO) Replace page that has been in memory the longest: yt = max xeS t-1(m)AGE(x) Let page reference stream, R = 2031203120316457 Frame 2 0 3 1 2 0 3 1 2 0 3 1 6 4 5 7 0 2 2 2 1 1 0 0 0 2 3 3 AGE5(1) = ? AGE5(0) = ? AGE5(3) = ? Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Belady’s Anomaly Let page reference stream, R = 012301401234 Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 3 3 3 4 4 4 4 4 4 1 1 1 1 0 0 0 0 0 2 2 2 2 2 2 2 1 1 1 1 1 3 3 Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 0 0 0 4 4 4 4 3 3 1 1 1 1 1 1 1 0 0 0 0 4 2 2 2 2 2 2 2 1 1 1 1 3 3 3 3 3 3 3 2 2 2 FIFO with m = 3 has 9 faults FIFO with m = 4 has 10 faults Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Stack Algorithms Some algorithms are well-behaved Inclusion Property: Pages loaded at time t with m is also loaded at time t with m+1 Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 3 1 1 1 1 2 2 2 LRU Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 0 1 1 1 1 2 2 2 3 3 Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Stack Algorithms Some algorithms are well-behaved Inclusion Property: Pages loaded at time t with m is also loaded at time t with m+1 Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 3 3 1 1 1 1 0 2 2 2 2 LRU Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 0 0 1 1 1 1 1 2 2 2 2 3 3 3 Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Stack Algorithms Some algorithms are well-behaved Inclusion Property: Pages loaded at time t with m is also loaded at time t with m+1 Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 3 3 3 1 1 1 1 0 0 2 2 2 2 1 LRU Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Stack Algorithms Some algorithms are well-behaved Inclusion Property: Pages loaded at time t with m is also loaded at time t with m+1 Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 3 3 3 4 1 1 1 1 0 0 0 2 2 2 2 1 1 LRU Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 2 2 2 2 2 4 3 3 3 3 3 Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Stack Algorithms Some algorithms are well-behaved Inclusion Property: Pages loaded at time t with m is also loaded at time t with m+1 Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 3 3 3 4 4 4 2 2 2 1 1 1 1 0 0 0 0 0 0 3 3 2 2 2 2 1 1 1 1 1 1 4 LRU Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 4 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 4 4 4 4 3 3 3 3 3 3 3 3 3 2 2 2 Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Stack Algorithms Some algorithms are well-behaved Inclusion Property: Pages loaded at time t with m is also loaded at time t with m+1 Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 3 3 3 4 4 4 4 4 4 1 1 1 1 0 0 0 0 0 2 2 2 2 2 2 2 1 1 1 1 1 3 3 FIFO Frame 0 1 2 3 0 1 4 0 1 2 3 4 0 0 0 0 0 0 0 4 4 4 4 3 3 1 1 1 1 1 1 1 0 0 0 0 4 2 2 2 2 2 2 2 1 1 1 1 3 3 3 3 3 3 3 2 2 2 Operating Systems: A Modern Perspective, Chapter 12

Dynamic Paging Algorithms The amount of physical memory -- the number of page frames -- varies as the process executes How much memory should be allocated? Fault rate must be “tolerable” Will change according to the phase of process Need to define a placement & replacement policy Contemporary models based on working set Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Working Set Intuitively, the working set is the set of pages in the process’s locality Somewhat imprecise Time varying Given k processes in memory, let mi(t) be # of pages frames allocated to pi at time t mi(0) = 0 i=1k mi(t)  |primary memory| Also have St(mi(t)) = St(mi(t-1))  Xt - Yt Or, more simply S(mi(t)) = S(mi(t-1))  Xt - Yt Operating Systems: A Modern Perspective, Chapter 12

Placed/Replaced Pages S(mi(t)) = S(mi(t-1))  Xt - Yt For the missing page Allocate a new page frame Xt = {rt} in the new page frame How should Yt be defined? Consider a parameter, w, called the window size Determine BKWDt(y) for every yS(mi(t-1)) if BKWDt(y)  w, unload y and deallocate frame if BKWDt(y) < w do not disturb y Operating Systems: A Modern Perspective, Chapter 12

Figure 12‑11: The Working Set Window ri R = … 0 3 1 2 1 1 0 3 0 1 2 … W=3 The “Window” At virtual time i-1: working set = {0, 1} At virtual time i: working set = {0, 1, 3} Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Working Set Principle Process pi should only be loaded and active if it can be allocated enough page frames to hold its entire working set The size of the working set is estimated using w Unfortunately, a “good” value of w depends on the size of the locality Empirically this works with a fixed w Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Working Set Example Susceptible to thrashing is w is too small Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Working Set Example Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Working Set Example Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Working Set Example Operating Systems: A Modern Perspective, Chapter 12

Operating Systems: A Modern Perspective, Chapter 12 Segmentation Unit of memory movement is: Variably sized Defined by the programmer Two component addresses, <Seg#, offset> Address translation is more complex than paging Bt: segments x offsets  Physical Address  {W} Bt(i, j) = k Operating Systems: A Modern Perspective, Chapter 12

Segment Address Translation Bt: segments x offsets  physical address  {W} Bt(i, j) = k S: segments  segment addresses Bt(S(segName), j) = k N: offset names  offset addresses Bt(S(segName), N(offsetName)) = k Read implementation in Section 12.6 Operating Systems: A Modern Perspective, Chapter 12

Address Translation in Segmentation <segmentName, offsetName> S N segment # offset ? Limit Bt Relocation Missing segment + Limit Base P To Memory Address Register Operating Systems: A Modern Perspective, Chapter 12