VM as a cache for disk

Similar documents
Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Computer Systems. Virtual Memory. Han, Hwansoo

Processes and Virtual Memory Concepts

Virtual Memory: Concepts

CSE 153 Design of Operating Systems

VIRTUAL MEMORY: CONCEPTS

Virtual Memory: Concepts

14 May 2012 Virtual Memory. Definition: A process is an instance of a running program

Carnegie Mellon. 16 th Lecture, Mar. 20, Instructors: Todd C. Mowry & Anthony Rowe

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

This lecture. Virtual Memory. Virtual memory (VM) CS Instructor: Sanjeev Se(a

Virtual Memory. CS61, Lecture 15. Prof. Stephen Chong October 20, 2011

Lecture 19: Virtual Memory: Concepts

Understanding the Design of Virtual Memory. Zhiqiang Lin

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Virtual Memory: Concepts

Virtual Memory II CSE 351 Spring

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Virtual Memory. Alan L. Cox Some slides adapted from CMU slides

Foundations of Computer Systems

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

Virtual Memory. Computer Systems Principles

University of Washington Virtual memory (VM)

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

Virtual Memory Oct. 29, 2002

Virtual Memory I. CSE 351 Spring Instructor: Ruth Anderson

Virtual Memory. Physical Addressing. Problem 2: Capacity. Problem 1: Memory Management 11/20/15

Virtual Memory Nov 9, 2009"

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

CSE 351. Virtual Memory

virtual memory. March 23, Levels in Memory Hierarchy. DRAM vs. SRAM as a Cache. Page 1. Motivation #1: DRAM a Cache for Disk

CISC 360. Virtual Memory Dec. 4, 2008

A Few Problems with Physical Addressing. Virtual Memory Process Abstraction, Part 2: Private Address Space

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Virtual Memory. Samira Khan Apr 27, 2017

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

CS 153 Design of Operating Systems

Virtual Memory: Systems

virtual memory Page 1 CSE 361S Disk Disk

@2010 Badri Computer Architecture Assembly II. Virtual Memory. Topics (Chapter 9) Motivations for VM Address translation

Memory Hierarchy. Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3. Instructor: Joanna Klukowska

Memory Hierarchy. Cache Memory Organization and Access. General Cache Concept. Example Memory Hierarchy Smaller, faster,

Virtual Memory I. CSE 351 Winter Instructor: Mark Wyse

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

Virtual Memory: From Address Translation to Demand Paging

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

CS 261 Fall Mike Lam, Professor. Virtual Memory

P6/Linux Memory System Nov 11, 2009"

CS 61C: Great Ideas in Computer Architecture. Lecture 23: Virtual Memory

CSE 560 Computer Systems Architecture

Read-only memory (ROM): programmed during production Programmable ROM (PROM): can be programmed once SRAM (Static RAM)

CS 61C: Great Ideas in Computer Architecture. Lecture 23: Virtual Memory. Bernhard Boser & Randy Katz

Memory System Case Studies Oct. 13, 2008

Virtual Memory: From Address Translation to Demand Paging

Pentium/Linux Memory System March 17, 2005

Virtual Memory. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Chapter 5 (Part II) Large and Fast: Exploiting Memory Hierarchy. Baback Izadi Division of Engineering Programs

Chapter 8. Virtual Memory

Virtual Memory. CS 3410 Computer System Organization & Programming

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

1. Creates the illusion of an address space much larger than the physical memory

Virtual Memory. Spring Instructors: Aykut and Erkut Erdem

CS162 Operating Systems and Systems Programming Lecture 10 Caches and TLBs"

Memory Management! Goals of this Lecture!

Virtual Memory: Systems

Chapter 5. Large and Fast: Exploiting Memory Hierarchy. Part II Virtual Memory

Memory Management! How the hardware and OS give application pgms:" The illusion of a large contiguous address space" Protection against each other"

Computer Science 146. Computer Architecture

Problem 9. VM address translation. (9 points): The following problem concerns the way virtual addresses are translated into physical addresses.

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013

Memory Management. Goals of this Lecture. Motivation for Memory Hierarchy

CSE 120 Principles of Operating Systems Spring 2017

The memory of a program. Paging and Virtual Memory. Swapping. Paging. Physical to logical address mapping. Memory management: Review

EN1640: Design of Computing Systems Topic 06: Memory System

Virtual memory Paging

CS 152 Computer Architecture and Engineering. Lecture 11 - Virtual Memory and Caches

CSE 120 Principles of Operating Systems

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

EN1640: Design of Computing Systems Topic 06: Memory System

COSC3330 Computer Architecture Lecture 20. Virtual Memory

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory. Reading. Sections 5.4, 5.5, 5.6, 5.8, 5.10 (2) Lecture notes from MKP and S. Yalamanchili

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

CS 152 Computer Architecture and Engineering. Lecture 8 - Address Translation

Chapter 10: Virtual Memory. Lesson 05: Translation Lookaside Buffers

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

CS 152 Computer Architecture and Engineering. Lecture 9 - Address Translation

LECTURE 4: LARGE AND FAST: EXPLOITING MEMORY HIERARCHY

Virtual Memory Virtual memory first used to relive programmers from the burden of managing overlays.

CS 153 Design of Operating Systems

Transcription:

Virtualization Virtual Memory Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Instructor: Joanna Klukowska Virtualization of a resource: presenting a user with a different view of that resource intercept all accesses to the resource possibly reinterpret/wrap/... such accesses and pass them along to the resource Examples: A wrapper function Virtual machine (just like the course machine) Access to hard drives (we/programs specify logical block number, not specific platter, cylinder, track number on the disk) Virtual memory (using virtual as opposed to physical addresses) Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran (NYU) 2 Virtual Address Space 4 3 Used in simple systems like embedded microcontrollers in devices like cars, elevators, and digital picture frames Applications need to know which ranges of addresses belong to them. 4

Linear address space: Ordered set of contiguous non-negative integer addresses: {0, 1, 2, 3 } 4100 Memory Management Unit 4 Virtual address space: Set of N = 2 n virtual addresses {0, 1, 2, 3,, N-1} Used in all modern servers, laptops, and smart-phones One of the great ideas in computer science (This is a big picture view; ignores caches, and other hardware elements that are design to reduce the time access to the main memory.) 5 Physical address space: Set of M = 2 m physical addresses {0, 1, 2, 3,, M-1} M N M - determined by amount of memory on the system, N - same for all processes 6 Uses main memory efficiently Use DRAM as a cache for parts of a virtual address space Simplifies memory management Each process gets the same uniform linear address space Isolates address spaces One process can t interfere with another s memory User program cannot access privileged kernel information and code VM as a cache for disk 7 8

Conceptually, virtual memory is an array of N contiguous bytes stored on disk. The contents of the array on disk are cached in physical memory (DRAM cache) These cache blocks are called pages (size is P = 2 p bytes) DRAM cache organization driven by the enormous miss penalty DRAM is about 10x slower than SRAM Disk is about 10,000x slower than DRAM Consequences Large page (block) size: typically 4 KB, sometimes 4 MB Fully associative Any VP can be placed in any PP Requires a large mapping function different from cache memories Highly sophisticated, expensive replacement algorithms Too complicated and open-ended to be implemented in hardware Write-back rather than write-through (defer writing to the disk as long as possible) 9 10 A page table is an array of page table entries (PTEs) that maps virtual pages to physical pages. Per-process kernel data structure in DRAM 11 12

Page miss causes page fault (an exception) 13 14 Page miss causes page fault (an exception) Page fault handler selects a victim to be evicted (here VP 4) Page miss causes page fault (an exception) Page fault handler selects a victim to be evicted (here VP 4) 15 16

Page miss causes page fault (an exception) Page fault handler selects a victim to be evicted (here VP 4) Offending instruction is restarted: page hit! 17 18 Virtual memory seems terribly inefficient, but it works because of locality. At any point in time, programs tend to access a set of active virtual pages called the working set Programs with better temporal locality will have smaller working sets If (working set size < main memory size) Good performance for one process after compulsory (cold) misses If ( SUM(working set sizes) > main memory size ) Thrashing: Performance meltdown where pages are swapped (copied) in and out continuously VM for memory management 19 20

Each process has its own virtual address space It can view memory as a simple linear array (each process/programmer has the virtual view of memory, not the real one) Mapping function scatters addresses through physical memory Simplifying memory allocation Each virtual page can be mapped to any physical page A virtual page can be stored in different physical pages at different times Sharing code and data among processes Map virtual pages to the same physical page (here: PP 6) 21 22 Linking Each program has similar virtual address space Code, data, and heap always start at the same addresses. %rsp Loading execve allocates virtual pages for.text and.data sections & creates PTEs marked as invalid The.text and.data sections are copied, page by page, on demand by the virtual memory system brk VM for memory protection malloc data bss 0x400000.init text.rodata 23 24

Address translation (not really) 25 26 Virtual Address Space V = {0, 1,, N 1} Physical Address Space P = {0, 1,, M 1} Address Translation MAP: V P U { } For virtual address a: MAP(a) = a if data at virtual address a is at physical address a in P MAP(a) = if data at virtual address a is not in physical memory Address translation For details of this see the textbook and slides that are posted at the end of this presentation. We will not cover the details of the address translation. 27 28

1) Processor sends virtual address to MMU 2-3) MMU fetches PTE from page table in memory 4) MMU sends physical address to cache/memory 5) Cache/memory sends data word to processor 29 30 1) Processor sends virtual address to MMU 2-3) MMU fetches PTE from page table in memory 4) Valid bit is zero, so MMU triggers page fault exception 5) Handler identifies victim (and, if dirty, pages it out to disk) 6) Handler pages in new page and updates PTE in memory 7) Handler returns to original process, restarting faulting instruction 31 32

Page table entries (PTEs) are cached in L1 like any other memory word PTEs may be evicted by other data references PTE hit still requires a small L1 delay Solution: Translation Lookaside Buffer (TLB) Small set-associative hardware cache in MMU Maps virtual page numbers to physical page numbers Contains complete page table entries for small number of pages VPN n-1 p+t p+t-1 TLB tag (TLBT) TLB index (TLBI) p p-1 VPO 0 33 34 35 36

Suppose: 4KB (2 12 ) page size, 48-bit address space, 8-byte PTE Problem: Would need a 512 GB page table! 2 48 * 2-12 * 2 3 = 2 39 bytes Common solution: Multi-level page table Example: 2-level page table Level 1 table: each PTE points to a page table (always memory resident) Level 2 table: each PTE points to a page (paged in and out like any other data) 37 38 n-1 VPN 1 VIRTUAL ADDRESS VPN 2... VPN k p-1 VPO 0 Level 1 page table Level 2 page table...... Level k page table PPN m-1 PPN p-1 PPO 0 PHYSICAL ADDRESS 39