Section 9: Virtual Memory (VM)

Slides:



Advertisements
Similar presentations
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Advertisements

Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
Virtual Memory October 25, 2006 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs class16.ppt.
Carnegie Mellon 1 Virtual Memory: Concepts : Introduction to Computer Systems 15 th Lecture, Oct. 14, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
Today Virtual memory (VM) Overview and motivation
Virtual Memory October 29, 2007 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs class16.ppt.
Virtual Memory Topics Virtual Memory Access Page Table, TLB Programming for locality Memory Mountain Revisited.
©UCB CS 161 Ch 7: Memory Hierarchy LECTURE 24 Instructor: L.N. Bhuyan
Carnegie Mellon 1 Virtual Memory: Concepts / : Introduction to Computer Systems 16 th Lecture, Oct. 21, 2014 Instructors: Greg Ganger, Greg.
Virtual Memory: Concepts
Carnegie Mellon 1 Saint Louis University Virtual Memory CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant.
Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work.
1 Seoul National University Virtual Memory: Systems.
1 Virtual Memory: Concepts Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaron.
Carnegie Mellon 1 Virtual Memory: Concepts Instructor: Rabi Mahapatra (TAMU) Slides: Randy Bryant and Dave O’Hallaron (CMU)
Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
University of Washington Today Lab 4 due Wednesday! HW 4 out today! What a process again?
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
Virtual Memory.  Next in memory hierarchy  Motivations:  to remove programming burdens of a small, limited amount of main memory  to allow efficient.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Concepts Slides adapted from Bryant.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Concepts CENG331 - Computer Organization.
Virtual Memory Topics Motivations for VM Address translation Accelerating translation with TLBs CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Virtual Memory Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs.
CSE 153 Design of Operating Systems Winter 2015 Lecture 11: Paging/Virtual Memory Some slides modified from originals by Dave O’hallaron.
1 Virtual Memory (I). 2 Outline Physical and Virtual Addressing Address Spaces VM as a Tool for Caching VM as a Tool for Memory Management VM as a Tool.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
University of Washington Indirection in Virtual Memory 1 Each process gets its own private virtual address space Solves the previous problems Physical.
Alan L. Cox Virtual Memory Alan L. Cox Some slides adapted from CMU slides.
Computer Architecture Lecture 12: Virtual Memory I
Virtual Memory Chapter 8.
CS161 – Design and Architecture of Computer
Virtual Memory Samira Khan Apr 27, 2017.
Virtual Memory Chapter 7.4.
Memory COMPUTER ARCHITECTURE
Virtual Memory Samira Khan Apr 25, 2017.
CS161 – Design and Architecture of Computer
From Address Translation to Demand Paging
Section 9: Virtual Memory (VM)
From Address Translation to Demand Paging
Today How was the midterm review? Lab4 due today.
Virtual Memory: Concepts CENG331 - Computer Organization
CS 704 Advanced Computer Architecture
Virtual Memory.
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory I CSE 351 Autumn 2017
CSE 153 Design of Operating Systems Winter 2018
CS 105 “Tour of the Black Holes of Computing!”
CSE 153 Design of Operating Systems Winter 2018
Virtual Memory: Concepts /18-213/14-513/15-513: Introduction to Computer Systems 17th Lecture, October 23, 2018.
Virtual Memory 3 Hakim Weatherspoon CS 3410, Spring 2011
CS 105 “Tour of the Black Holes of Computing!”
ECE Dept., University of Toronto
Instructors: Majd Sakr and Khaled Harras
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Virtual Memory Nov 27, 2007 Slide Source:
Virtual Memory II CSE 351 Winter 2018
CSC3050 – Computer Architecture
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory I CSE 351 Winter 2019
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Instructor: Phil Gibbons
Presentation transcript:

Section 9: Virtual Memory (VM) Overview and motivation Indirection VM as a tool for caching Memory management/protection and address translation Virtual memory example Virtual Memory as Cache

VM and the Memory Hierarchy Think of virtual memory as an array of N = 2n contiguous bytes stored on a disk Then physical main memory (DRAM) is used as a cache for the virtual memory array The cache blocks are called pages (size is P = 2p bytes) PP 2m-p-1 Physical memory Empty Uncached VP 0 VP 1 VP 2n-p-1 Virtual memory Unallocated Cached PP 0 PP 1 N-1 M-1 Virtual pages (VPs) stored on disk Physical pages (PPs) cached in DRAM Virtual Memory as Cache

Memory Hierarchy: Core 2 Duo Not drawn to scale L1/L2 cache: 64 B blocks ~4 MB ~4 GB ~500 GB L1 I-cache D-cache L2 unified cache Main Memory Disk 32 KB CPU Reg Throughput: 16 B/cycle 8 B/cycle 2 B/cycle 1 B/30 cycles Latency: 3 cycles 14 cycles 100 cycles millions Miss penalty (latency): 33x Miss penalty (latency): 10,000x Virtual Memory as Cache

DRAM Cache Organization DRAM cache organization driven by the enormous miss penalty DRAM is about 10x slower than SRAM Disk is about 10,000x slower than DRAM (for first byte; faster for next byte) Consequences? Block size? Associativity? Write-through or write-back? Virtual Memory as Cache

