Chapter 9: Virtual Memory

Similar documents
Operating System - Virtual Memory

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

Chapter 9: Virtual-Memory

Chapter 9: Virtual Memory

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

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

Module 9: Virtual Memory

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

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

Module 9: Virtual Memory

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

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

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

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 9: Virtual Memory

CS420: Operating Systems

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

Virtual Memory COMPSCI 386

CS370 Operating Systems

CS307: Operating Systems

Virtual Memory Outline

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

1. Background. 2. Demand Paging

OPERATING SYSTEM. Chapter 9: Virtual Memory

Chapter 10: Virtual Memory. Background

Chapters 9 & 10: Memory Management and Virtual Memory

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

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

Chapter 9: Virtual Memory

CS370 Operating Systems

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

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

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

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

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

Chapter 10: Virtual Memory

Introduction to Virtual Memory Management

Chapter 9: Virtual Memory

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

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

Operating System Concepts 9 th Edition

Virtual Memory - I. Roadmap. Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012


Where are we in the course?

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

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

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

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

Page Replacement Algorithms

CS510 Operating System Foundations. Jonathan Walpole

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

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

VII. Memory Management

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

Virtual Memory Design and Implementation

Principles of Operating Systems

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

Chapter 9: Virtual Memory

Frequently asked questions from the previous class survey

stack Two-dimensional logical addresses Fixed Allocation Binary Page Table

Chapter 6: Demand Paging

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

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

Basic Page Replacement

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

Chapter 4 Memory Management

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

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

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

Operating System Concepts

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

CS370 Operating Systems

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

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

Course: Operating Systems Instructor: M Umair. M Umair

Basic Memory Management

CS399 New Beginnings. Jonathan Walpole

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

Operating System 1 (ECS-501)

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

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

First-In-First-Out (FIFO) Algorithm

CS370 Operating Systems

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Main Memory (Part I)

Memory Management. 3. What two registers can be used to provide a simple form of memory protection? Base register Limit Register

CS450/550 Operating Systems

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

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

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

Address spaces and memory management

UNIT - IV. What is virtual memory?

Virtual Memory CHAPTER CHAPTER OBJECTIVES. 8.1 Background

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. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

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

12: Memory Management

MEMORY MANAGEMENT/1 CS 409, FALL 2013

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

Transcription:

Chapter 9: Virtual Memory

Multiprogramming Memory Management so far 1. Dynamic Loading The main Program gets loaded into memory Routines are stored in Relocatable Load format on disk As main program (or subsequently loaded routine) executes it calls other routines The calling program checks if called routine is loaded? Reference the called routine Else: Calling program calls Relocatble Linker Loader to load Routine into memory Reloactable Linker Loader updates address space of calling program 2. Dynamic Linking A stub is included into the image of each library routine reference Locates appropriate memory-resident library routine(s) Indicates how to load the library routine(s) Operating Systems CS 33211 2

Multiprogramming Memory Management so far 3. Swapping A process is swapped temporarily out of memory to fast and large disk, and then brought back into memory for continued execution Round-Robin CPU Scheduling using time slice 4. Paging 5. Segmentation Operating Systems CS 33211 3

Multiprogramming Memory Management Techniques so far Let s Summarize Goal: Simultaneously keep several processes in memory to facilitate multiprogramming Require an entire process to be in memory to execute Dynamic Loading and Dynamic Linking are exceptions But require extra work by programmer Program size cannot exceed size of physical memory Operating Systems CS 33211 4

Multiprogramming Memory Management Technique Virtual Memory Background Allows execution of processes that are not completely in memory Program not constrained by size of physical memory Increased CPU utilization Increased throughput Operating Systems CS 33211 5

Multiprogramming Memory Management Technique Virtual Memory Virtual memory separation of user s view of logical memory from physical memory. Virtual memory is typically larger than physical memory Process Logical address space can therefore be much larger than physical address space. Process is modeled as a sequence of Pages At time t i, Page may be in either i. Physical memory ii. High speed disk Operating Systems CS 33211 6

Virtual Memory Address Space Virtual Address Space: Logical view of how process is stored in memory Contiguous page frames Fixed starting logical address (0) MMU maps contiguous logical frames to non contiguous physical frames Utilizing the Hole Heap used for dynamic memory allocation Stack - used for successive function calls Dynamically link libraries during execution Dynamically link shared objects during execution Operating Systems CS 33211 7

Virtual Memory Shared Library Utilizing the Hole (Sparse address) Allows files and memory to be shared by two or more processes during execution System libraries Object(s) mapped to process virtual address space Shared memory Inter-process communication Process P creates a set of pages for sharing with other Processes The other processes consider shared pages as part of their virtual address space Operating Systems CS 33211 8

Virtual Memory Systems Demand Paging How are executable programs loaded from disk to memory? At init, one or more virtual pages will be in Physical memory or fast high speed disk (secondary memory) The pager ( swapper ) guesses which pages should be swapped in before the process is swapped out Next, Virtual Pages are loaded into Memory as they are needed (Demand Paging) eg., When a page fault occurs Too many page faults may lead to performance bottlenecks? Need a technique to decrease swap time Operating Systems CS 33211 9

Demand Paging Basic Concept Need to distinguish between pages that are in memory and pages on the disk Use Valid-Invalid Bits: Valid page is legal and in memory invalid page is not in logical address space of the process or page is valid, but currently on disk Access to a page designated as an invalid in the page table: Page fault trap to OS Trap OS cannot move desired page int memory Operating Systems CS 33211 10

