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

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

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

Module 9: Virtual Memory

Module 9: Virtual Memory

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

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

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

Chapter 10: Virtual Memory. Background

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

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical 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

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

Chapter 9: Virtual-Memory

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

Chapter 9: Virtual Memory

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

Where are we in the course?

CS370 Operating Systems

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

CS370 Operating Systems

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

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

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

Chapter 8 Main Memory

Chapter 9: Virtual Memory

Chapters 9 & 10: Memory Management and Virtual Memory

Introduction to Virtual Memory Management

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

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

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

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

Operating Systems. Paging... Memory Management 2 Overview. Lecture 6 Memory management 2. Paging (contd.)

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

Chapter 8: Virtual Memory. Operating System Concepts

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

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

Chapter 9: Memory Management. Background

Operating System Concepts

Module 8: Memory Management

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

Basic Memory Management

Virtual Memory Outline

Memory Management. Memory Management

Principles of Operating Systems

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

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

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Chapter 8: Main Memory

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

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

Chapter 8: Main Memory

Part Three - Memory Management. Chapter 8: Memory-Management Strategies

Module 8: Memory Management

Logical versus Physical Address Space

Goals of Memory Management

OPERATING SYSTEM. Chapter 9: Virtual Memory

Module 9: Memory Management. Background. Binding of Instructions and Data to Memory

CS307: Operating Systems

Chapter 8 Virtual Memory

Chapter 8: Memory Management Strategies

CS 143A - Principles of Operating Systems

CS370 Operating Systems

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

Memory Management. Dr. Yingwu Zhu

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

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

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

8.1 Background. Part Four - Memory Management. Chapter 8: Memory-Management Management Strategies. Chapter 8: Memory Management

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

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

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

Chapter 8: Memory Management

CS 3733 Operating Systems:

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

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

I.-C. Lin, Assistant Professor. Textbook: Operating System Principles 7ed CHAPTER 8: MEMORY

Chapter 6: Demand Paging

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure.

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

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 8: MEMORY

Chapter 4 Memory Management

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

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

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

Virtual Memory COMPSCI 386

Chapter 8 Memory Management

CS420: Operating Systems

Main Memory. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & APPS 1

Chapter 10: Virtual Memory

VII. Memory Management

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Outlook. Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The Intel Pentium

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

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

Operating System Concepts 9 th Edition

Memory Management. Dr. Yingwu Zhu

Transcription:

CSE325 Principles of Operating Systems Virtual Memory David P. Duggan dduggan@sandia.gov March 7, 2013

Reading Assignment 9 Chapters 10 & 11 File Systems, due 3/21 3/7/13 CSE325 - Virtual Memory 2

Outline Paging Why virtual memory? Virtual memory organization Demand paging, handle page faults Page replacement Random Replacement Belady s Optimal Algorithm Least Recently Used (LRU) Least Frequently Used (LFU) First In First Out (FIFO) 3/7/13 CSE325 - Virtual Memory 3

Paging Fundamentals Memory management scheme Allows use of non-contiguous physical memory by a process Requires a backing store Requires hardware support 3/7/13 CSE325 - Virtual Memory 4

Basic Method Physical memory is structured into frames Logical memory is structured into pages Size of frames and pages are the same Backing store is structured into fixed-size blocks the same size as frames Addresses are divided into 2 parts Page number (p) [index into page table] Page offset [index into page] 3/7/13 CSE325 - Virtual Memory 5

Basic Method, Cont. Hardware support Could be implemented in registers Page-table base register (PTBR) Translation look-aside buffer (TLB) Small, usually 64 to 1024 entries Protection Pages can be set as read-only, read-write Page-table length register (PTLR) Page table has valid-invalid designators 3/7/13 CSE325 - Virtual Memory 6

Shared Pages Some code is pure, or reentrant, code Many processes can share those pages What types of programs might have reentrant code? 3/7/13 CSE325 - Virtual Memory 7

Page Tables Large memory space can make large page tables Can use a two-level page table structure Section, page, offset Hashed page tables Inverted page tables 3/7/13 CSE325 - Virtual Memory 8

Motivation for Virtual Memory Virtual memory separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Physical address space can be non-contiguous. Logical address space can therefore be much larger than physical address space. Allows address spaces to be shared by several processes. Allows for more efficient process creation. Virtual memory can be implemented via: Demand paging Demand segmentation 3/7/13 CSE325 - Virtual Memory 9

Virtual Memory Organization " Virtual Memory That is Larger Than Physical Memory 3/7/13 CSE325 - Virtual Memory 10

