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

Similar documents
Virtual Memory Oct. 29, 2002

virtual memory Page 1 CSE 361S Disk Disk

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

CISC 360. Virtual Memory Dec. 4, 2008

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

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

Virtual Memory Nov 9, 2009"

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

Computer Systems. Virtual Memory. Han, Hwansoo

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

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

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

CSE 153 Design of Operating Systems

CSE 560 Computer Systems Architecture

Processes and Virtual Memory Concepts

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

Virtual Memory: Concepts

Virtual Memory: Concepts

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

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

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Topic 18: Virtual Memory

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

VM as a cache for disk

P6/Linux Memory System Nov 11, 2009"

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Virtual Memory II CSE 351 Spring

18-447: Computer Architecture Lecture 16: Virtual Memory

University of Washington Virtual memory (VM)

Lecture 19: Virtual Memory: Concepts

Virtual Memory: Systems

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

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

CS 261 Fall Mike Lam, Professor. Virtual Memory

Virtual Memory: From Address Translation to Demand Paging

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

CSE 351. Virtual Memory

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

Pentium/Linux Memory System March 17, 2005

Virtual Memory: Concepts

Understanding the Design of Virtual Memory. Zhiqiang Lin

EE108B Lecture 13. Caches Wrap Up Processes, Interrupts, and Exceptions. Christos Kozyrakis Stanford University

Announcements. EE108B Lecture 13. Caches Wrap Up Processes, Interrupts, and Exceptions. Measuring Performance. Memory Performance

Memory System Case Studies Oct. 13, 2008

Virtual Memory. Samira Khan Apr 27, 2017

Virtual Memory. Computer Systems Principles

Foundations of Computer Systems

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

Topic 18 (updated): Virtual Memory

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

Computer Architecture. Lecture 8: Virtual Memory

Virtual Memory: From Address Translation to Demand Paging

Chapter 8. Virtual Memory

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

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

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

CSE 120 Principles of Operating Systems

John Wawrzynek & Nick Weaver

SE-292 High Performance Computing. Memory Hierarchy. R. Govindarajan

CS 153 Design of Operating Systems

Another View of the Memory Hierarchy. Lecture #25 Virtual Memory I Memory Hierarchy Requirements. Memory Hierarchy Requirements

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

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

CIS Operating Systems Memory Management Cache and Demand Paging. Professor Qiang Zeng Spring 2018

Virtual Memory I. CSE 351 Spring Instructor: Ruth Anderson

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

ECE4680 Computer Organization and Architecture. Virtual Memory

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

VIRTUAL MEMORY: CONCEPTS

Memory Management! Goals of this Lecture!

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

CSE 120 Principles of Operating Systems Spring 2017

CS 153 Design of Operating Systems

Computer Science 146. Computer Architecture

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

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

ECE468 Computer Organization and Architecture. Virtual Memory

This Unit: Main Memory. Virtual Memory. Virtual Memory. Other Uses of Virtual Memory

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

Translation Buffers (TLB s)

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

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

Handout 4 Memory Hierarchy

COSC3330 Computer Architecture Lecture 20. Virtual Memory

Virtual Memory. CS 3410 Computer System Organization & Programming

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

CS 153 Design of Operating Systems Winter 2016

Cache Performance and Memory Management: From Absolute Addresses to Demand Paging. Cache Performance

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2017

Computer Architecture. Memory Hierarchy. Lynn Choi Korea University

CS 61C: Great Ideas in Computer Architecture Virtual Memory. Instructors: John Wawrzynek & Vladimir Stojanovic

COEN-4730 Computer Architecture Lecture 3 Review of Caches and Virtual Memory

Virtual Memory. CS 351: Systems Programming Michael Saelee

Transcription:

Virtual Memory Today Motivations for VM Address translation Accelerating translation with TLBs Fabián Chris E. Bustamante, Riesbeck, Fall Spring 2007 2007

A system with physical memory only Addresses generated by the CPU correspond directly to bytes in physical memory Memory Physical Addresses 0: 1: CPU E.g. most Cray machines, early PCs, nearly all embedded systems, etc. N-1: 2