Demand Paging Handling Page Fault 1. Check internal table in PCB if reference is valid 2. If invalid (i), terminate process. If valid but page is not in physical memory (i) bring page in mem: 3. Seek a free frame 4. Schedule disk operation to move The page into free frame (pure demand paging) Alt. move page and its neighbors to free frames (locality of reference ) 5. When step 4 is complete, modify page table and internal table 6. Restart interrupted instruction Operating Systems CS 33211 11

Demand Paging Performance Page Fault Rate 0 p 1.0 if p = 0 no page faults if p = 1, every reference is a fault Effective Access Time (EAT) EAT = (1 p) x memory access + p (page fault overhead + swap page out + swap page in + restart overhead) Operating Systems CS 33211 12

Performance of Demand Paging Example Memory access time = 1 microsecond 50% of the time the page that is being replaced has been modified and therefore needs to be swapped out Swap Page Time = 10 msec = 10,000 msec EAT = (1 p) x 1 + p (15000) 1 + 15000P (in msec) Operating Systems CS 33211 13

Page Replacement Basic Method The OS needs to allocate a frame to a process but there are no available free frames, what happens? OS makes room in memory by copying a page from its frame to the disk (backing store) Each Page of a frame is associated with a Modify bit (or dirty bit) Bit set by hardware whenever word/byte is written to frame 1. Select location of desired page on disk. 2. Find a free frame If one exists, use it Otherwise use a Page Replacement algorithm to select a victim Select a page for replacement & Examine its Modify bit If modify bit is set Page has been modified since it was copied into memory a. Write victim Page to disk b. Change the victim Page and Frame tables Otherwise, Page has not been modified since it was brought into memory a. No need to write the page to disk 3. Read the desired Page into newly freed frame; change the page and frame table 4. Restart the user process How does OS select a page to copy to disk? Use a page Replacement policy Random Take any page (victim) FIFO Select Page in Memory for the longest LEAST Recently Used Use the page that has not been referenced for the longest period We will talk about these shortly Operating Systems CS 33211 14

Page Replacement Operating Systems CS 33211 15

Demand Paging Page-Replacement and Frame Allocation Page replacement & Frame Allocation compliment Demand Paging Process with 20 pages can be executed with 10 or less frames. How? Use Page Replacement Algorithm Assume multiple Processes reside in memory How do you efficiently allocate frames to each process? Use page Allocation Algorithm Operating Systems CS 33211 16

Page-Replacement Algorithm Attributes Goal: Seek lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string Reference String: Assume memory address sequence with 100 bytes/page: 0100, 0102, 0202, 0103, 0300, 0401, 0106, 0207, 0505, 0106, 0204, 0301, 0404, 0508 Reference String: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Operating Systems CS 33211 17

Page-Replacement Algorithm First-In First-out (FIFO) FIFO Record time when each page is brought into memory Replace Page with oldest time Assume reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 2 3 1 2 3 4 1 2 5 3 4 9 page faults with 3 frames 3 frames 3 pages can be in memory at a time per process 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 4 frames 4 pages can be in memory at a time per process 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 2 3 1 2 3 5 1 2 4 4 3 4 5 10 page faults with 4 frames Operating Systems CS 33211 18

FIFO Page-Replacement Algorithm Operating Systems CS 33211 19

Optimal Page-Replacement Algorithm OPT Basic idea: Replace the page that will not be used for the longest period of time Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 2 3 4 6 page faults with 4 frames 4 5 Challenge: Implementation requires knowledge of the reference string a priori Benefit: To compare relative efficiency of other (or new) algorithms Has the lowest page-fault rate Operating Systems CS 33211 20

Optimal Page-Replacement Algorithm OPT Operating Systems CS 33211 21

Least Recently Used Algorithm LRU Basic idea: Replace the page that has not been used for the longest period of time Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 5 2 3 5 4 4 3 Counter implementation Associate each page entry with a counter Set the counter-timer each time the page is referenced When a page needs to be changed, look at the counters and select one with the longest period Operating Systems CS 33211 22

LRU Page Replacement Algorithm Operating Systems CS 33211 23

Allocation of Frames How do we allocate fixed amount of free memory amongst the various processes? Suppose there are 100 frames and two processes, how many does each get? Each process needs at least minimum number of pages. Why? Minimum value dictated by computer architecture Two major allocation schemes fixed allocation priority allocation Operating Systems CS 33211 24

Allocation Algorithms Equal allocation Algorithm For example, if there are 100 frames and 5 processes, give each process 20 frames. Do you see a disadvantage with this algorithm? Proportional allocation Algorithm Allocate according to the size of process Let m = number of available frames s i = size of process P i Then number of frames a i allocated to P i : a i = ( m s i s i ) Operating Systems CS 33211 25

Proportional Allocation Algorithm Priority proportional allocation based on priority A high-priority process selects frames from lower-priority processes for replacement If process P i generates a page fault, select for replacement one of its frames select for replacement a frame from a process with lower priority number Disadvantage: Low priority process cannot control its page fault rate. Why? Operating Systems CS 33211 26

Trashing If a process does not have enough frames to support pages, its page-fault rate will be very high. Why? This leads to: low CPU utilization operating system thinks that it needs to increase the degree of multiprogramming another process added to the system Thrashing a process is busy swapping pages in and out Performance degradation Use Local replacement or priority replacement to limit the effect of trashing Operating Systems CS 33211 27