If you miss a key. Chapter 6: Demand Paging Source:

Similar documents

#4 Inverted page table. The need for more bookkeeping. Inverted page table architecture. Today. Our Small Quiz

Chapter 6: Demand Paging

Virtual Memory. Background. No. 10. Virtual Memory: concept. Logical Memory Space (review) Demand Paging(1) Virtual Memory

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

ELEC 377 Operating Systems. Week 6 Class 3

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

Cache Performance 3/28/17. Agenda. Cache Abstraction and Metrics. Direct-Mapped Cache: Placement and Access

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

Module 9: Virtual Memory

Module 9: Virtual Memory

Chapter 9: Virtual Memory

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

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

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

Chapter 9: Virtual Memory

Chapter 8: Virtual Memory. Operating System Concepts

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

Nachos Project 3. Speaker: Sheng-Wei Cheng 2010/12/16

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

Chapter 9: Virtual Memory

Chapter 10: Virtual Memory. Background

4/11/17. Agenda. Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Storage Management.

Chapter 9: Virtual-Memory

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

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

Where are we in the course?

OPERATING SYSTEM. Chapter 9: Virtual Memory

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

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

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

Operating System Concepts

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

CS307: Operating Systems

CS420: Operating Systems

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

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

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

Virtual Memory Outline

Virtual Memory COMPSCI 386

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

Chapter 10: Virtual Memory

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Memory and I/O Organization

Operating System Concepts 9 th Edition

CS370 Operating Systems

VIRTUAL MEMORY READING: CHAPTER 9

Basic Memory Management

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

Principles of Operating Systems

An Efficient Garbage Collection for Flash Memory-Based Virtual Memory Systems

Virtual Memory III. Jo, Heeseung

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

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Page Replacement Algorithms

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

Assembler. Building a Modern Computer From First Principles.

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

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

Basic Page Replacement

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

Chapter 9: Virtual Memory

Efficient Distributed File System (EDFS)

Real-Time Guarantees. Traffic Characteristics. Flow Control

현재이이미지를표시할수없습니다. Chapter 9: Virtual Memory

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

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

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018

Virtual Memory Management

instruction is 6 bytes, might span 2 pages 2 pages to handle from 2 pages to handle to Two major allocation schemes

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

Operating Systems. Operating Systems Sina Meraji U of T

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture 12: Demand Paging

Chapter 4 Memory Management

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Memory management, part 2: outline

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - XIV Virtual Memory - I. Louisiana State University.

First-In-First-Out (FIFO) Algorithm

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

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

CS370 Operating Systems

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

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

kccvoip.com basic voip training NAT/PAT extract 2008

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

CS370 Operating Systems

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Chapters 9 & 10: Memory Management and Virtual Memory

Chapter 5: Memory Management

How to create a process? What does process look like?

Memory Management. Outline. Memory. Virtual Memory. Instructor: Dr. Tongping Liu

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

Even in those cases where the entire program is needed, it may not all be needed at the same time (such is the case with overlays, for example).

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

3/3/2014! Anthony D. Joseph!!CS162! UCB Spring 2014!

VII. Memory Management

Transcription:

ADRIAN PERRIG & TORSTEN HOEFLER ( -6- ) Networks and Operatng Systems Chapter 6: Demand Pagng Source: http://redmne.replcant.us/projects/replcant/wk/samsunggalaxybackdoor If you mss a key after yesterday s exercse sesson pck t up here! Next Thursday (March th ) No lecture! Frday wll be a lecture! TLB shootdown TLB management TLB management Recall: the TLB s a cache. Machnes have many MMUs on many cores many TLBs Problem: TLBs should be coherent. Why? Securty problem f mappngs change E.g., when s reused Core Core Core Process ID VPN PPN acces s x x r/w xf8 x r/w x x r/w x x read xf8 x r/w x x read

