Topic 18 (updated): Virtual Memory

Similar documents
Topic 18: Virtual Memory

virtual memory Page 1 CSE 361S Disk Disk

Virtual Memory Oct. 29, 2002

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

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

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

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

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

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Virtual Memory. Virtual Memory

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

CS162 Operating Systems and Systems Programming Lecture 14. Caching and Demand Paging

Virtual Memory: From Address Translation to Demand Paging

CSE 560 Computer Systems Architecture

VIRTUAL MEMORY II. Jo, Heeseung

CS162 Operating Systems and Systems Programming Lecture 14. Caching (Finished), Demand Paging

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

Virtual Memory Nov 9, 2009"

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

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

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

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

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

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

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

Memory Hierarchy. Mehran Rezaei

Modern Computer Architecture

Virtual Memory: From Address Translation to Demand Paging

CS162 - Operating Systems and Systems Programming. Address Translation => Paging"

18-447: Computer Architecture Lecture 16: Virtual Memory

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

Chapter Seven. Memories: Review. Exploiting Memory Hierarchy CACHE MEMORY AND VIRTUAL MEMORY

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

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

UC Berkeley CS61C : Machine Structures

ECE232: Hardware Organization and Design

Background. Memory Hierarchies. Register File. Background. Forecast Memory (B5) Motivation for memory hierarchy Cache ECC Virtual memory.

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

Computer Architecture. Lecture 8: Virtual Memory

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

Address Translation. Tore Larsen Material developed by: Kai Li, Princeton University

Translation Buffers (TLB s)


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

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

Fast access ===> use map to find object. HW == SW ===> map is in HW or SW or combo. Extend range ===> longer, hierarchical names

COS 318: Operating Systems. Virtual Memory and Address Translation

Lecture 13: Address Translation

The Virtual Memory Abstraction. Memory Management. Address spaces: Physical and Virtual. Address Translation

Virtual Memory. Samira Khan Apr 27, 2017

Virtual Memory. CS 3410 Computer System Organization & Programming

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

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

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

Modern Virtual Memory Systems. Modern Virtual Memory Systems

ECE468 Computer Organization and Architecture. Virtual Memory

Virtual Memory. Motivation:

ECE4680 Computer Organization and Architecture. Virtual Memory

TDT Coarse-Grained Multithreading. Review on ILP. Multi-threaded execution. Contents. Fine-Grained Multithreading

Page 1. CS162 Operating Systems and Systems Programming Lecture 14. Caching and Demand Paging

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

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

Motivation, Concept, Paging January Winter Term 2008/09 Gerd Liefländer Universität Karlsruhe (TH), System Architecture Group

CS162 Operating Systems and Systems Programming Lecture 14. Caching and Demand Paging

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

Main Memory (Fig. 7.13) Main Memory

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

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

Memory Hierarchy Review

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

EECS 470. Lecture 16 Virtual Memory. Fall 2018 Jon Beaumont

Virtual Memory Review. Page faults. Paging system summary (so far)

Lecture 11. Virtual Memory Review: Memory Hierarchy

Computer Science 146. Computer Architecture

Virtual Memory - Objectives

Cache Performance (H&P 5.3; 5.5; 5.6)

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

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

Virtual Memory. Study Chapters something I understand. Finally! A lecture on PAGE FAULTS! doing NAND gates. I wish we were still

John Wawrzynek & Nick Weaver

Operating Systems. Operating Systems Sina Meraji U of T

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

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

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

Fast access ===> use map to find object. HW == SW ===> map is in HW or SW or combo. Extend range ===> longer, hierarchical names

Sarah L. Harris and David Money Harris. Digital Design and Computer Architecture: ARM Edition Chapter 8 <1>

Virtual to physical address translation

EN1640: Design of Computing Systems Topic 06: Memory System

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

HY225 Lecture 12: DRAM and Virtual Memory

Computer Science 432/563 Operating Systems The College of Saint Rose Spring Topic Notes: Memory Hierarchy

CS 152 Computer Architecture and Engineering. Lecture 9 - Virtual Memory

Handout 4 Memory Hierarchy

Transcription:

Topic 18 (updated): Virtual Memory COS / ELE 375 Computer Architecture and Organization Princeton University Fall 2015 Prof. David August 1

Virtual Memory Any time you see virtual, think using a level of indirection Virtual memory: level of indirection to physical memory Program uses virtual memory addresses Virtual address is converted to a physical address Physical address indicates physical location of data Physical location can be memory or disk! 0x800 Disk: Mem: 0x803C4 0x3C00 Virtual address Physical address 2

3 Virtual Memory

Virtual Memory 1 4

Virtual Memory: Take 1 Main memory may not be large enough for a task Programmers turn to overlays and disk Many programs would have to do this Programmers should have to worry about main memory size across machines Use virtual memory to make memory look bigger for all programs 5

A System with Only Physical Memory Examples: Most Cray machines, early PCs, nearly all current embedded systems, etc. Memory Store 0x10 0: 1: CPU Load 0xf0 N-1: CPU s load or store addresses used directly to access memory. 6