DRAM Cache Organization DRAM cache organization driven by the enormous miss penalty DRAM is about 10x slower than SRAM Disk is about 10,000x slower than DRAM (for first byte; faster for next byte) Consequences Large page (block) size: typically 4-8 KB, sometimes 4 MB Fully associative Any VP can be placed in any PP Requires a “large” mapping function – different from CPU caches Highly sophisticated, expensive replacement algorithms Too complicated and open-ended to be implemented in hardware Write-back rather than write-through Virtual Memory as Cache

Indexing into the “DRAM Cache” Main memory 0: CPU Chip 1: 2: Virtual address (VA) Physical address (PA) 3: CPU MMU 4: 5: 6: 7: 8: ... M-1: Data word How do we perform the VA -> PA translation? Virtual Memory as Cache

Address Translation: Page Tables A page table (PT) is an array of page table entries (PTEs) that maps virtual pages to physical pages. Physical memory (DRAM) Physical page number or disk address Valid VP 1 PP 0 VP 2 PTE 0 null VP 7 1 VP 4 PP 3 1 1 Virtual memory (disk) null PTE 7 1 VP 1 Memory resident page table (DRAM) VP 2 VP 3 VP 4 How many page tables are in the system? One per process VP 6 Virtual Memory as Cache VP 7

Address Translation With a Page Table Virtual address (VA) Page table base register (PTBR) Virtual page number (VPN) Virtual page offset (VPO) Page table Page table address for process Valid Physical page number (PPN) PTBR is another name for control register 3 (CR3) in x86: http://en.wikipedia.org/wiki/Control_register#CR3 Valid bit = 0: page not in memory (page fault) In most cases, the hardware (the MMU) can perform this translation on its own, without software assistance Physical page number (PPN) Physical page offset (PPO) Physical address (PA) Virtual Memory as Cache

Virtual Memory as Cache Page Hit Page hit: reference to VM byte that is in physical memory Physical memory (DRAM) Physical page number or disk address Virtual address Valid VP 1 PP 0 VP 2 PTE 0 null VP 7 1 VP 4 PP 3 1 1 Virtual memory (disk) null PTE 7 1 VP 1 Memory resident page table (DRAM) VP 2 VP 3 VP 4 VP 6 VP 7 Virtual Memory as Cache

Virtual Memory as Cache Page Fault Page fault: reference to VM byte that is NOT in physical memory Physical memory (DRAM) Physical page number or disk address Virtual address VP 1 PP 0 Valid VP 2 PTE 0 null VP 7 1 VP 4 PP 3 1 1 Virtual memory (disk) null PTE 7 1 VP 1 Memory resident page table (DRAM) VP 2 VP 3 VP 4 What happens when a page fault occurs? VP 6 VP 7 Virtual Memory as Cache

Fault Example: Page Fault int a[1000]; main () { a[500] = 13; } User writes to memory location That portion (page) of user’s memory is currently on disk Page handler must load page into physical memory Returns to faulting instruction: mov is executed again! Successful on second try 80483b7: c7 05 10 9d 04 08 0d movl $0xd,0x8049d10 User Process OS exception: page fault movl Create page and load into memory returns Virtual Memory as Cache

Virtual Memory as Cache Handling Page Fault Page miss causes page fault (an exception) Physical memory (DRAM) Physical page number or disk address Virtual address Valid VP 1 PP 0 VP 2 PTE 0 null VP 7 1 VP 4 PP 3 1 1 Virtual memory (disk) null PTE 7 1 VP 1 Memory resident page table (DRAM) VP 2 VP 3 VP 4 VP 6 VP 7 Virtual Memory as Cache

Virtual Memory as Cache Handling Page Fault Page miss causes page fault (an exception) Page fault handler selects a victim to be evicted (here VP 4) Physical memory (DRAM) Physical page number or disk address Virtual address Valid VP 1 PP 0 VP 2 PTE 0 null VP 7 1 VP 4 PP 3 1 1 Virtual memory (disk) null PTE 7 1 VP 1 Memory resident page table (DRAM) VP 2 VP 3 VP 4 VP 6 VP 7 Virtual Memory as Cache

Virtual Memory as Cache Handling Page Fault Page miss causes page fault (an exception) Page fault handler selects a victim to be evicted (here VP 4) Physical memory (DRAM) Physical page number or disk address Virtual address Valid VP 1 PP 0 VP 2 PTE 0 null VP 7 1 VP 3 PP 3 1 1 Virtual memory (disk) null PTE 7 1 VP 1 Memory resident page table (DRAM) VP 2 VP 3 VP 4 VP 6 VP 7 Virtual Memory as Cache

Virtual Memory as Cache Handling Page Fault 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! Physical memory (DRAM) Physical page number or disk address Virtual address Valid VP 1 PP 0 VP 2 PTE 0 null VP 7 1 VP 3 PP 3 1 1 Virtual memory (disk) null PTE 7 1 VP 1 Memory resident page table (DRAM) VP 2 VP 3 VP 4 VP 6 VP 7 Virtual Memory as Cache

Why does it work? Locality Virtual memory works well because of locality Same reason that L1 / L2 / L3 caches work The set of virtual pages that a program is “actively” accessing at any point in time is called its 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 misses If (SUM(working set sizes) > main memory size): Thrashing: Performance meltdown where pages are swapped (copied) in and out continuously Virtual Memory as Cache