<1% 15% 35% 20% <1% 30% Why is virtual memory is a feasible idea? Address Space for P i Execution time Locality Address space is logically partitioned Text, data, stack Initialization, main, error handle Different parts have different reference patterns: 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 Is there any correlation between the size of a part of the address space and the amount of time that a process will execute in that locality? 11

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 compiletime address is not bound until run time 3/7/13 CSE325 - Virtual Memory 12

Virtual Memory (Cont.) Since binding changes with time, use a dynamic virtual address map, B t Virtual Address Space B t 3/7/13 CSE325 - Virtual Memory 13

Fragmented Virtual Address Space Secondary Memory Physical Address Space 0 Virtual Address Space for P i Virtual Address Space for P j Virtual Address Space for P k Complete virtual address space is stored in secondary memory Each address space is fragmented Fragments of the virtual address space are dynamically loaded into primary memory at any given time n-1 Primary Memory 14

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 3/7/13 CSE325 - Virtual Memory 15

Demand Paging Bring a page into memory only when it is needed (benefits?) Less I/O needed Less physical memory needed Faster response More users Page is needed? invalid reference abort reference to it not-in-memory bring to memory 3/7/13 CSE325 - Virtual Memory 16

Demand Paging A page is a fixed size, 2 h, block of virtual addresses A page frame is a fixed size, 2 h, 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 3/7/13 CSE325 - Virtual Memory 17

Valid-Invalid Bit With each page table entry a valid invalid bit is associated (1 in-memory, 0 not-in-memory) Initially valid invalid bit is set to 0 on all entries Example of a page table snapshot: Frame #" " page table" valid-invalid bit" 1" 1" 1" 1" 0" 0" 0" During address translation, if valid invalid bit in page table entry is 0 page fault 18

Page Table When Some Pages Are Not in Main Memory Important! 3/7/13 CSE325 - Virtual Memory 19

Page Fault If there is ever a reference to a page, first reference will trap to OS page fault OS looks at another table to decide: Invalid reference abort. Just not in memory. Find an empty frame. Swap page into frame. Reset tables, validation bit = 1. Restart instruction 3/7/13 CSE325 - Virtual Memory 20

Handling a Page Fault 3/7/13 CSE325 - Virtual Memory 21

Demand Paging Algorithm 1. Page fault occurs 2. Process with missing page is interrupted 3. Memory manager locates the missing page 4. Page frame is unloaded (replacement policy) 5. Page is loaded in the vacated page frame 6. Page table is updated 7. Process is continued with instruction that caused page fault 3/7/13 CSE325 - Virtual Memory 22

Addresses Suppose there are G= 2 g 2 h =2 g+h virtual addresses and H=2 j+h physical addresses assigned to a process Each page/page frame is 2 h addresses There are 2 g pages in the virtual address space 2 j page frames are allocated to the process Rather than map individual addresses B t maps the 2 g pages to the 2 j page frames That is, page_frame j = B t (page i ) Address k in page i corresponds to address k in page_frame j 3/7/13 CSE325 - Virtual Memory 23

Page-Based Address Translation Let N = {d 0, d 1, d n-1 } be the pages Let M = {b 0, b 1,, b m-1 } be page frames Virtual address, i, satisfies 0 i<g= 2 g+h Physical address, k = U2 h +V (0 V<G= 2 h ) U is page frame number V is the line number within the page (offset) B t :[0:G-1] <U, V> {Ω} Since every page is size c=2 h page number = U = i/c line number = V = i mod c 3/7/13 CSE325 - Virtual Memory 24

What happens if there is no free frame? Page replacement find some page in memory, but not really in use, swap it out algorithm performance want an algorithm which will result in minimum number of page faults Same page may be brought into memory several times 3/7/13 CSE325 - Virtual Memory 25

Performance of Demand Paging Page Fault Rate 0 p 1.0 if p = 0 no page faults if p = 1, every reference is a fault Page fault overhead is: Time to swap page out (not always needed) Time to swap page in Time to restart process Effective Access Time (EAT) EAT = (1 p) x memory access time + p x page fault overhead 3/7/13 CSE325 - Virtual Memory 26

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 µsec EAT = (1 p) x 1 + p(15000) = 1 + 14999p (in µsec) 3/7/13 CSE325 - Virtual Memory 27

Need For Page Replacement 3/7/13 CSE325 - Virtual Memory 28

Page Replacement Prevent over-allocation of memory by modifying page-fault service routine to include page replacement Use modify (dirty) bit to reduce overhead of page transfers only modified pages are written to disk Page replacement completes separation between logical memory and physical memory large virtual memory can be provided on a smaller physical memory 3/7/13 CSE325 - Virtual Memory 29

Basic Page Replacement 1. Find the location of the desired page on disk 2. Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame 3. Read the desired page into the (newly) free frame. Update the page and frame tables. 4. Continue the process from instruction that caused the page fault 30

Page Replacement 3/7/13 CSE325 - Virtual Memory 31