TLB management TLB management Core Core Process ID VPN PPN acces s x x r/w xf8 x r/w x x r/w x x read Change to read only Core Core Process ID VPN PPN acces s x x r/w xf8 x r/w x x r/w x x read Change to read only Core xf8 x r/w x x read Core xf8 x r/w x x read TLB management Core Core Core Process ID VPN PPN acces s x x r/w xf8 x r/w x x r/w x x read xf8 x r/w x x read Change to read only Process on core can only contnue once shootdown s complete! Keepng TLBs consstent. Hardware TLB coherence Integrate TLB mgmt wth cache coherence Invaldate TLB entry when PTE changes Rarely mplemented. Vrtual caches Requred cache flush / nvaldate wll take care of the TLB Hgh context swtch cost! Most processors use caches. Software TLB shootdown Most common OS on one core notfes all other cores - Typcally an IPI Each core provdes local nvaldaton 6. Hardware shootdown nstructons Broadcast specal access on the bus Interpreted as TLB shootdown rather than cache coherence message E.g., PowerPC archtecture Our Small Quz True or false (rase hand). Base (relocaton) and lmt regsters provde a full vrtual. Base and lmt regsters provde protecton. Segmentaton provdes a base and lmt for each segment. Segmentaton provdes a full vrtual. Segmentaton allows lbrares to share ther code 6. Segmentaton provdes lnear ng 7. Segment tables are set up for each process n the CPU 8. Segmentng prevents nternal fragmentaton 9. Pagng prevents nternal fragmentaton. Protecton nformaton s stored at the frame. Pages can be shared between processes. The same may be wrteable n proc. A and wrte protected n proc. B. The same can be references through dfferent es from (a) two dfferent processes (b) the same process?. Inverted tables are faster to search than herarchcal (asymptotcally) Today Uses for vrtual Copy-on-wrte Demand pagng Page fault handlng Page replacement algorthms Frame allocaton polces Thrashng and workng set Book: OSPP Sectons 9., 9.7 (all of 9 as refresh)

Recap: Vrtual Memory The many uses of translaton User logcal. Only part of the program must be n RAM for executon Logcal can be larger than Address s can be shared by several processes More effcent process creaton Vrtualze usng software+hardware Process solaton Memory mapped fles IPC Vrtual Shared code segments Checkpont and restart Program ntalzaton Persstent data structures Effcent dynamc allocaton Process mgraton Cache management Informaton flow control Program debuggng Dstrbuted shared Effcent I/O and many more Recall fork() Copy-on-wrte (COW) Can be expensve to create a complete copy of the process Especally just to do exec()! vfork(): shares, doesn t copy Fast Dangerous two wrters to same heap Better: only copy when you know somethng s gong to get wrtten Copy-on-Wrte Example: processes sharng an area of COW allows both parent and chld processes to ntally share the same s n If ether process modfes a shared, only then s the coped COW allows more effcent process creaton as only modfed s are coped A B Free s are allocated from a pool of zeroed-out s C Process Process

Example: processes sharng an area of How does t work? A B C Not necessarly the same vrtual es (but would be after fork()) Intally mark all s as read-only Ether process wrtes fault Fault handler allocates new frame Makes copy of n new frame Maps each copy nto resp. processes wrteable Only modfed s are coped Less usage, more sharng Cost s fault for each mutated Process Process After process wrtes to C After process wrtes to C A A Stll read-only B B C C copy of C copy of C Process Process Process Process After process wrtes to C General prncple Mark a VPN as nvald or readonly trap ndcates attempt to read or wrte On a fault, change mappngs somehow Restart nstructon, as f nothng had happened A B Stll read-only General: allows emulaton of as well as multplexng. E.g. on-demand zero-fllng of s And Now wrteable C copy of C Process Process

Pagng concepts Pagng concepts -resdent v vrtual table dsk v vrtual table dsk Pagng concepts Pagng concepts Wrte drty s out to dsk v vrtual table Keep track of where s are on dsk dsk v vrtual table Keep track of where s are on dsk dsk Pagng concepts Demand Pagng Read n s from dsk on demand Brng a nto only when t s needed Less I/O needed Less needed Faster response More users Turns RAM nto a cache for processes on dsk! v vrtual table dsk

Demand Pagng Page needed reference (load or store) to t nvald reference abort not-n- brng to Lazy swapper never swaps a nto unless wll be needed Swapper that deals wth s s a r Can do ths wth segments, but more complex Strct demand pagng: only n when referenced Page Fault If there s a reference to a, frst reference to that wll trap to operatng system: fault. Operatng system looks at another table to decde: Invald reference abort Just not n. Get empty frame. Swap nto frame. Reset tables. Set vald bt v 6. Restart the nstructon that caused the fault Recall: handlng a fault Recall: handlng a fault ExcepHon Page fault handler CPU Chp CPU VA MMU PTEA PTE Cache/ Memory Dsk CPU Chp CPU VA MMU PTEA PTE Cache/ Memory Dsk ) Processor sends vrtual to MMU -) MMU fetches PTE from table n ) Vald bt s zero, so MMU trggers fault excepton ) Handler dentfes vctm (and, f drty, s t out to dsk) 6) Handler s n new and updates PTE n 7) Handler returns to orgnal process, restartng faultng nstructon ) Processor sends vrtual to MMU -) MMU fetches PTE from table n ) Vald bt s zero, so MMU trggers fault excepton ) Handler dentfes vctm (and, f drty, s t out to dsk) 6) Handler s n new and updates PTE n 7) Handler returns to orgnal process, restartng faultng nstructon Recall: handlng a fault Recall: handlng a fault ExcepHon Page fault handler ExcepHon Page fault handler CPU Chp CPU VA MMU PTEA PTE Cache/ Memory Dsk CPU Chp CPU VA MMU PTEA PTE Cache/ Memory New 6 Dsk ) Processor sends vrtual to MMU -) MMU fetches PTE from table n ) Vald bt s zero, so MMU trggers fault excepton ) Handler fnds a frame to use for mssng 6) Handler s n new and updates PTE n 7) Handler returns to orgnal process, restartng faultng nstructon ) Processor sends vrtual to MMU -) MMU fetches PTE from table n ) Vald bt s zero, so MMU trggers fault excepton ) Handler fnds a frame to use for mssng 6) Handler s n new and updates PTE n 7) Handler returns to orgnal process, restartng faultng nstructon 6

