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

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

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

Chapter 6: Demand Paging

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

ELEC 377 Operating Systems. Week 6 Class 3

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

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

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. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007

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

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

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

Chapter 9: Virtual Memory

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

Chapter 10: Virtual Memory. Background

Chapter 9: Virtual-Memory

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

Operating System Concepts

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

OPERATING SYSTEM. Chapter 9: Virtual 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. CSCI 315 Operating Systems Design Department of Computer Science

Where are we in the course?

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

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

CS420: Operating Systems

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

CS307: Operating Systems

Chapter 5: Memory Management

Virtual Memory Outline

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

Virtual Memory COMPSCI 386

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

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

Chapter 10: Virtual Memory

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

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Operating System Concepts 9 th Edition

VIRTUAL MEMORY READING: CHAPTER 9

CS370 Operating Systems

Virtual Memory III. Jo, Heeseung

Memory and I/O Organization

Basic Memory Management

Efficient Distributed File System (EDFS)

Real-Time Guarantees. Traffic Characteristics. Flow Control

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

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

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

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

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

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

Principles of Operating Systems

Page Replacement Algorithms

Assembler. Building a Modern Computer From First Principles.

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

Basic Page Replacement

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

Chapter 9: Virtual Memory

Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory Management

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

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

Signal types (some of them) Networks and Operating Systems ( ) Chapter 5: Memory Management. Where do signals come from?

kccvoip.com basic voip training NAT/PAT extract 2008

Operating Systems. Operating Systems Sina Meraji U of T

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

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

Chapter 4 Memory Management

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

Memory management, part 2: outline

First-In-First-Out (FIFO) Algorithm

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

Problem Set 3 Solutions

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

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

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

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

Lecture 12: Demand Paging

CE 221 Data Structures and Algorithms

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

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

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Memory Management Ch. 3

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

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

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).

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier

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

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

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

Chapters 9 & 10: Memory Management and Virtual Memory

Transcription:

ADRIAN PERRIG & TORSTEN HOEFLER ( -6- ) Networks and Operatng Systems Chapter 6: Demand Pagng Page Table Structures Page table structures Page table structures Problem: smple lnear table s too bg Problem: smple lnear table s too bg Solutons:. Herarchcal tables. Vrtual tables. Hashed tables. Inverted tables Solutons:. Herarchcal tables. Vrtual tables (VAX). Hashed tables. Inverted tables Saw these last Semester. # Hashed Page Tables Hashed Page Table VPN s hashed nto table Hash bucket has chan of logcal-> mappngs Hash chan s traversed to fnd match. Can be fast, but can be unpredcable Often used for Portablty Software-loaded TLBs (e.g., MIPS) logcal p d r d hash functon q s p r hash table

# Inverted Page Table Inverted Page Table Archtecture One system-wde table now maps PFN -> VPN One entry for each real of Contans VPN, and whch process owns the Bounds total sze of all nformaton on machne Hashng used to locate an entry effcently Examples: PowerPC, a6, UltraSPARC CPU logcal pd p d d Physcal search pd p table The need for more bookkeepng Most OSes keep ther own translaton nfo Per-process herarchcal table (Lnux) System wde nverted table (Mach, MacOS) Why? Portablty Trackng objects Software vrtual translaton Physcal vrtual translaton 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 shared lbrares Segmentaton provdes lnear ng Segment tables are set up for each process n the CPU Segmentng prevents nternal fragmentaton 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 7

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 " Keep track of where s are on dsk table dsk v vrtual " Keep track of where s are on dsk table 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 6

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 valdaton bt = v 6. Restart the nstructon that caused the fault Recall: handlng a fault Recall: handlng a fault ExcepIon 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 ExcepIon Page fault handler ExcepIon 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 7

Recall: handlng a fault ExcepIon 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 Cache/ Memory ) 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 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 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) 8

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 f v Page table. Change fault PTE to vald f vctm Evaluate algorthm by runnng t on a partcular strng of references (reference strng) and computng the number of faults on that strng E.g. 7,,,,,,,,,,,,,,,,, 7,,. Load desred n from dsk Physcal 9

Page faults vs. number of frames FIFO (Frst-In-Frst-Out) replacement Very lttle : thrashng (see later) What we mght expect reference strng: 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 reference strng: 7 7 reference strng: 7 7 7 7 7 FIFO (Frst-In-Frst-Out) replacement FIFO (Frst-In-Frst-Out) replacement reference strng: 7 7 reference strng: 7 7 7 7 7 7 7 7

FIFO (Frst-In-Frst-Out) replacement FIFO (Frst-In-Frst-Out) replacement reference strng: 7 7 reference strng: 7 7 7 7 7 7 7 7 FIFO (Frst-In-Frst-Out) replacement FIFO (Frst-In-Frst-Out) replacement reference strng: 7 7 reference strng: 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 reference strng: 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 reference strng: 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 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 localty > 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 6

Allocate demand frames D = Σ WSS total demand frames Intuton: how much s really needed Workng-set model Page reference strng: D > m Thrashng Polcy: f D > m, suspend some processes... 6 7 7 7 7 6 Workng-set model Workng-set model Page reference strng: Page reference strng:... 6 7 7 7 7 6... 6 7 7 7 7 6 Δ Δ Δ WS(t ) = {,,,6,7} t 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 7

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 8