A system with virtual memory Modern processors use virtual addresses Hardware converts virtual addresses to physical addresses via OS-managed page table Memory Virtual Addresses Page Table 0: 1: Physical Addresses 0: 1: CPU E.g. workstations, servers, modern PCs, etc. P-1: N-1: Disk 3

Motivations for virtual memory Use physical DRAM as a cache for the disk Address space of a process can exceed physical memory size Sum of address spaces of multiple processes can exceed physical memory Simplify memory management Multiple processes resident in main memory. Each process with its own address space Only active code and data is actually in memory Allocate more memory to process as needed. Provide protection One process can t interfere with another. because they operate in different address spaces. User process cannot access privileged information different sections of address spaces have different permissions. 4

Motivation #1: DRAM a cache for disk Full address space is quite large: 32-bit addresses: ~4,000,000,000 (4 billion) bytes 64-bit addresses: ~16,000,000,000,000,000,000 (16 quintillion) bytes Disk storage is ~300X cheaper than DRAM storage 80 GB of DRAM: ~ $33,000 80 GB of disk: ~ $110 To access large amounts of data in a cost-effective manner, the bulk of the data must be stored on disk 4 MB: ~$500 SRAM 1GB: ~$200 DRAM 80 GB: ~$110 Disk 5

Levels in memory hierarchy cache virtual memory CPU regs 8 B C a c h e 32 B Memory 4 KB disk size: speed: $/Mbyte: line size: Register Cache Memory Disk Memory 32 B 1 ns 8 B 32KB-4MB 2 ns $125/MB 32 B 1024 MB 30 ns $0.20/MB 4 KB 100 GB 8 ms $0.001/MB larger, slower, cheaper 6

DRAM vs. SRAM as a cache DRAM vs. disk is more extreme than SRAM vs. DRAM Access latencies: DRAM ~10X slower than SRAM Disk ~100,000X slower than DRAM Importance of exploiting spatial locality: First byte is ~100,000X slower than successive bytes on disk vs. ~4X improvement for page-mode vs. regular accesses to DRAM Bottom line: Design decisions made for DRAM caches driven by enormous cost of misses 7

Impact of properties on design If DRAM was to be organized similar to an SRAM cache, how would we set the following design parameters? Line size? Large, since disk better at transferring large blocks Associativity? High, to minimize miss rate Write through or write back? Write back, since can t afford to perform small writes to disk What would the impact of these choices be on: Miss rate: Extremely low. << 1% Hit time: Must match cache/dram performance Miss latency: Very high. ~20ms Tag storage overhead: Low, relative to block size 8

Locating an object in a Cache SRAM Cache Tag stored with cache line Maps from cache block to memory blocks From cached to uncached form Save a few bits by only storing tag No tag for block not in cache Hardware retrieves information Can quickly match against multiple tags Cache Tag Data Object Name X = X? 0: 1: N-1: D 243 X 17 J 105 9

(. cont ) Locating an object in Cache DRAM Cache Each allocated page of virtual memory has entry in page table Mapping from virtual pages to physical pages From uncached form to cached form Page table entry even if page not in memory Specifies disk address Only way to indicate where to find page OS retrieves information Page Table Cache Location Data Object Name D: 0 0: 243 X J: On Disk X: 1 1: N-1: 17 105 10