A System with Virtual Memory Examples: modern workstations, servers, PCs, etc. Memory Virtual Addresses Store 0x10 Page Table 0: 1: Physical Addresses 0: 1: CPU Load 0xf0 P-1: N-1: Disk Address Translation: the hardware converts virtual addresses into physical addresses via an OS-managed lookup table (page table) 7

Page Faults (Similar to Cache Misses ) What if an object is on disk rather than in memory? 1. Page table indicates that the virtual address is not in memory 2. OS trap handler is invoked, moving data from disk into memory Current process suspends, others can resume OS has full control over placement, etc. Memory Virtual Addresses Page Table 0: 1: Physical Addresses 0: 1: CPU Load 0x05 Store 0xf8 P-1: N-1: Working Set Disk 8

Virtual Memory 2 9

Virtual Memory: Take 2 Concurrently executing programs will interfere in memory At some point, programs assume addresses These addresses may conflict if we don t manage them. Which programs will execute concurrently? Don t know Manage dynamically Programs can maliciously interfere with each other! They need protection from one another Use virtual memory to avoid/manage conflict between programs 10

Separate Virtual Address Spaces Each process has its own virtual address space OS controls how virtual is assigned to physical memory Virtual Addresses Physical Addresses Process 1: 0 VP 1 VP 2 Address Translation 0 PP 2 N-1 Process 2: 0 VP 1 VP 2 PP 7 PP 10 (Read-only library code) N-1 M-1 11

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

Virtual Memory 3 13

Virtual Memory: Take 3 Programs and data exist on disk Registers, caches, and memory just make using the data on disk faster Locality at different granularities Use virtual memory to improve performance, hide physical location from program 14

Levels in Memory Hierarchy cache virtual memory CPU regs C 8 B a 32 B 8 KB Memory c h e disk size: speed: $/Mbyte: block size: Register Cache Memory Disk Memory 200 B 3 ns 8 B larger, slower, cheaper 32 KB / 4MB 128 MB 6 ns 60 ns $100/MB $1.50/MB 32 B 8 KB 20 GB 8 ms $0.05/MB 15

16

Virtual Memory Just like caches, but origins are different Cache - performance goals Virtual Memory - programmability/multiprogram goals Blocks are called Pages A virtual address consists of A virtual page number A page offset field (low order bits of the address) 31 Virtual page number 11 Page offset 0 17

Page Tables Each process gets its own page table, why?

Page Tables Can t Execute From Here

Page Faults Blocks are called Pages Page Tables translate virtual to physical page numbers Misses are call Page faults (handled as an exception) Retrieve data from disk Huge miss penalty, pages are fairly large (how big?) Reducing page faults is important Can handle the faults in software instead of hardware Using write-through is too expensive, use writeback 31 Virtual page number 11 Page offset 0 20

Servicing a Page Fault 1. Make space in memory by writing physical page to disk Page Frames Replacement policy? 2. Load page Loading pages could waste processor time, use DMA DMA allows processor to do something else 3. OS updates the process's page table Desired data is in memory for process to resume 21

Servicing a Page Fault 1. Processor Signals Controller Read block of length P starting at disk address X and store starting at memory address Y 2. DMA Read Occurs 3. I / O Controller Signals Completion Interrupts processor Can resume suspended process Processor Reg Cache Memory Memory-I/O bus (2) DMA Transfer (1) Initiate Block Read (3) Read Done I/O controller disk Disk disk Dis k 22

Where Is the Page Table?

24 Making Translation Faster: The TLB Translation Look-Aside Buffer

TLB Design Issues Accessed frequently: speed is important TLB Miss Involves (not to be confused with page fault): 1. Stall pipeline 2. Invoke Operating System (what about OS pages?) 3. Read Page Table 4. Write entry in TLB (evicting old entry?) 5. Return to user code 6. Restart at reference MIPS. Another HW Option?

TLB Design Issues Clearly, we want to minimize TLB misses: Can be fully-associative, set-associative, or direct mapped Often fully associative, can be set associative Sized to maximize hits, but make timing Usually not more than 128, 256 entries (associtivity) 26

27

Loading Your Program: A Neat Trick 1. Ask operating system to create a new process 2. Construct a page table for this process 3. Mark all page table entries as invalid with a pointer to the disk image of the program 4. Run the program and get an immediate page fault on the first instruction. 28

Process Interactions Virtual Addresses are per Process Context Switch: Save state : regs, PC, page table (PTBR) TLB? Could Flush TLB Every time perform context switch Refill for new process by series of TLB misses ~100 clock cycles each Could Include Process ID Tag with TLB Entry Identifies which address space being accessed OK even when sharing physical pages 29

30

A System with Physical Memory Examples: Most Cray machines, early PCs, nearly all current embedded systems, etc. Memory Store 0x10 0: 1: CPU Load 0xf0 N-1: CPU s load or store addresses used directly to access memory. 31

A System with Virtual Memory Memory Virtual Addresses Page Table 0: 1: Physical Addresses 0: 1: CPU Load 0x05 Store 0xf8 P-1: N-1: Working Set Disk 32

Page Tables Each process gets its own page table, why?