Recall: handlng a fault ExcepHon Page fault handler Performance of demand pagng Page Fault Rate p. f p = : no faults f p = : every reference s a fault CPU Chp CPU VA 7 MMU PTEA ) Processor sends vrtual to MMU -) MMU fetches PTE from table n ) Vald bt s zero, so MMU trggers fault excepton ) Handler fnds a frame to use for mssng Cache/ Memory 6) Handler s n new and updates PTE n 7) Handler returns to orgnal process, restartng faultng nstructon PTE New 6 Dsk Effectve Access Tme (EAT) EAT = ( p) x access + p ( fault overhead + swap out + swap n + restart overhead ) Demand pagng example Memory access tme = nanoseconds Average -fault servce tme = 8 mllseconds EAT = ( p) x + p (8 mllseconds) = ( p) x + p x 8,, = + p x 7,999,8 Page Replacement If one access out of, causes a fault, then EAT = 8. mcroseconds. Ths s a slowdown by a factor of!! What happens f there s no free frame? Page replacement fnd lttle used resdent to dscard or wrte to dsk vctm needs selecton algorthm performance want an algorthm whch wll result n mnmum number of faults Same may be brought nto several tmes Page replacement Try to pck a vctm whch won t be referenced n the future Varous heurstcs but ultmately t s a guess Use modfy bt on PTE Don t wrte clean (unmodfed) to dsk Try to pck clean s over drty ones (save a dsk wrte) 7

Page replacement Page replacement frame vald frame vald. Swap vctm to dsk f v f vctm f v f vctm Page table Page table Physcal Physcal Page replacement Page replacement frame vald. Swap vctm to dsk frame vald f vctm f vctm. Change vctm PTE to nvald Page table Page table. Load desred n from dsk Physcal Physcal Page replacement Page replacement algorthms Want lowest -fault rate frame vald. Change fault PTE to vald Evaluate algorthm by runnng t on a partcular strng of references (reference strng) and computng the number of faults on that strng f v f vctm E.g. 7,,,,,,,,,,,,,,,,, 7,, Page table. Load desred n from dsk Physcal 8

Page faults vs. number of frames FIFO (Frst-In-Frst-Out) replacement Very lttle : thrashng (see later) What we mght expect 7 7 Number of faults Plenty of : more doesn t help much Number of frames FIFO (Frst-In-Frst-Out) replacement FIFO (Frst-In-Frst-Out) replacement 7 7 7 7 7 7 7 FIFO (Frst-In-Frst-Out) replacement FIFO (Frst-In-Frst-Out) replacement 7 7 7 7 7 7 7 7 7 7 9

FIFO (Frst-In-Frst-Out) replacement FIFO (Frst-In-Frst-Out) replacement 7 7 7 7 7 7 7 7 7 7 FIFO (Frst-In-Frst-Out) replacement FIFO (Frst-In-Frst-Out) replacement 7 7 7 7 7 7 7 7 7 7 7 7 7 Here, faults. More s better? More s better? Reference strng:,,,,,,,,,,, Reference strng:,,,,,,,,,,, frames ( s can be n ): Belady s Anomaly: more frames more faults Belady s Anomaly: more frames more faults

More s better? More s better? Reference strng:,,,,,,,,,,, frames ( s can be n ): Reference strng:,,,,,,,,,,, frames ( s can be n ): Belady s Anomaly: more frames more faults Belady s Anomaly: more frames more faults More s better? More s better? Reference strng:,,,,,,,,,,, frames ( s can be n ): Reference strng:,,,,,,,,,,, frames ( s can be n ): 9 faults Belady s Anomaly: more frames more faults Belady s Anomaly: more frames more faults More s better? More s better? Reference strng:,,,,,,,,,,, frames ( s can be n ): Reference strng:,,,,,,,,,,, frames ( s can be n ): 9 faults 9 faults Belady s Anomaly: more frames more faults Belady s Anomaly: more frames more faults

