Virtual Memory Prof. Eric Rotenberg

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.
Memory Management (II)
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Translation Buffers (TLB’s)
©UCB CS 162 Ch 7: Virtual Memory LECTURE 13 Instructor: L.N. Bhuyan
Virtual Memory I Chapter 8.
Virtual Memory By: Dinouje Fahih. Definition of Virtual Memory Virtual memory is a concept that, allows a computer and its operating system, to use a.
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui COMP 203 / NWEN 201 Computer Organisation / Computer Architectures Virtual.
Virtual Memory Expanding Memory Multiple Concurrent Processes.
Virtual Memory. DRAM as cache What about programs larger than DRAM? When we run multiple programs, all must fit in DRAM! Add another larger, slower level.
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
The Three C’s of Misses 7.5 Compulsory Misses The first time a memory location is accessed, it is always a miss Also known as cold-start misses Only way.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
Virtual Memory 1 1.
4.3 Virtual Memory. Virtual memory  Want to run programs (code+stack+data) larger than available memory.  Overlays programmer divides program into pieces.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
1  2004 Morgan Kaufmann Publishers Chapter Seven Memory Hierarchy-3 by Patterson.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
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)
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
CS203 – Advanced Computer Architecture Virtual Memory.
Memory Management memory hierarchy programs exhibit locality of reference - non-uniform reference patterns temporal locality - a program that references.
Virtual Memory Chapter 8.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
Lecture 11 Virtual Memory
Virtual Memory Chapter 7.4.
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
Section 9: Virtual Memory (VM)
Virtual Memory User memory model so far:
From Address Translation to Demand Paging
Paging COMP 755.
Section 9: Virtual Memory (VM)
From Address Translation to Demand Paging
Today How was the midterm review? Lab4 due today.
CS 704 Advanced Computer Architecture
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.
Memory Hierarchy Virtual Memory, Address Translation
CS510 Operating System Foundations
Virtual Memory: Concepts /18-213/14-513/15-513: Introduction to Computer Systems 17th Lecture, October 23, 2018.
Operating System Concepts
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
From Address Translation to Demand Paging
ECE 445 – Computer Organization
Page that info back into your memory!
Lecture 29: Virtual Memory-Address Translation
Translation Lookaside Buffer
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Virtual Memory Nov 27, 2007 Slide Source:
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2004 Page Tables, TLBs, and Other Pragmatics Hank Levy 1.
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CS703 - Advanced Operating Systems
CSE 451: Operating Systems Winter 2005 Page Tables, TLBs, and Other Pragmatics Steve Gribble 1.
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
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.
Operating Systems: Internals and Design Principles, 6/E
Review What are the advantages/disadvantages of pages versus segments?
Instructor: Phil Gibbons
Virtual Memory 1 1.
Presentation transcript:

