ECE 252 / CPS 220 Advanced Computer Architecture I Lecture 14 Virtual Memory Benjamin Lee Electrical and Computer Engineering Duke University www.duke.edu/~bcl15.

Slides:



Advertisements
Similar presentations
Virtual Memory Basics.
Advertisements

EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
Virtual Memory Chapter 18 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi.
Virtual Memory Hardware Support
CSC 4250 Computer Architectures December 8, 2006 Chapter 5. Memory Hierarchy.
COMP 3221: Microprocessors and Embedded Systems Lectures 27: Virtual Memory - III Lecturer: Hui Wu Session 2, 2005 Modified.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Address Translation and Protection Steve Ko Computer Sciences and Engineering University at.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Virtual Memory I Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 490/590 Computer Architecture Virtual Memory II
February 25, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 11 - Virtual Memory and Caches Krste Asanovic Electrical Engineering.
CS 153 Design of Operating Systems Spring 2015
CSCE 212 Chapter 7 Memory Hierarchy Instructor: Jason D. Bakos.
CS 152 Computer Architecture and Engineering Lecture 11 - Virtual Memory and Caches Krste Asanovic Electrical Engineering and Computer Sciences University.
CS 152 Computer Architecture and Engineering Lecture 10 - Virtual Memory Krste Asanovic Electrical Engineering and Computer Sciences University of California.
S.1 Review: The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of.
February 23, 2011CS152, Spring 2011 CS 152 Computer Architecture and Engineering Lecture 9 - Virtual Memory Krste Asanovic Electrical Engineering and Computer.
February 16, 2011CS152, Spring 2011 CS 152 Computer Architecture and Engineering Lecture 8 - Address Translation Krste Asanovic Electrical Engineering.
CS 152 Computer Architecture and Engineering Lecture 9 - Address Translation Krste Asanovic Electrical Engineering and Computer Sciences University of.
February 23, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 10 - Virtual Memory Krste Asanovic Electrical Engineering and.
Translation Buffers (TLB’s)
CS 152 Computer Architecture and Engineering Lecture 9 - Address Translation Krste Asanovic Electrical Engineering and Computer Sciences University of.
Memory: Virtual MemoryCSCE430/830 Memory Hierarchy: Virtual Memory CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng Zhu.
A. Frank - P. Weisberg Operating Systems Simple/Basic Paging.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Memory Hierarchy 2.
February 18, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 9 - Address Translation Krste Asanovic Electrical Engineering.
© Krste Asanovic, 2014CS252, Spring 2014, Lecture 15 CS252 Graduate Computer Architecture Spring 2014 Lecture 15: Virtual Memory and Caches Krste Asanovic.
CSE431 L22 TLBs.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 22. Virtual Memory Hardware Support Mary Jane Irwin (
Lecture 19: Virtual Memory
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
CS 61C: Great Ideas in Computer Architecture Virtual Memory Instructors: Krste Asanovic, Randy H. Katz 1Fall.
ECE 552 / CPS 550 Advanced Computer Architecture I Lecture 14 Virtual Memory Benjamin Lee Electrical and Computer Engineering Duke University
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Virtual Memory Muhamed Mudawar CS 282 – KAUST – Spring 2010 Computer Architecture & Organization.
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
2/14/2013 CS152, Spring 2013 CS 152 Computer Architecture and Engineering Lecture 8 - Address Translation Krste Asanovic Electrical Engineering and Computer.
Review (1/2) °Caches are NOT mandatory: Processor performs arithmetic Memory stores data Caches simply make data transfers go faster °Each level of memory.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Virtual Memory.  Next in memory hierarchy  Motivations:  to remove programming burdens of a small, limited amount of main memory  to allow efficient.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
© Krste Asanovic, 2014CS252, Spring 2014, Lecture 14 CS252 Graduate Computer Architecture Spring 2014 Lecture 14: Memory Protection and Address Translation.
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
Virtual Memory CENG331 - Computer Organization Instructor: Murat Manguoglu(Section 1) Adapted from:
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
CS203 – Advanced Computer Architecture Virtual Memory.
1 Lecture 12 Virtual Memory Peng Liu
CENG709 Computer Architecture and Operating Systems Lecture 8 - Address Translation Murat Manguoglu Department of Computer Engineering Middle East Technical.
CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.
CMSC 611: Advanced Computer Architecture
Bernhard Boser & Randy Katz
From Address Translation to Demand Paging
From Address Translation to Demand Paging
CS 704 Advanced Computer Architecture
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
From Address Translation to Demand Paging
CS 105 “Tour of the Black Holes of Computing!”
Lecture 12 Virtual Memory
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Virtual Memory Nov 27, 2007 Slide Source:
CSE 451: Operating Systems Autumn 2005 Memory Management
Virtual Memory Overcoming main memory size limitation
CS 152 Computer Architecture and Engineering CS252 Graduate Computer Architecture Lecture 8 – Address Translation Krste Asanovic Electrical Engineering.
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CS 105 “Tour of the Black Holes of Computing!”
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Address Translation and Virtual Memory CENG331 - Computer Organization
CS 105 “Tour of the Black Holes of Computing!”
CS703 - Advanced Operating Systems
Dr. George Michelogiannakis EECS, University of California at Berkeley
Presentation transcript:

ECE 252 / CPS 220 Advanced Computer Architecture I Lecture 14 Virtual Memory Benjamin Lee Electrical and Computer Engineering Duke University

ECE 252 / CPS 2202 ECE252 Administrivia 20 October – Project Proposals Due One page proposal 1.What question are you asking? 2.How are you going to answer that question? 3.Talk to me if you are looking for project ideas. 25 October – Homework #3 Due 25 October – Class Discussion Roughly one reading per class. Do not wait until the day before! 1.Jouppi. “Improving direct-mapped cache performance by the addition of a small fully-associative cache and prefetch buffers.” 2.Kim et al. “An adaptive, non-uniform cache structure for wire-delay dominated on-chip caches.” 3.Fromm et al. “The energy efficiency of IRAM architectures” 4.Lee et al. “Phase change memory architecture and the quest for scalability”

ECE 252 / CPS 2203 Last Time Caches Quantify cache/memory hierarchy with AMAT Three types of cache misses: (1) compulsory, (2) capacity, (3) conflict Cache structure and data placement policies determine miss rates Write buffers improve performance Prefetching Identify and exploit spatial locality Prefetchers can be implemented in hardware, software, both Caches and Code Restructuring SW code can improve HW cache performance Data re-use can improve with code structure (e.g., matrix multiply)

ECE 252 / CPS 2204 Physical Addresses One program runs at a time. Program has unrestricted access to machine (RAM, I/O) Program addresses depend on where program is loaded into memory But programmers do not think about memory addresses when writing sub-routines… -How is location independence achieved? Loader/Linker -(1) loads sub-routines into memory, determines physical addresses, -(2) links multiple sub-routines, -(3) resolves physical addresses so jumps to sub-routines go to correct memory locations

ECE 252 / CPS 2205 Machine with Physical Addresses With unrestricted access to a machine, program uses physical addresses. PC Inst. Cache D Decode EM Data Cache W + Main Memory (DRAM) Memory Controller Physical Address

ECE 252 / CPS 2206 Address Translation Motivation -In early machines, I/O is slow and requires processor support -Increase throughput by over-lapping I/O for multiple programs -Eliminate processor support with direct memory access (DMA) -DMA: (1) Processor initiates I/O, (2) Processor does other operations during transfer, (3) Processor receives interrupt from DMA controller when transfer is complete Location-Independent Programs -Simplify program and storage management Protection -Independent programs should not affect others (isolated memory spaces) -Multi-programming requires “supervisor” to schedule programs, manage context switches between programs prog1 prog2 Physical Memory OS

ECE 252 / CPS 2207 Virtual and Physical Memory Programs receive allocations of physical memory at specific physical addresses. Program operates in virtual memory with virtual addresses. Memory Management Unit (MMU) – performs address translation to map virtual addresses to physical addresses. Virtual Memory Physical Memory

ECE 252 / CPS Base & Bound Base register – Identifies a program’s allocation in physical memory. Bound register – Provides protection and isolation between programs Base, Bound registers visible only when processor is running in “supervisor” mode Virtual Memory Program Address Space Bound Register  Bounds Violation? Physical Memory current segment Base Register + Physical Address Virtual Address Base Physical Address Segment Length

ECE 252 / CPS 2209 Machine with Virtual Addresses Every access to memory requires translating virtual addresses to physical addresses. Efficient adder implementations are possible for (base+offset). PC Inst. Cache D Decode EM Data Cache W + Main Memory (DRAM) Memory Controller Physical Address Data Bound Register Data Base Register  + Logical Address Bounds Violation? Physical Address Prog. Bound Register Program Base Register  + Logical Address Bounds Violation?

ECE 252 / CPS Base & Bounds Implementation Hardware Cost -Two registers, adder, comparator -Fast logic Context Switch -Save/restore base, bound registers

ECE 252 / CPS Segmentation Motivation -Separate virtual address space into several segments. -Each segment is contiguous but segments may be fragmented. -Segmentation does not require fully contiguous address space (i.e., allow holes in address space) Idea -Generalize Base & Bounds -Implement a table of base-bound pairs Virtual Segment #Physical Segment BaseSegment Size Code (00)0x40000x700 Data (01)0x00000x500 -(10)00 Stack(11)0x20000x1000

ECE 252 / CPS Data & Program Segments What is the advantage of this separation? Physical Address Virtual Memory Program Address Space Main Memory data segment Data Bound Register Mem. Address Register Data Base Register  + Bounds Violation? Program Bound Register Program Counter Program Base Register  + Bounds Violation? program segment Logical Address

ECE 252 / CPS Segmentation Implementation Virtual Address -Partition into segment and offset -Segment – Specifies segment number, which indexes table -Offset – Specifies offset within a segment Segment Table -Segment – Provides segment base -Size – Provides segment bound Translation -Compute physical address from segment base, offset, and bound

ECE 252 / CPS Fragmentation -As programs enter and leave the system, physical memory is fragmented. -Fragmentation occurs because segments are variable size OS Space 16K 32K user 1 user 2 user 3 OS Space 16K 24K user 1 user 2 user 3 user 5 user 4 8K Users 4 & 5 arrive Users 2 & 5 leave OS Space 16K 24K 16K 24K user 1 user 4 8K user 3 free 24K 32K

ECE 252 / CPS Paging Motivation -Branch&Bounds, Segmentation require fancy memory management -Example: What mechanism coalesces free fragments? Idea -Constrain segmentation with fixed-size segments (e.g., pages) -Paging simplifies memory management -Example: free page management is a simple bitmap Each bit represents on page of physical memory -1 means allocated, 0 means free

ECE 252 / CPS Paging Implementation Virtual Address -Partition into page and offset -Page – Specifies virtual page number, which indexes table -Offset – Specifies offset within a page Page Table -Page – Provides a physical page number -Size – No longer required, all pages equal size (e.g., 4KB) Translation -Compute physical address from physical page number, offset

ECE 252 / CPS – Segmentation & Paging Motivation -Assume 32-bit virtual addresses, 4KB page size -4KB = 4096 bytes = 2 12 bytes per page bytes per page requires a 12-bit offset -Remaining address bits used for page number, 20-bit page number -Page tables can be very large. -With 20-bit page number, 2 20 pages -Each program in multi-programmed machine requires its own page table -Total size of page tables = [# of programs] x 2 20 Idea -Combine segmentation with paging -Adds indirection to reduce size of page table

ECE 252 / CPS Segmented Page Tables Virtual Address -Partition into segment, page, offset -Segment –Specifies segment#, which indexes Table 1 -Page – Specifies virtual page # number, which indexes Table 2 -Offset – Specifies offset in page Table 1 -Segment – Points to a page table -Size – Specifies number of pages in segment Table 2 -Page – Provides a physical page# Translation -Compute physical address from physical page number, offset What about paged page tables?

ECE 252 / CPS Address Translation & Protection -Every access to instruction/data memory requires (1) address translation and (2) protection checks -A good virtual memory system must be fast (completing in approximately 1 cycle) and space efficient Physical Address Virtual Address Address Translation Virtual Page No. (VPN)offset Physical Page No. (PPN)offset Protection Check Exception? Kernel/User Mode Read/Write

ECE 252 / CPS Translation Lookaside Buffer (TLB) Address Translation is Expensive -In a two-level page table, each reference requires several memory accesses. Solution -Cache translations. We use a data structure called a TLB. -TLB Hit – single cycle translation -TLB Miss – walk page table to translate, update TLB VPN offset tag PPN physical address PPN offset virtual address hit? (VPN = virtual page number) (PPN = physical page number)

ECE 252 / CPS TLB Design entries, fully associative -Each entry maps a large page. Little spatial locality across 4KB pages. Conflicts are more likely. -Larger TLBs (e.g., entries) may be 4-8 way set-associative -Even larger systems may have multi-level TLBs Random or FIFO replacement policies Definition – TLB Reach -Size of largest virtual address space that can be simultaneously mapped -64 entries, 4KB pages, 1 page per entry -TLB Reach = [64 entries] x [4KB] = 256KB (if pages contiguous in memory)

ECE 252 / CPS TLB Misses Software (MIPS, Alpha) -TLB miss causes an exception -Operating system walks page table and reloads TLB -Requires privileged processor mode. Why? Hardware (SPARC v8, x86, PowerPC) -Memory management unit (MMU) walks page table and reloads TLB -If MMU encounters missing page, MMU causes an exception -Operating system handles page fault, which requires transferring page from disk to memory.

ECE 252 / CPS Machine with Virtual Memory PC Inst. TLB Inst. Cache D Decode EM Data Cache W + Page Fault? Protection violation? Page Fault? Protection violation? Data TLB Main Memory (DRAM) Memory Controller Physical Address Page-Table Base Register Virtual Address Physical Address Virtual Address Hardware Page Table Walker Miss?

ECE 252 / CPS Address Translation Summary virtual address TLB Lookup Page Table Walk update TLB page fault (OS loads page) Protection Check physical address (use to access L1 cache) miss hit denied permitted protection fault hardware hardware or software software exception handler page in mem page not in mem seg fault

ECE 252 / CPS Summary Virtual Memory Enables multi-programming Programs operate in virtual memory space Programs are protected from each other Virtual to Physical Address Translation Base&Bound Segmentation Paging Multi-level Translation (segmented paging, paged paging) Translation Lookaside Buffer Accelerates virtual memory, address translation

ECE 252 / CPS Acknowledgements These slides contain material developed and copyright by -Arvind (MIT) -Krste Asanovic (MIT/UCB) -Joel Emer (Intel/MIT) -James Hoe (CMU) -Arvind Krishnamurthy (U. Washington) -John Kubiatowicz (UCB) -Alvin Lebeck (Duke) -David Patterson (UCB) -Daniel Sorin (Duke)