Separate Virtual Address Spaces Each process has its own virtual address space OS controls how virtual is assigned to physical memory Virtual Addresses Physical Addresses Process 1: 0 N-1 VP 1 VP 2 Address Translation 0 PP 2 Page Frames Process 2: 0 VP 1 VP 2 PP 7 PP 10 (Read-only library code) N-1 M-1 34

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

Virtual Memory Lingo Blocks are called Pages 31 Virtual page number 11 Page offset 0 Misses are called Page faults (handled as an exception) Retrieve data from disk Huge miss penalty, pages are fairly large (4-8K) Reducing page faults is important Can handle the faults in software instead of hardware Using write-through is too expensive, use writeback 36

37 Making Translation Faster: The TLB Translation Look-Aside Buffer

Virtual Memory Summary Virtual memory provides Protection and sharing Illusion of large main memory Speed/Caching (when viewed from disk perspective) Virtual Memory requires twice as many memory accesses, so cache page table entries in the TLB. Three things can go wrong on a memory access TLB miss Page fault Cache miss Caches and virtual memory? 38

39

Virtually Memory and Caches: 3 Options 1. Physically Addressed Cache CPU VA Trans PA Cache PA MEM Translate before accessing cache Cache is: Physically Indexed Physically Tagged Allows multiple processes to have blocks in cache at same time, share pages, etc. Access rights checked as part of translation Speed? 40

Virtually Memory and Caches: 3 Options 2. Virtually Addressed Cache Translate after accessing cache CPU VA Cache VA Trans PA MEM Cache is: Virtually Indexed Virtually Tagged Translate Only on Miss! The synonym/alias problem How would you make this work? 41

Virtually Memory and Caches: 3 Options 3. Virtually Indexed, Physically Tagged VA CPU $ Trans PA L2 $ Translate during cache access Cache is: Physically/Virtually Indexed Physically Tagged Excellent performance MEM Requires cache index to remain invariant across translation. How? 42

Virtually Indexed, Physically Tagged Example Note Size Here 43

Issues With Overlapped TLB Access Limits cache parameters: small caches, large page sizes, or high n-way set-associative caches Example: Suppose everything the same except that the cache is increased to 8 K bytes instead of 4 K 11 2 cache index 20 12 Virtual page # Displ. 00 This bit is changed by VA translation, but is needed for cache lookup Solutions: Go to 8K byte page sizes; Go to 2-way set-associative cache; or SW guarantee VA[13]=PA[13] 10 4 bytes 4 bytes 1K 2-way set-associative cache 44

45

Some Page Table Math # of page table entries on 64-bit machine with 4K pages: 2 64 / 2 12 = (only) 2 52 entries Size of page table: 2 52 * 8 bytes per table entry = 2 55 bytes (only 32 petabytes) kilo- 2 10, mega- 2 20, giga- 2 30, tera- 2 40, peta- 2 50, exa- 2 60, zetta- 2 70, yotta- 2 80 46

Some Page Table Math Size of page table: 2 52 * 8 bytes per table entry = 2 55 bytes (only 32 petabytes) Oh, by the way, that s per process 47

Solutions 1. Limit Page Table Size Keep a limit Check limit before going to page If more entries needed (process needs more memory): 1. Up the limit 2. Add the entries Good way to do this: Double page table size at each step: Limit is: 0 01 1 (number 0 à 2 n-1 ) Also, can grow bi-directionally (stack/heap) 48

Solutions 2. Inverted Page Table!! These things are UGLY!! Each Physical Frame has an entry. Inverted page table size: Physical memory size = 8 Gigabytes = 2 33 bytes Page frame size = 4K = 2 12 bytes 2 33 / 2 12 = 2 21 entries 2 21 entries * 8 bytes per entry (incl. PID) = 2 24 bytes 16MB, not too bad (not per process!) 49

Solutions 3. Multilevel Page Tables Key Idea: Take advantage of sparse use of virtual memory Create a hierarchy of pages: Create a red page table to describe very large pages (coarse cut of virtual address space) Not Used Create a black page table for each red page table entry used (finer cut of superpage) 50

51 Solution 3: Multi-Level Page Tables Example

Solutions 4. Page The Page Table Compatible with other methods Tricky to get right Need to have page portion that refers to rest of page table always in memory 52

53

Segmentation Real Stuff (x86 IA32) Segments: Variable-sized pages Virtual address are segment number + offset Generally 2 quantities Segment register Offset is address Bounds checking Nice in some ways: Program fits in one segment - set ReadOnly/Executable Data in another - set ReadWrite/NonExecutable 54

55 x86: Segmentation (From: IA-32 Intel Architecture Software Developers Manual)

x86: Segment Registers (From: IA-32 Intel Architecture Software Developers Manual) Pages and Segments Can Co-exist! 56

57

Relating to the MIPS Pipeline MIPS R3000 Pipeline Inst Fetch Dcd/ Reg ALU / E.A. Memory Write Reg TLB I-Cache RF Operation WB E.A. TLB D-Cache 58

Summary Real/Virtual Tag/Index Cache Multi Level Page Tables Segments Pipeline Interaction 59