( misses Page faults (like cache What if an object is on disk rather than in memory? Page table entry indicates virtual address not in memory OS exception handler invoked to move data from disk into memory current process suspends, others can resume OS has full control over placement, etc. Before fault Memory After fault Memory CPU Virtual Addresses Page Table Physical Addresses CPU Virtual Addresses Page Table Physical Addresses Disk Disk 11

Servicing a page fault Processor signals controller Read block of length P starting at disk address X and store starting at memory address Y Read occurs ( DMA ) Direct Memory Access Under control of I/O controller I / O controller signals completion Interrupt processor OS resumes suspended process Processor Reg Cache Memory (1) Initiate Block Read Memory-I/O bus (2) DMA Transfer (3) Read Done I/O controller disk Disk disk Disk 12

Motivation #2: Memory management Multiple processes can reside in physical memory. How do we resolve address conflicts? what if two processes access something at the same address? %esp kernel virtual memory stack memory invisible to user code Linux/x86 process Memory mapped region forshared libraries memory image 0 ( malloc runtime heap (via ( bss.) uninitialized data ( data.) initialized data ( text.) program text forbidden the brk ptr 13

Solution: Separate virtual addr. spaces Virtual and physical address spaces divided into equal-sized blocks ( physical blocks are called pages (both virtual and Each process has its own virtual address space operating system controls how virtual pages as assigned to physical memory Virtual Address Space for Process 1: 0 N-1 VP 1 VP 2... Address Translation 0 PP 2 Physical Address Space ( DRAM ) Virtual Address Space for Process 2: 0 N-1 VP 1 VP 2... PP 7 PP 10 M-1 (e.g., read/only ( code library 14

Motivation #3: Protection Page table entry contains access rights information. Hardware enforces this protection. Trap into OS if violation occurs. Process i: Page Tables Read? Write? Physical Addr VP 0: Yes No PP 9 VP 1: Yes Yes PP 4 0: 1: Memory VP 2: No No XXXXXXX Process j: VP 0: VP 1: VP 2: Read? Write? Yes Yes No Yes No No Physical Addr PP 6 PP 9 XXXXXXX N-1: 15

VM address translation Virtual Address Space V = {0, 1,, N 1} Physical Address Space P = {0, 1,, M 1} M < N 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 Either invalid or stored on disk 16

VM address translation: Miss Processor a Hardware Addr Trans Mechanism a' Main Memory virtual address part of the on-chip memory mgmt unit (MMU) physical address 17

VM address translation: Miss page fault Processor fault handler a Hardware Addr Trans Mechanism a' Main Memory Secondary memory virtual address part of the on-chip memory mgmt unit (MMU) physical address OS performs this transfer ( miss (only if 18

VM address translation Parameters P = 2 p = page size (bytes). N = 2 n = Virtual address limit M = 2 m = Physical address limit n 1 p p 1 0 virtual page number page offset virtual address address translation m 1 p p 1 0 physical page number page offset physical address Page offset bits donʼt change as a result of translation 19

Page tables Virtual Page Number Valid 1 1 0 1 1 1 0 1 0 1 Memory resident page table (physical page ( address or disk Physical Memory Disk Storage (swap file or ( file regular file system 20

Address translation via page table page table base register VPN acts as table index virtual address n 1 p p 1 0 ( VPN ) virtual page number valid access page offset VPO ( PPN ) physical page number if valid=0 then page not in memory m 1 ( PPN ) physical page number p p 1 page offset PPO 0 physical address 21

Page table operation Translation Separate (set of) page table(s) per process ( entry VPN forms index into page table (points to a page table 22

Page table operation Computing physical address Page Table Entry (PTE) provides info about page if (valid bit = 1) then the page is in memory. Use physical page number (PPN) to construct address if (valid bit = 0) then the page is on disk - page fault 23

Page table operation Checking protection Access rights field indicate allowable access e.g., read-only, read-write, execute-only typically support multiple protection modes Protection violation fault if user doesn t have necessary permission 24

Checkpoint

Multi-level page tables Given: 4KB (2 12 ) page size 32-bit address space 4-byte PTE Problem: Would need a 4 MB page table! 2 20 *4 bytes Common solution multi-level page tables ( P6 ) e.g., 2-level table Level 1 table: 1024 entries, each of which points to a Level 2 page table. Level 2 table: 1024 entries, each of which points to a page Level 1 Table Level 2 Tables... 25

Integrating VM and cache Most caches accessed by physical addresses Allows multiple processes to have blocks in cache at a time Allows multiple processes to share pages Cache doesn t need to be concerned with protection issues Access rights checked as part of address translation Perform address translation before cache lookup ( PTE But this could involve a memory access itself (of the Of course, page table entries can also become cached. CPU VA PA miss Translation Cache data hit Main Memory 26

Speeding up translation with a TLB ( TLB ) Translation Lookaside Buffer Small hardware cache with high associativity in MMU Maps virtual page numbers to physical page numbers Contains complete page table entries for small number of pages CPU hit VA PA miss TLB Cache Lookup Main Memory miss hit Translation data 27

Address translation with a TLB n 1 p p 1 0 virtual page number page offset virtual address valid tag... physical page number TLB TLB hit = physical address tag valid tag data index byte offset Cache cache hit = data 28

Taken stock main themes Programmer s view Large flat address space Can allocate large blocks of contiguous addresses Processor owns machine Has private address space Unaffected by behavior of other processes System view Virtual address space created by mapping to set of pages Need not be contiguous Allocated dynamically Enforce protection during address translation OS manages many processes simultaneously Continually switching among processes Especially when one must wait for resource E.g., disk I/O to handle page fault 29

Simple memory system Memory is byte addressable Access are to 1-byte words 14-bit virtual addresses, 12-bit physical address ( 6 (2 bytes Page size = 64 13 12 11 10 9 8 7 6 5 4 3 2 1 0 VPN ( Number (Virtual Page VPO ( Offset (Virtual Page 11 10 9 8 7 6 5 4 3 2 1 0 PPN ( Number (Physical Page PPO ( Offset (Physical Page 30

Simple memory system page table Only show first 16 entries VPN PPN Valid VPN PPN Valid 00 28 1 08 13 1 01 0 09 17 1 02 33 1 0A 09 1 03 02 1 0B 0 04 0 0C 0 05 16 1 0D 2D 1 06 0 0E 11 1 07 0 0F 0D 1 31

Simple memory system TLB TLB 16 entries 4-way associative TLBT TLBI 13 12 11 10 9 8 7 6 5 4 3 2 1 0 VPN VPO Set Tag PPN Valid Tag PPN Valid Tag PPN Valid Tag PPN Valid 0 03 0 09 0D 1 00 0 07 02 1 1 03 2D 1 02 0 04 0 0A 0 2 02 0 08 0 06 0 03 0 3 07 0 03 0D 1 0A 34 1 02 0 32

Set Tag PPN Valid Tag PPN Valid Tag PPN Valid Tag PPN Valid 0 03 0 09 0D 1 00 0 07 02 1 1 03 2D 1 02 0 04 0 0A 0 2 02 0 08 0 06 0 03 0 3 07 0 03 0D 1 0A 34 1 02 0 Idx Tag Valid B0 B1 B2 B3 Idx Tag Valid B0 B1 B2 B3 0 19 1 99 11 23 11 8 24 1 3A 00 51 89 1 15 0 9 2D 0 2 1B 1 00 02 04 08 A 2D 1 93 15 DA 3B 3 36 0 B 0B 0 4 32 1 43 6D 8F 09 C 12 0 5 0D 1 36 72 F0 1D D 16 1 04 96 34 15 6 31 0 E 13 1 83 77 1B D3 7 16 1 11 C2 DF 03 F 14 0 34

Simple memory system cache Cache 16 lines 4-byte line size Direct mapped CT CI CO 11 10 9 8 7 6 5 4 3 2 1 0 PPN PPO Idx Tag Valid B0 B1 B2 B3 Idx Tag Valid B0 B1 B2 B3 0 19 1 99 11 23 11 8 24 1 3A 00 51 89 1 15 0 9 2D 0 2 1B 1 00 02 04 08 A 2D 1 93 15 DA 3B 3 36 0 B 0B 0 4 32 1 43 6D 8F 09 C 12 0 5 0D 1 36 72 F0 1D D 16 1 04 96 34 15 6 31 0 E 13 1 83 77 1B D3 7 16 1 11 C2 DF 03 F 14 0 33

Checkpoint

Harsh reality Memory matters Memory is not unbounded It must be allocated and managed Many applications are memory dominated Especially those based on complex, graph algorithms Memory referencing bugs especially pernicious Effects are distant in both time and space Memory performance is not uniform Cache and virtual memory effects can greatly affect program performance Adapting program to characteristics of memory system can lead to major speed improvements