More s better? More s better? Reference strng:,,,,,,,,,,, frames ( s can be n ): Belady s Anomaly: more frames more faults 9 faults faults! Reference strng:,,,,,,,,,,, frames ( s can be n ): Belady s Anomaly: more frames more faults 9 faults faults! FIFO showng Belady s Anomaly Optmal algorthm Replace that wll not be used for longest perod of tme Number of faults frames example: 6 faults Number of frames How do you know ths? you can t! Used for measurng how well your algorthm performs Optmal replacement Least Recently Used (LRU) algorthm 7 7 7 7 7 7 Here, 9 faults. Reference strng: Counter mplementaton Every entry has a counter; every tme s referenced through ths entry, copy the clock nto the counter When a needs to be changed, look at the counters to determne whch are to change

LRU replacement LRU algorthm 7 7 7 7 7 7 Here, faults. Stack mplementaton keep a stack of numbers n a double lnk form: Page referenced: move t to the top requres 6 ponters to be changed No search for replacement General term: stack algorthms Have property that addng frames always reduces faults (no Belady s Anomaly) Use a stack to record most recent references 7 7 7 Reference strng 7 LRU approxmaton algorthms Reference bt Wth each assocate a bt, ntally = When s referenced bt set to Replace a whch s (f one exsts) We do not know the order, however Second chance Need reference bt Clock replacement If to be replaced (n clock order) has reference bt = then: set reference bt leave n replace next (n clock order), subject to same rules 7 Second-chance (clock) replacement algorthm Second-chance (clock) replacement algorthm Next vctm ( clock hand ) Crcular queue of s Next vctm ( clock hand ) Crcular queue of s Reference bts Reference bts

Second-chance (clock) replacement algorthm Second-chance (clock) replacement algorthm Next vctm ( clock hand ) Crcular queue of s Next vctm ( clock hand ) Crcular queue of s Reference bts Reference bts Allocaton of frames Frame allocaton polces Each process needs mnmum number of s Example: IBM 7 6 s to handle SS MOVE nstructon: nstructon s 6 bytes, mght span s s to handle from s to handle to Two major allocaton schemes fxed allocaton prorty allocaton Fxed allocaton Prorty allocaton Equal allocaton all processes get equal share Proportonal allocaton allocate accordng to the sze of process Proportonal allocaton scheme Usng prortes rather than sze If process P generates a fault, select:. one of ts frames, or. frame from a process wth lower prorty s = szeof process p S = s m = total number of frames s a = allocaton for p = m S m = 6 s = s = 7 a = 6 7 7 a = 6 9 7

Global vs. local allocaton Global replacement process selects a replacement frame from the set of all frames; one process can take a frame from another Local replacement each process selects from only ts own set of allocated frames Thrashng If a process does not have enough s, the fault rate s very hgh. Ths leads to: low CPU utlzaton operatng system thnks that t needs to ncrease the degree of multprogrammng another process added to the system Thrashng a process s busy swappng s n and out Source: wkpeda Thrashng Demand pagng and thrashng Useful CPU utlzaton Thrashng begns! Why does demand pagng work? Localty model Process mgrates from one localty to another Localtes may overlap Why does thrashng occur? Σ sze of localtes > total sze Demand for vrtual (e.g., more procs) Localty n a reference pattern Workng-set model Δ workng-set wndow a fxed number of references Example:, nstructon WSS (workng set of Process P ) = total number of s referenced n the most recent Δ (vares n tme) Δ too small wll not encompass entre localty Δ too large wll encompass several localtes Δ = wll encompass entre program

Allocate demand frames D = Σ WSS total demand frames Intuton: how much s really needed Workng-set model Page D > m Thrashng Polcy: f D > m, suspend some processes... 6 7 7 7 7 6... Δ Δ WS(t ) = {,,,6,7} t WS(t ) = {,} t Keepng track of the workng set Approxmate wth nterval tmer + a reference bt Example: Δ =, Tmer nterrupts after every tme unts Keep n bts for each Whenever a tmer nterrupts shft+copy and sets the values of all reference bts to If one of the bts n = n workng set Why s ths not completely accurate? Hnt: Nyqust-Shannon! Keepng track of the workng set Approxmate wth nterval tmer + a reference bt Example: Δ =, Tmer nterrupts after every tme unts Keep n bts for each Whenever a tmer nterrupts shft+copy and sets the values of all reference bts to If one of the bts n = n workng set Why s ths not completely accurate? Improvement = bts and nterrupt every tme unts Page-fault frequency scheme Establsh acceptable -fault rate If actual rate too low, process loses frame If actual rate too hgh, process gans frame Rate of faults Increase number of frames Upper bound Lower bound Number of frames Decrease number of frames 6