Carnegie Mellon 15-213/18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) 1998 - 2010. All Rights Reserved. All work.

Slides:



Advertisements
Similar presentations
Virtual Memory October 25, 2006 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs class16.ppt.
Advertisements

Carnegie Mellon 1 Virtual Memory: Concepts : Introduction to Computer Systems 15 th Lecture, Oct. 14, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
Instructors: Randy Bryant and Dave O’Hallaron
Today Virtual memory (VM) Overview and motivation
Virtual Memory Nov 27, 2007 Slide Source: Topics Motivations for VM Address translation Accelerating translation with TLBs class12.ppt.
Virtual Memory Topics Motivations for VM Address translation Accelerating translation with TLBs CS213.
Virtual Memory October 30, 2001 Topics Motivations for VM Address translation Accelerating translation with TLBs class19.ppt “The course that gives.
Virtual Memory October 29, 2007 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs class16.ppt.
Virtual Memory May 19, 2008 Topics Motivations for VM Address translation Accelerating translation with TLBs EECS213.
Carnegie Mellon 1 Virtual Memory: Concepts / : Introduction to Computer Systems 16 th Lecture, Oct. 21, 2014 Instructors: Greg Ganger, Greg.
Virtual Memory Topics Motivations for VM Address translation Accelerating translation with TLBs CS 105 “Tour of the Black Holes of Computing!”
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.
1 Seoul National University Virtual Memory: Systems.
1 Virtual Memory. 2 Outline Pentium/Linux Memory System Core i7 Suggested reading: 9.6, 9.7.
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)
Pentium III Memory.
Virtual Memory March 23, 2000 Topics Motivations for VM Address translation Accelerating address translation with TLBs Pentium II/III memory system
Carnegie Mellon Introduction to Computer Systems /18-243, spring th Lecture, Mar. 24 th Instructors: Gregory Kesden and Markus Püschel.
Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work.
Instructors: Majd Sakr and Khaled Harras
Virtual Memory.  Next in memory hierarchy  Motivations:  to remove programming burdens of a small, limited amount of main memory  to allow efficient.
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!”
Carnegie Mellon Introduction to Computer Systems / Spring 2009 March 23, 2009 Virtual Memory.
Carnegie Mellon 1 Virtual Memory: Systems / : Introduction to Computer Systems 17 th Lecture, Oct. 27, 2011 Instructors: Dave O’Hallaron,
Virtual Memory Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs.
Virtual Memory October 14, 2008 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs lecture-14.ppt.
CSE 153 Design of Operating Systems Winter 2015 Lecture 11: Paging/Virtual Memory Some slides modified from originals by Dave O’hallaron.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
1 Virtual Memory. 2 Outline Virtual Space Address translation Accelerating translation –with a TLB –Multilevel page tables Different points of view Suggested.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Systems CSCE312: Computer Organization.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Systems CENG331 - Computer Organization.
Carnegie Mellon 1 Virtual Memory: Systems / : Introduction to Computer Systems 17 th Lecture, Mar. 19, 2015 Instructors: Seth Copen Goldstein,
University of Washington Indirection in Virtual Memory 1 Each process gets its own private virtual address space Solves the previous problems Physical.
Virtual Memory: Systems
Alan L. Cox Virtual Memory Alan L. Cox Some slides adapted from CMU slides.
1 Virtual Memory. 2 Outline Case analysis –Pentium/Linux Memory System –Core i7 Suggested reading: 9.7.
Computer Architecture Lecture 12: Virtual Memory I
Virtual Memory Samira Khan Apr 27, 2017.
Virtual Memory Samira Khan Apr 25, 2017.
Section 9: Virtual Memory (VM)
Virtual Memory: Systems
CS703 - Advanced Operating Systems
Section 9: Virtual Memory (VM)
Today How was the midterm review? Lab4 due today.
Virtual Memory: Concepts CENG331 - Computer Organization
Virtual Memory.
CS 105 “Tour of the Black Holes of Computing!”
CSE 153 Design of Operating Systems Winter 2018
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory II CSE 351 Autumn 2016
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: Systems
Virtual Memory: Systems
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory S04, Recitation, Section A
Virtual Memory II CSE 410 Winter 2017
Instructors: Majd Sakr and Khaled Harras
Virtual Memory Nov 27, 2007 Slide Source:
Virtual Memory II CSE 351 Winter 2018
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
Instructor: Phil Gibbons
Presentation transcript:

Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work contained herein is copyrighted and used by permission of the authors. Contact for permission or for more 16 th Lecture, 18 March 2010 Virtual Memory II

Carnegie Mellon Last Time: Virtual Memory Each process gets its own private memory space Mapping function is general: 1 ↔ 1, n ↔ 1, 1 ↔ m Physical memory Virtual memory Process 1 Process n mapping

Carnegie Mellon A System Using Virtual Addressing Used in all modern desktops, laptops, workstations One of the great ideas in computer science MMU checks the cache 0: 1: M-1: Main memory MMU 2: 3: 4: 5: 6: 7: Physical address (PA) Data word 8:... CPU Virtual address (VA) CPU Chip

Carnegie Mellon VM Solves Many Problems VM as a tool for caching  Dodges huge miss penalty associated with disks  Disk latency is millions of cycles (3 GHz / 5mSec = 600 million cycles) VM as a tool for memory management  Each virtual page can be mapped to any physical page  Different pages at different times  Vastly simplifies Linking and Loading VM as a tool for memory protection  Add a few access bits to the page table (SUP, READ, WRITE)  Now, processes are incapable of overwriting each other’s memory  User processes can’t access kernel data structures/code/etc

Carnegie Mellon Today Address Translation Multi-level page tables Intel Core i7 Address Translation

Virtual Address Physical Address Carnegie Mellon Address Translation With a Page Table Virtual page offset (VPO)Virtual page number (VPN) Virtual address Physical page number (PPN)Physical page offset (PPO) Physical address Page table base register (PTBR) Page table address for process Page table Valid bit = 0: page not in memory (page fault) ValidPhysical page number (PPN)

Carnegie Mellon Concrete Examples VAX 11/780 (from 1978)  32-bit virtual address, 32-bit physical address, page size of 512 bytes  How big is VPN / VPO?  PPN? PPO? Alpha (~2002)  43-bit virtual address, 41-bit physical address, page size of 8KB  How big is VPN / VPO?  PPN? PPO? Intel Core i7 (2008)  48-bit virtual address, 52-bit physical address  If page size is 4MB, how many PTEs in page table? How big is PPN?

Carnegie Mellon Address Translation: Page Hit 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 MMU Cache/ Memory PA Data CPU VA CPU Chip PTEA PTE

MMU CPU CPU Chip Carnegie Mellon Address Translation: Page Fault 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 Cache/ Memory VA PTEA PTE Disk Page fault handler Victim page New page Exception 6 7

MMU CPU CPU Chip Carnegie Mellon Aside: Integrating a Cache Cache VA PTEA PTE Memory DATA 6 7 Hit? Y N PTE PTEA 3 PA Hit? Y N PA DATA

MMU CPU CPU Chip Carnegie Mellon Aside: Integrating a Cache (2) Cache VA PTEA PTE Memory DATA 6 7 Hit? Y N PTE PTEA 3 PA Hit? Y N PA DATA Cache usually designed to use physical addresses  Blocks from multiple processes may have the same virtual address  Shared page (i.e. same virtual address) will still have same physical address  Simplifies protection issues ➙ access rights already checked in MMU

Carnegie Mellon Speeding up Translation with a TLB 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 1-cycle delay Solution: Translation Lookaside Buffer (TLB)  Small hardware cache in MMU  Maps virtual page numbers to physical page numbers  Contains complete page table entries for small number of pages

Carnegie Mellon TLB Hit MMU Cache/ Memory PA Data CPU VA CPU Chip PTE TLB VPN 3 A TLB hit eliminates a memory access

MMU Cache/ Memory TLB CPU Carnegie Mellon TLB Miss PA Data VA CPU Chip PTE VPN 4 PTEA 3 A TLB miss incurs an add’l memory access (the PTE)  Fortunately, TLB misses are rare  The PTE may be in cache even then, so 1-2 cycle access

Carnegie Mellon Simple Memory System Example Addressing  14-bit virtual addresses  12-bit physical address  Page size = 64 bytes VPO PPOPPN VPN Virtual Page Number Virtual Page Offset Physical Page Number Physical Page Offset

Carnegie Mellon Example: Page Table Only first 16 PTEs are shown (out of 256) VPNValidPPN VPNValidPPN A109 0B0-- 0C0-- 0D12D 0E111 0F10D

Carnegie Mellon Example: TLB 16 entries 4-way set associative (TLBT = TLB Tag, TLBI = TLB Index) VPOVPN TLBI TLBT SetTagValidPPNTagValidPPNTagValidPPNTagValidPPN D D A D0A

Carnegie Mellon Example: Cache 16 lines, 4-byte block size Physically addressed Direct mapped (CT = Cache Tag, CI = Set Index, CO = Block Offset) PPOPPN CO CI CT IdxTagValidB0B1B2B B D8F09 50D13672F01D C2DF03 IdxTagValidB0B1B2B A D0-- A2D19315DA3B B0B0-- C120-- D E BD3 F140--

Carnegie Mellon Address Translation Example #1 VPOVPN TLBI TLBT PPOPPN CO CI CT

Carnegie Mellon Address Translation Example #2 VPOVPN TLBI TLBT PPOPPN CO CI CT

Carnegie Mellon Address Translation Example #3 VPOVPN TLBI TLBT PPOPPN CO CI CT

Carnegie Mellon Summary Programmer’s view of virtual memory  Each process has its own private linear address space  Cannot be corrupted by other processes System view of virtual memory  Uses memory efficiently by caching virtual memory pages  Efficient only because of locality  Simplifies memory management and programming  Simplifies protection by providing a convenient interpositioning point to check permissions

Carnegie Mellon Today Address Translation Multi-level page tables Intel Core i7 Address Translation

Carnegie Mellon Allocating Virtual Pages Example: Allocating VP5 null Memory resident page table (DRAM) Physical memory (DRAM) VP 7 VP 3 Virtual memory (disk) Valid Physical page number or disk address PTE 0 PTE 7 PP 0 VP 2 VP 1 PP 3 VP 1 VP 2 VP 4 VP 6 VP 7 VP 3

Carnegie Mellon Allocating Virtual Pages Example: Allocating VP 5 Kernel allocates VP 5 on disk and points PTE 5 to it null Memory resident page table (DRAM) Physical memory (DRAM) VP 7 VP 3 Virtual memory (disk) Valid Physical page number or disk address PTE 0 PTE 7 PP 0 VP 2 VP 1 PP 3 VP 1 VP 2 VP 4 VP 6 VP 7 VP 3 VP 5

Carnegie Mellon Multi-Level Page Tables Intel Core i7:  4KB (2 12 ) page size  48-bit address space  4-byte PTE Page table size = 256 GB! Ooops!  2 48 * * 2 2 = 2 38 bytes Common solution  Multi-level page tables  Example: 2-level page table  Level 1 table: each PTE points to a page table  Level 2 table: each PTE points to a page (paged in and out like other data)  Level 1 table stays in memory  Level 2 tables paged in and out Level 1 Table... Level 2 Tables...

Carnegie Mellon A Two-Level Page Table Hierarchy Level 1 page table... Level 2 page tables VP 0... VP 1023 VP VP 2047 Gap 0 PTE 0... PTE 1023 PTE 0... PTE null PTEs PTE unallocated pages VP 9215 Virtual memory (1K - 9) null PTEs PTE 0 PTE 1 PTE 2 (null) PTE 3 (null) PTE 4 (null) PTE 5 (null) PTE 6 (null) PTE 7 (null) PTE 8 2K allocated VM pages for code and data 6K unallocated VM pages 1023 unallocated pages 1 allocated VM page for the stack

VPN 1 0p-1n-1 VPOVPN 2VPN k PPN 0p-1m-1 PPOPPN... Level 1 page table Level 2 page table Level k page table Carnegie Mellon Translating with a k-level Page Table Virtual Address Physical Address

Carnegie Mellon Today Address Translation Multi-level page tables Intel Core i7 Address Translation

L3 unified cache 8 MB, 16-way (shared by all cores) DDR3 Memory controller 3 x GB/s 32 GB/s total (shared by all cores) L1 d-cache 32 KB, 8-way L1 d-TLB 64 entries, 4-way L1 i-TLB 128 entries, 4-way L2 unified TLB 512 entries, 4-way QuickPath interconnect GB/s GB/s total L1 i-cache 32 KB, 8-way L2 unified cache 256 KB, 8-way Instruction fetch Carnegie Mellon Intel Core i7 To Main memory Registers MMU (addr translation) Core x(2-6) To other cores To I/O bridge Chip

PTE Carnegie Mellon Intel Core i7 Address Translation CPU VPNVPO 3612 TLBTTLBI L1 TLB (16 sets, 4 entries/set) VPN1VPN2 99 CR3 PPNPPO 4012 Page tables TLB miss TLB hit Physical address (PA) Result 32/64... CTCO 406 CI 6 L2, L3, and main memory L1 d-cache (64 sets, 8 lines/set) L1 hit L1 miss Virtual address (VA) VPN3VPN4 99 PTE i-cache, i-TLB and L2 unified TLB not shown

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

Carnegie Mellon Further Reading Intel TLBs:  Application Note: “TLBs, Paging-Structure Caches, and Their Invalidation”, April 2007

Carnegie Mellon Summary Address Translation Multi-level Page Tables Intel Core i7 Address Translation Next Time: Virtual Memory III  Linux memory management