Virtual Memory Prof. Eric Rotenberg ECE 463/563 Fall `18 Virtual Memory Prof. Eric Rotenberg Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg Virtual Memory Every program has its own virtual memory Large virtual address space Divided into virtual pages When a program runs, it needs physical memory Physical memory is actual storage: DRAM – main memory Hard Disk – overflow storage for main memory Operating System (O/S) manages physical memory as a shared resource among many running programs When a program first accesses a particular virtual page, O/S is invoked to allocate a physical page in main memory that will now correspond to the program’s virtual page Upon starting a program: The O/S “loader” allocates initial physical pages for the program’s text (code) and data segments (globals, stack) During program execution: The O/S “page-fault handler” allocates physical pages for first-time accesses to new virtual pages (e.g., heap, stack). The handler also swaps physical pages between the main memory (in DRAM) and the overflow storage for main memory (in Hard Disk). Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Physical Page Number (PPN) Virtual Memory (cont.) Virtual Memory for Program #1 Virtual Memory for Program #2 Physical Memory Virtual Page Number (VPN) Virtual Page Number (VPN) 1 1 2 DRAM: Main Memory 2 3 3 4 4 5 Physical Page Number (PPN) 5 1 6 6 2 7 7 3 8 8 4 5 … N … … 1 physical page Hard Disk: Overflow Storage for Main Memory swap space file system 1 virtual page Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg Virtual Memory (cont.) Virtual Memory for Program #1 Virtual Memory for Program #2 Physical Memory VPN: VPN: 1 1 2 DRAM: Main Memory 2 3 3 PPN: 4 4 5 5 1 6 6 2 7 7 3 8 8 4 5 … N … … Hard Disk: Overflow Storage for Main Memory swap space file system Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg Virtual Memory (cont.) Virtual Memory for Program #1 Virtual Memory for Program #2 Physical Memory VPN: VPN: 1 1 2 DRAM: Main Memory 2 3 3 PPN: 4 4 5 5 1 6 6 2 7 7 3 8 8 4 9 5 10 … 11 12 N … … ?? Hard Disk: Overflow Storage for Main Memory swap space file system Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg O/S Page Tables O/S maintains a page table (PT) per running program PT is software data structure used to translate the program’s virtual addresses to physical addresses PT is searched using the virtual address There is one PT entry for each virtual page used by the program. Contents of PT entry: Whether corresponding physical page is in main memory (DRAM) or in swap space (hard disk) If in main memory: PT entry provides physical page number If in swap space: PT entry provides location on disk PT entry typically has other information too (recency of access, protection bits, etc.) Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Virtual-to-Physical Address Translation A running program O/S Page Table for running program Access L1 I/D caches (entry point to memory hierarchy) virtual address physical address translate virtual address to physical address Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Virtual-to-Physical Address Translation VPN DRAM First time VPN referenced? yes PPN first ever access to VPN Scenario 3 Disk no In DRAM or on Disk? DRAM on Disk PPN Scenario 2 Swap-in from disk to DRAM (“page fault”) Scenario 1 Disk DRAM In DRAM PPN PPN Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Overhead of Virtual Memory Program counter is a virtual address Each instruction fetch requires address translation Loads and stores generate virtual addresses Each load and store requires address translation For every instruction fetch, load, and store, call O/S to search the page table??? This would have unacceptable performance The O/S address translation function takes 10s to 100s of instructions and several memory accesses (to access page table). Exact overhead depends on the scenario, page table organization, etc. There has to be a better way… Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Translation Lookaside Buffer (TLB) The TLB is a small cache of recently used address translations TLB is defined in the ISA, because software and hardware collaborate w.r.t. the TLB Hardware role Hardware provides and accesses the TLB Provides: TLB is a hardware table Accesses: Hardware searches the TLB for desired translation. If TLB doesn’t have translation, hardware calls the O/S. Software role Software manages the TLB When there is a TLB miss, O/S is responsible for handling the miss. Once it has a translation, it writes the translation into the TLB, at a location of its choosing. Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Virtual-to-Physical Address Translation, with TLB translate virtual address to physical address A running program TLB Access L1 I/D caches (entry point to memory hierarchy) CPU is executing application virtual address physical address 1 cycle TLB miss exception TLB-write instruction puts translation into TLB O/S Page Table for running program CPU is executing O/S TLB miss exception handler 10s-100s of cycles Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg TLB Organization TLB organization Can be direct-mapped, set-associative, or fully-associative Many modern RISC ISAs define it to be fully-associative since software manages it Unified versus split TLBs Unified: One TLB for both instruction and data address translation Split: Separate TLBs for instruction and data address translation I-TLB: TLB for instruction address translation (program counter). I-TLB sits alongside L1 I-cache. D-TLB: TLB for data address translation (loads and stores). D-TLB sits alongside L1 D-cache. Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Using the TLB for translation Example: Fully-associative TLB X valid bit virtual page number physical page number =? VPN PPN v =? VPN PPN v =? VPN PPN v X’ X =? VPN PPN v X’ Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg TLB increases hit time Without Virtual Memory With Virtual Memory virtual address address TLB 1 cycle L1 Cache 1 cycle physical address L1 Cache 1 cycle Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Using the TLB for translation: A closer look virtual page number page offset 31 12 11 TLB tag block offset index physical page number virtual address Ex: page size = 4KB # page offset bits = log2(4KB) = 12 physical address This is how cache interprets the physical address Observation: What if index bits were entirely contained in page offset bits? Then first part of cache access (indexing) would not wait on TLB Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Accessing TLB and Cache in Parallel data array word select tag array =? virtual page number page offset 31 12 11 TLB tag physical page number index block offset Cache hit time reduces from two cycles to one! Because cache can now be indexed in parallel with TLB access (only the final tag match uses the output from TLB) But some constraints... Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Constraint: Size of 1 cache way Constraint for “physically-indexed cache with parallel cache/TLB access” Index and block offset bits contained within page offset bits Therefore: Total amount of storage in 1 way of the cache should not exceed page size block size set Way 1 Way 2 Way N # sets N-way set-assoc. cache … Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Page size / associativity tradeoff From previous slide: Cache size equation: Therefore: Example: MC88110 Page size = 4KB I$, D$ both: 8KB 2-way set-associative (8KB/4KB) = 2 ways Example: VAX series Page size = 512B For a 16KB cache, need assoc. = (16KB / 512B) = 32-way set-associative! Moral: sometimes associativity is thrust upon you Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg Backup Slides The following slides are for interest only Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Notation on following slide X: Virtual page number to be translated into a physical page number X’: Physical page number corresponding to X V: Virtual page number of a victim page struct page_table_entry { bool resident; // ‘true’ if in DRAM, ‘false’ if on disk (swap space) unsigned int ppn; // if resident==true, this is physical page number disk_loc_type disk_loc; // if resident==false, this is location on disk } // PT is a hash table (unbounded array) of page table entries. // Key (index) of the hash table is virtual page number. If true: X is in DRAM, at PT[X].ppn. Thus X’ = PT[X].ppn. PT[X].resident If false: X is not in DRAM. PT[X].ppn is bogus, PT[X].disk_loc indicates disk location. Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg

Virtual-to-Physical Address Translation X Is X in PT? Is there a free DRAM page? SwapOut(V) PT[V].resident = false PT[V].disk_loc = … PT[X].resident = true PT[X].ppn = PT[V].ppn no no first ever access to X PT[X].resident = true PT[X].ppn = freelist.pop() yes yes SwapOut(V) PT[V].resident = false PT[V].disk_loc = … PT[X].resident = true PT[X].ppn = PT[V].ppn SwapIn(X) PT[X].resident Is there a free DRAM page? false no Swap-in X from disk to DRAM (“page fault”) PT[X].resident = true PT[X].ppn = freelist.pop() SwapIn(X) yes true X’ = PT[X].ppn X’ Fall 2018 ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg