Virtual Memory III CSE 351 Spring 2017

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

COMP 3221: Microprocessors and Embedded Systems Lectures 27: Virtual Memory - III Lecturer: Hui Wu Session 2, 2005 Modified.
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.
Virtual Memory October 29, 2007 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 16 th Lecture, Oct. 21, 2014 Instructors: Greg Ganger, Greg.
Virtual Memory: Concepts
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. 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)
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
Pentium III Memory.
CSE 351 Virtual Memory. Agenda Today … Review on VM Example problems on VM accesses.
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 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs.
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.
1 Virtual Memory. 2 Outline Case analysis –Pentium/Linux Memory System –Core i7 Suggested reading: 9.7.
CS161 – Design and Architecture of Computer
Virtual Memory Samira Khan Apr 27, 2017.
Virtual Memory Chapter 7.4.
Virtual Memory Samira Khan Apr 25, 2017.
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
Section 9: Virtual Memory (VM)
From Address Translation to Demand Paging
CS703 - Advanced Operating Systems
Section 9: Virtual Memory (VM)
From Address Translation to Demand Paging
Today How was the midterm review? Lab4 due today.
Virtual Memory.
CS 105 “Tour of the Black Holes of Computing!”
Some Real Problem What if a program needs more memory than the machine has? even if individual programs fit in memory, how can we run multiple programs?
Caches II CSE 351 Spring 2017 Instructor: Ruth Anderson
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.
CSCI206 - Computer Organization & Programming
Virtual Memory Wrap-Up CSE 351 Autumn 2017
Virtual Memory 3 Hakim Weatherspoon CS 3410, Spring 2011
From Address Translation to Demand Paging
Virtual Memory II CSE 410 Winter 2017
Page that info back into your memory!
Instructors: Majd Sakr and Khaled Harras
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Virtual Memory Nov 27, 2007 Slide Source:
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Translation Buffers (TLB’s)
Virtual Memory II CSE 351 Winter 2018
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
Translation Buffers (TLBs)
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.
CS161 – Design and Architecture of Computer
Review What are the advantages/disadvantages of pages versus segments?
Instructor: Phil Gibbons
Presentation transcript:

Virtual Memory III CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis

Administrivia Homework 4 – Due TONIGHT, this Friday 5/19 Cache questions Lab 4 – Due Tuesday 5/23 Cache runtimes and parameter puzzles Homework 5 – coming soon! Processes and VM Lab 5 – coming soon! Memory Allocator (malloc)

Quick Review What do Page Tables map? Where are Page Tables located? 11/23/2016 Quick Review What do Page Tables map? Where are Page Tables located? How many Page Tables are there? Can your program tell if a page fault has occurred? What is thrashing? True / False: Virtual Addresses that are contiguous will always be contiguous in physical memory TLB stands for _______________________ and stores _______________

Quick Review Answers What do Page Tables map? 11/23/2016 Quick Review Answers What do Page Tables map? VPN → PPN or disk address Where are Page Tables located? In physical memory How many Page Tables are there? One per process Can your program tell if a page fault has occurred? Nope, but it has to wait a long time What is thrashing? Constantly paging out and paging in True / False: Virtual Addresses that are contiguous will always be contiguous in physical memory Could fall across a page boundary TLB stands for Translation Lookaside Buffer and stores page table entries

Example from Section

Simple Memory System Example (small) Addressing 14-bit virtual addresses 12-bit physical address Page size = 64 bytes 13 12 11 10 9 8 7 6 5 4 3 2 1 VPO VPN Virtual Page Number Virtual Page Offset 11 10 9 8 7 6 5 4 3 2 1 PPO PPN Physical Page Number Physical Page Offset

Simple Memory System: Page Table Only showing first 16 entries (out of _____) Note: showing 2 hex digits for PPN even though only 6 bits Note: management bits not shown, but part of each PTE VPN PPN Valid 28 1 – 2 33 3 02 4 5 16 6 7 VPN PPN Valid 8 13 1 9 17 A 09 B – C D 2D E F 0D Size of page table = 2^(n-p) entries

Simple Memory System: TLB 16 entries total 4-way set associative Why does the TLB ignore the page offset? 13 12 11 10 9 8 7 6 5 4 3 2 1 virtual page offset virtual page number TLB index TLB tag Calculate VPN for valid TLB entry using Tag & Set Set Tag PPN Valid Tag PPN Valid Tag PPN Valid Tag PPN Valid 03 – 09 0D 1 00 – 07 02 1 1 03 2D 1 02 – 04 – 0A – 2 02 – 08 – 06 – 03 – 3 07 – 03 0D 1 0A 34 1 02 –

Simple Memory System: Cache Note: It is just coincidence that the PPN is the same width as the cache Tag Simple Memory System: Cache Direct-mapped with K = 4 B, C/K = 16 Physically addressed cache tag cache index cache offset 11 10 9 8 7 6 5 4 3 2 1 physical page number physical page offset Index Tag Valid B0 B1 B2 B3 19 1 99 11 23 15 – 2 1B 00 02 04 08 3 36 4 32 43 6D 8F 09 5 0D 72 F0 1D 6 31 7 16 C2 DF 03 Index Tag Valid B0 B1 B2 B3 8 24 1 3A 00 51 89 9 2D – A 93 15 DA 3B B 0B C 12 D 16 04 96 34 E 13 83 77 1B D3 F 14

Current State of Memory System Page table (partial): TLB: VPN PPN V 28 1 – 2 33 3 02 4 5 16 6 7 VPN PPN V 8 13 1 9 17 A 09 B – C D 2D E F 0D Set Tag PPN V 03 – 09 0D 1 00 07 02 2D 04 0A 2 08 06 3 34 TLB and Cache are separate pieces of hardware; page table stored in memory Show correlation between TLB & page table (VPN 0x0D and 0x0F in particular) Cache: Index Tag V B0 B1 B2 B3 19 1 99 11 23 15 – 2 1B 00 02 04 08 3 36 4 32 43 6D 8F 09 5 0D 72 F0 1D 6 31 7 16 C2 DF 03 Index Tag V B0 B1 B2 B3 8 24 1 3A 00 51 89 9 2D – A 93 15 DA 3B B 0B C 12 D 16 04 96 34 E 13 83 77 1B D3 F 14

Memory Request Example #1 Note: It is just coincidence that the PPN is the same width as the cache Tag Memory Request Example #1 Virtual Address: 0x03D4 Physical Address: TLBI TLBT 13 12 11 10 1 9 8 7 6 5 4 3 2 VPO VPN VPN ______ TLBT _____ TLBI _____ TLB Hit? ___ Page Fault? ___ PPN _____ TLB Hit, Cache Hit 11 10 9 8 7 6 5 4 3 2 1 PPO PPN CO CI CT CT ______ CI _____ CO _____ Cache Hit? ___ Data (byte) _______

Memory Request Example #2 Note: It is just coincidence that the PPN is the same width as the cache Tag Memory Request Example #2 Virtual Address: 0x038F Physical Address: TLBI TLBT 13 12 11 10 1 9 8 7 6 5 4 3 2 VPO VPN VPN ______ TLBT _____ TLBI _____ TLB Hit? ___ Page Fault? ___ PPN _____ TLB Miss, page fault 11 10 9 8 7 6 5 4 3 2 1 PPO PPN CO CI CT CT ______ CI _____ CO _____ Cache Hit? ___ Data (byte) _______

Memory Request Example #3 Note: It is just coincidence that the PPN is the same width as the cache Tag Memory Request Example #3 Virtual Address: 0x0020 Physical Address: TLBI TLBT 13 12 11 10 9 8 7 6 1 5 4 3 2 VPO VPN VPN ______ TLBT _____ TLBI _____ TLB Hit? ___ Page Fault? ___ PPN _____ TLB Miss, Page Table Hit, Cache Miss 11 10 9 8 7 6 5 4 3 2 1 PPO PPN CO CI CT CT ______ CI _____ CO _____ Cache Hit? ___ Data (byte) _______

Memory Request Example #4 Note: It is just coincidence that the PPN is the same width as the cache Tag Memory Request Example #4 Virtual Address: 0x036B Physical Address: TLBI TLBT 13 12 11 10 1 9 8 7 6 5 4 3 2 VPO VPN VPN ______ TLBT _____ TLBI _____ TLB Hit? ___ Page Fault? ___ PPN _____ TLB Hit, Cache Hit 11 10 9 8 7 6 5 4 3 2 1 PPO PPN CO CI CT CT ______ CI _____ CO _____ Cache Hit? ___ Data (byte) _______

