Last class: Today: Paging. Virtual Memory

Similar documents
Virtual Memory Outline

Chapter 9: Virtual-Memory

Module 9: Virtual Memory

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

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 9: Virtual Memory

Module 9: Virtual Memory

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

Chapter 9: Virtual Memory

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

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

Virtual Memory Design and Implementation

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

Chapter 10: Virtual Memory. Background

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

Chapter 9: Virtual Memory

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

Chapter 8: Virtual Memory. Operating System Concepts

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

CS370 Operating Systems

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

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

Chapter 6: Demand Paging

Virtual Memory Design and Implementation

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

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

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

Where are we in the course?

1. Background. 2. Demand Paging

Virtual Memory COMPSCI 386

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

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

Operating System Concepts

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

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

Operating Systems. Operating Systems Sina Meraji U of T

OPERATING SYSTEM. Chapter 9: Virtual Memory

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

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

CS307: Operating Systems

Memory management, part 2: outline

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

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

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

Chapters 9 & 10: Memory Management and Virtual Memory

Page replacement algorithms OS

CS370 Operating Systems

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

! What is virtual memory and when is it useful? ! What is demand paging? ! What pages should be. ! What is the working set model?

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

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

10/9/2013 Anthony D. Joseph and John Canny CS162 UCB Fall 2013

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

VIRTUAL MEMORY READING: CHAPTER 9

CS370 Operating Systems

Chapter 10: Virtual Memory

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Virtual Memory Design and Implementation

CS 550 Operating Systems Spring Memory Management: Page Replacement

Operating System Concepts 9 th Edition

Computer Systems II. Memory Management" Subdividing memory to accommodate many processes. A program is loaded in main memory to be executed

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

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

a. What is a lower bound on the number of page faults? b. What is an upper bound on the number of page faults?

Lecture 14 Page Replacement Policies

CS 153 Design of Operating Systems Winter 2016

CSE 120 Principles of Operating Systems

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

Paging and Page Replacement Algorithms

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Operating Systems Lecture 6: Memory Management II

Principles of Operating Systems

Operating System - Virtual Memory

Virtual Memory III. Jo, Heeseung

Basic Memory Management

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

Lecture 12: Demand Paging

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

CS510 Operating System Foundations. Jonathan Walpole

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

First-In-First-Out (FIFO) Algorithm

Practice Exercises 449

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

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

Introduction to Virtual Memory Management

Page Replacement Algorithms

UNIT - IV. What is virtual memory?

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

CS370 Operating Systems

Memory: Paging System

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

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

Chapter 4 Memory Management

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

Virtual Memory Management

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

Last Class: Demand Paged Virtual Memory

Transcription:

Last class: Paging Today: Virtual Memory

Virtual Memory What if programs require more memory than available physical memory? Use overlays ifficult to program though! Virtual Memory. Supports programs that are larger than available physical memory. llows several programs to reside in physical memory (or at-least the relevant portions of them). llows non-contiguous allocation without making programming difficult.

Example Virtual ddress Space-1 (1 M) Physical Memory (16 K).. Virtual ddress Space-2 (1 M) Virtual ddress Space-n (1 M)

Page Faults If a Page-table mapping indicates an absence of the page in physical memory, hardware raises a Page- Fault. OS traps this fault and the interrupt handler services the fault by initiating a disk-read request. Once page is brought in from disk to main memory, page-table entry is updated and the process which faulted is restarted. May involve replacing another page and invalidating the corresponding page-table entry.

Page Table When Some Pages re Not in Main Memory

Page Fault If there is a reference to a page, first reference to that page will trap to operating system: page fault Operating system looks at another table to decide: Invalid reference -- abort Just not in memory Get empty frame Swap page into frame Reset tables Set validation bit = v Restart the instruction that caused the page fault

Steps in Handling a Page Fault

Performance of emand Paging Page Fault Rate 0 p 1.0 if p = 0 no page faults if p = 1, every reference is a fault Effective ccess Time (ET) ET = (1 p) x memory access + p (page fault overhead + swap page out + swap page in + restart overhead)

emand Paging Example Memory access time = 200 nanoseconds verage page-fault service time = 8 milliseconds ET = (1 p) x 200 + p (8 milliseconds) = (1 p x 200 + p x 8,000,000 = 200 + p x 7,999,800 If one access out of 1,000 causes a page fault, then ET = 8.2 microseconds. This is a slowdown by a factor of 40!!

Putting it all together! VS before execution int [2K]; int [2k]; main() { int i, j, p; p = malloc(16k); } P Heap Pointer Stack Pointer 0x0 0 No Page table Entries here ll Point To Null (i.e. fault the first time) 4K page size 0xf f Page Table

fter executing malloc Malloc/free first manipulate this space (using buddy, ) If out of Space, call OS To allocate more PT entries (using sbrk()) P Heap Pointer Stack Pointer 0x0 0 No Page table Entries here These re still Null!, and remain so Until you access a Page here 0xf f Page Table Note: you are not allocating physical memory using malloc()

Page Replacement When bringing in a page, something has to be evicted. What should we evict? page replacement algorithm.

Optimal Page Replacement Why optimal? lgorithm No other algorithm can have # of page faults lower than this, for a given page reference stream. lgorithm: t any point, amongst the given pages in memory, evict the one whose next reference from now is the furthest in the future.

n example of OPT Reference String... 5, 3, 3, 5, 2, 4, 4, 3, 2,.. t this point, what do we replace? urrent Physical Memory 5 3 4 Evict 2

Problem with OPT Not implementable! Requires us to know the future. ut it has the best page fault behavior How do we approach OPT?

1. First-in First-out Maintain a linked list of pages in the order they were brought into PM. On a page fault, evict the one at the head. Put the newly brought in page (from disk) at tail of this list. Problems: Reference String: 1,2,3,4,1,1,5,1,1, Page fault at (5) would replace (1)! Need to know what is in recent use!

2. Not Recently Used Referenced bit set on each Read/write by h/w Modified set on each write by h/w On startup set both R and M bits to 0. Periodically (using clock interrupts) the R bit is cleared. On a page fault, examine the state of a page lass 0: R = M = 0 lass 1: R = 0, M = 1 lass 2: R = 1 M = 0 lass 3: R = 1 M = 1 NRU replaces a page chosen at random from the lowest numbered nonempty class.

3. Second hance Replacement or lock lgorithm Same as FIFO, except you skip over the pages whose reference bit is set, resetting this bit, and moving those pages to end of list. Implementation: 1 0 0 1 1 1 1 0 0 1 0 0 0 0 0 0 Evict

4. Least Recently Used Order the list of physical memory pages in decreasing order of recency of usage. Replace the page at the tail. Problem: This list will need to be updated on each memory reference. sking the h/w to do this is ridiculous! Solution: pproximate LRU

5. pproximate LRU using counters Keep a counter for each Phys page. Initially set to 0. t the end of each time interval (interval to be determined), shift the bits right by one position. opy the reference bit to the MS of counter and reset reference. For a page replacement, pick the one with the lowest counter value. It is an approximation of LRU because: we do not differentiate between references that occured in the same tick. the history is limited by the size of the counter.

Summary of page replacement algorithms OPT, FIFO, NRU, second-chance/clock, LRU, approximate LRU In practice, OSes use second chance/clock or some variations of it.

elady s nomaly Normally you expect number of page faults to decrease as you increase physical memory size. However, this may not be the case in certain replacement algorithms

Example of elady s nomaly FIFO replacement lgorithm Reference string: 0 1 2 3 0 1 4 0 1 2 3 4 3 physical frames F F F F F F F - - F F - # of faults = 9 4 physical frames F F F F - - F F F F F F # of faults = 10

lgorithms which do NOT suffer from elady s anomaly are called stack algorithms E.g. OPT, LRU.

Modeling Paging Paging behavior characterized by Reference string Physical memory size Replacement algorithm

e.g.,, and Visualize it as a stack (say M), where a page that is referenced is brought to the top of the stack from wherever it is. are virtual pages Move own When is referenced

Whatever is in recent use is on the top of M, and the ones that are not in recent use are at the bottom. In fact, the top P entries of M represent the pages in physical memory, where P is the # of physical frames. In memory On isk

istance String: For each element of reference string, this represents the distance of that element from the top of stack in M.

n example of how M changes with 5 virtual pages E E E E E E E E 3 3 2 2 4 4 4 Reference String istance String

efine vector [i] represents the number of times i appears in the distance string.

E E E E E E E E 3 3 2 2 4 4 4 Reference String istance String vector: [0]=0, [1]=0, [2]=2, [3]=2, [4]=3, [5] =0 [ ]=5

efine Vector F F[j] is the number of page faults that will occur for the given reference string with j physical frames. F[j] = [j] + [j+1] + [j+2] + [j+3] + [ ]

It is now straightforward to prove LRU does not suffer from elady s anomaly. The M vector tracks what is in physical memory in the top P slots for LRU. Note that vector [i] is independent of physical memory size. When you go from physical memory with j frames to (j +x) frames, note that the number of vector terms in the RHS of equation for F decreases => Page faults can only decrease if at all!

Paging Issues Keep the essentials of what you currently need (working set) in physical memory. When something you need is not in memory, bring it in from disk: On demand (demand-paging) head of need (pre-paging) Programs need to exhibit good locality to avoid thrashing of pages in memory. This usually requires good programming skills!

Fragmentation in paging Note that there is only internal fragmentation, and that too only in the last allocated page. Smaller the page, smaller the internal fragmentation. However, this reduces spatial locality.

Page size trade-offs verage process size = s bytes Page size = p bytes Page Table entry = e bytes Overhead = s.e/p + p/2 To minimize, p = sqrt(2.s.e)

Page Replacement Virtual memory Page faults Summary Optimal page replacement not achievable Variety of algorithms nomalies

Next time: Virtual memory issues