Virtual Memory 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 sharing Simplifies protection by providing permissions checking

Address Translation VM is complicated, but also elegant and effective 11/23/2016 Address Translation VM is complicated, but also elegant and effective Level of indirection to provide isolated memory & caching TLB as a cache of page tables avoids two trips to memory for every memory access Virtual Address TLB Lookup Page Table “Walk” Update Page Fault (OS loads page) Protection Check Physical Address TLB Miss TLB Hit Page not in Mem Access Denied Permitted Fault SIGSEGV Page Check cache Find in Disk Find in Mem Need to restart instruction. Soft and hard page faults. CS252 S05

Memory System Summary Memory Caches (L1/L2/L3) Virtual Memory Purely a speed-up technique Behavior invisible to application programmer and (mostly) OS Implemented totally in hardware Virtual Memory Supports many OS-related functions Process creation, task switching, protection Operating System (software) Allocates/shares physical memory among processes Maintains high-level tables tracking memory type, source, sharing Handles exceptions, fills in hardware-defined mapping tables Hardware Translates virtual addresses via mapping tables, enforcing permissions Accelerates mapping via translation cache (TLB)

Memory Overview movl 0x8043ab, %rdi Disk Page Main memory (DRAM) CPU Word Main memory (DRAM) CPU Cache Page Line MMU Line TLB

Memory System – Who controls what? Memory Caches (L1/L2/L3) Controlled by hardware Programmer cannot control it Programmer can write code to take advantage of it Virtual Memory Controlled by OS and hardware Programmer cannot control mapping to physical memory Programmer can control sharing and some protection via OS functions (not in CSE 351)

11/23/2016 Page Table Reality Just one issue… the numbers don’t work out for the story so far! The problem is the page table for each process: Suppose 64-bit VAs, 8 KiB pages, 8 GiB physical memory How many page table entries is that? About how long is each PTE? Moral: Cannot use this naïve implementation of the virtual→physical-page mapping – it’s way too big 2^64/2^13 = 2^51 PPN = 20 bits; plus Valid, R/W/X; so ~ 3 B per PTE So each page table takes up 2^52 + 2^51 B!

A Solution: Multi-level Page Tables This is extra (non-testable) material A Solution: Multi-level Page Tables This is called a page walk Page table base register (PTBR) Virtual Address n-1 p-1 VPN 1 VPN 2 ... VPN k VPO Level 1 page table Level 2 page table Level k page table ... ... PPN m-1 p-1 TLB PTE VPN → PPN PPO Physical Address

Multi-level Page Tables This is extra (non-testable) material Multi-level Page Tables A tree of depth 𝑘 where each node at depth 𝑖 has up to 2 𝑗 children if part 𝑖 of the VPN has 𝑗 bits Hardware for multi-level page tables inherently more complicated But it’s a necessary complexity – 1-level does not fit Why it works: Most subtrees are not used at all, so they are never created and definitely aren’t in physical memory Parts created can be evicted from cache/memory when not being used Each node can have a size of ~1-100KB But now for a 𝑘-level page table, a TLB miss requires 𝑘+1 cache/memory accesses Fine so long as TLB misses are rare – motivates larger TLBs

Practice VM Question Our system has the following properties 1 MiB of physical address space 4 GiB of virtual address space 32 KiB page size 4-entry fully associative TLB with LRU replacement Fill in the following blanks: ________ Entries in page table Minimum bit-width of PTBR TLBT bits Max # of valid entries in a page table

11/23/2016 Practice VM Question One process uses a page-aligned square matrix mat[] of 32-bit integers in the code shown below: #define MAT_SIZE = 2048 for(int i = 0; i < MAT_SIZE; i++) mat[i * (MAT_SIZE + 1)] = i; What is the largest stride (in bytes) between successive memory accesses (in the VA space)?

Practice VM Question One process uses a page-aligned square matrix mat[] of 32-bit integers in the code shown below: #define MAT_SIZE = 2048 for(int i = 0; i < MAT_SIZE; i++) mat[i * (MAT_SIZE + 1)] = i; What are the following hit rates for the first execution of the for loop? ________ TLB Hit Rate Page Table Hit Rate