Virtual Memory: From Address Translation to Demand Paging

Similar documents
Virtual Memory: From Address Translation to Demand Paging

CS 152 Computer Architecture and Engineering. Lecture 11 - Virtual Memory and Caches

Modern Virtual Memory Systems. Modern Virtual Memory Systems

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

CS 152 Computer Architecture and Engineering. Lecture 9 - Virtual Memory

CS 152 Computer Architecture and Engineering. Lecture 9 - Address Translation

CS 152 Computer Architecture and Engineering. Lecture 9 - Address Translation

Lecture 9 - Virtual Memory

CS 152 Computer Architecture and Engineering. Lecture 8 - Address Translation

CS 152 Computer Architecture and Engineering. Lecture 8 - Address Translation

John Wawrzynek & Nick Weaver

CS 61C: Great Ideas in Computer Architecture. Lecture 23: Virtual Memory. Bernhard Boser & Randy Katz

CS 61C: Great Ideas in Computer Architecture. Lecture 23: Virtual Memory

CS252 Spring 2017 Graduate Computer Architecture. Lecture 17: Virtual Memory and Caches

Lecture 9 Virtual Memory

CS 61C: Great Ideas in Computer Architecture Virtual Memory. Instructors: John Wawrzynek & Vladimir Stojanovic

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

Virtual Memory and Interrupts

CS 152 Computer Architecture and Engineering. Lecture 9 - Virtual Memory. Last?me in Lecture 9

CS 152 Computer Architecture and Engineering CS252 Graduate Computer Architecture. Lecture 9 Virtual Memory

Last =me in Lecture 7 3 C s of cache misses Compulsory, Capacity, Conflict

ECE 4750 Computer Architecture, Fall 2017 T03 Fundamental Memory Concepts

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

CS 318 Principles of Operating Systems

COSC3330 Computer Architecture Lecture 20. Virtual Memory

Virtual Memory Virtual memory first used to relive programmers from the burden of managing overlays.

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Chapter 8. Virtual Memory

CSE 120 Principles of Operating Systems Spring 2017

New-School Machine Structures. Overarching Theme for Today. Agenda. Review: Memory Management. The Problem 8/1/2011

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

Virtual Memory. Motivation:

Cache Performance and Memory Management: From Absolute Addresses to Demand Paging. Cache Performance

CSE 120 Principles of Operating Systems

Virtual to physical address translation

Improving Cache Performance and Memory Management: From Absolute Addresses to Demand Paging. Highly-Associative Caches

EECS 470. Lecture 16 Virtual Memory. Fall 2018 Jon Beaumont

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

Computer Science 146. Computer Architecture

Computer Architecture Lecture 13: Virtual Memory II

CS 153 Design of Operating Systems Winter 2016

Virtual Memory. Samira Khan Apr 27, 2017

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Learning to Play Well With Others

Virtual Memory. Virtual Memory

VIRTUAL MEMORY II. Jo, Heeseung

Processes and Virtual Memory Concepts

Computer Systems. Virtual Memory. Han, Hwansoo

virtual memory. March 23, Levels in Memory Hierarchy. DRAM vs. SRAM as a Cache. Page 1. Motivation #1: DRAM a Cache for Disk

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

Virtual Memory Oct. 29, 2002

Computer Architecture. Lecture 8: Virtual Memory

CS162 - Operating Systems and Systems Programming. Address Translation => Paging"

virtual memory Page 1 CSE 361S Disk Disk

A Typical Memory Hierarchy

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Memory: Page Table Structure. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

CS 152 Computer Architecture and Engineering CS252 Graduate Computer Architecture. Lecture 8 Address Transla>on

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

Agenda. CS 61C: Great Ideas in Computer Architecture. Virtual Memory II. Goals of Virtual Memory. Memory Hierarchy Requirements

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Computer Architecture ECE 568/668

A Typical Memory Hierarchy

HY225 Lecture 12: DRAM and Virtual Memory

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

1. Creates the illusion of an address space much larger than the physical memory

Virtual Memory. Reading. Sections 5.4, 5.5, 5.6, 5.8, 5.10 (2) Lecture notes from MKP and S. Yalamanchili

ECE468 Computer Organization and Architecture. Virtual Memory

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

ECE4680 Computer Organization and Architecture. Virtual Memory

SE-292 High Performance Computing. Memory Hierarchy. R. Govindarajan

Virtual Memory. CS61, Lecture 15. Prof. Stephen Chong October 20, 2011

Learning to Play Well With Others

Chapter 5. Large and Fast: Exploiting Memory Hierarchy. Part II Virtual Memory

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

Virtual Memory. CS 3410 Computer System Organization & Programming

Chapter 5 (Part II) Large and Fast: Exploiting Memory Hierarchy. Baback Izadi Division of Engineering Programs

CSE 351. Virtual Memory

Topic 18: Virtual Memory

ECE331: Hardware Organization and Design

18-447: Computer Architecture Lecture 18: Virtual Memory III. Yoongu Kim Carnegie Mellon University Spring 2013, 3/1

@2010 Badri Computer Architecture Assembly II. Virtual Memory. Topics (Chapter 9) Motivations for VM Address translation

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Transla'on, Protec'on, and Virtual Memory. 2/25/16 CS 152 Sec'on 6 Colin Schmidt

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

Cache Performance (H&P 5.3; 5.5; 5.6)

CS 61C: Great Ideas in Computer Architecture Virtual Memory. Instructors: Krste Asanovic & Vladimir Stojanovic h>p://inst.eecs.berkeley.

CS 5523 Operating Systems: Memory Management (SGG-8)

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Chapter Seven. Memories: Review. Exploiting Memory Hierarchy CACHE MEMORY AND VIRTUAL MEMORY

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

CHAPTER 4 MEMORY HIERARCHIES TYPICAL MEMORY HIERARCHY TYPICAL MEMORY HIERARCHY: THE PYRAMID CACHE PERFORMANCE MEMORY HIERARCHIES CACHE DESIGN

V. Primary & Secondary Memory!

ECE232: Hardware Organization and Design

Virtual Memory II CSE 351 Spring

Virtual Memory. Stefanos Kaxiras. Credits: Some material and/or diagrams adapted from Hennessy & Patterson, Hill, online sources.

Multi-level Translation. CS 537 Lecture 9 Paging. Example two-level page table. Multi-level Translation Analysis

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

Transcription:

Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November 12, 2014 http://csg.csail.mit.edu/6.175 L20-1

Modern Virtual Memory Systems Illusion of a large, private, uniform store Protection & Privacy Each user has one private and one or more shared address spaces page table name space Demand Paging Provides the ability to run programs larger than the primary memory Hides differences in machine configurations Primary Memory OS user i Swapping Store The price of VM is address translation on each memory reference VA mapping TLB PA November 12, 2014 http://csg.csail.mit.edu/6.175 L20-2

Names for Memory Locations machine language address ISA virtual address Address Mapping physical address Physical Memory (DRAM) Machine language address as specified in machine code Virtual address ISA specifies translation of machine code address into virtual address of program variable (sometime called effective address) Physical address operating system specifies mapping of virtual address into name for a physical memory location November 12, 2014 http://csg.csail.mit.edu/6.175 L20-3

Paged Memory Systems Processor generated address can be interpreted as a pair <page number, offset> A page table contains the physical address of the base of each page 0 1 2 3 Address Space of User-1 page number 0 1 2 3 Page Table of User-1 offset Page tables make it possible to store the pages of a program non-contiguously November 12, 2014 http://csg.csail.mit.edu/6.175 L20-4 1 0 3 2

Physical Memory Private Address Space per User User 1 VA1 Page Table OS pages User 2 VA1 Page Table User 3 VA1 Page Table Each user has a page table Page table contains an entry for each user page free November 12, 2014 http://csg.csail.mit.edu/6.175 L20-5

Page Tables in Physical Memory PT User 1 VA1 User 1 Two memory references are required to access a virtual address. 100% overhead! PT User 2 VA1 User 2 Idea: cache the address translation of frequently used pages Translation Lookaside Buffer (TLB) November 12, 2014 http://csg.csail.mit.edu/6.175 L20-6

Linear Page Table Page Table Entry (PTE) contains: A bit to indicate if a page exists PPN (physical page number) for a memoryresident page DPN (disk page number) for a page on the disk Status bits for protection and usage OS sets the Page Table Base Register whenever active user process changes PT Base Register Page Table PPN PPN DPN PPN DPN PPN PPN DPN DPN DPN PPN PPN VPN Offset VPN Offset Virtual address Data Pages Data word November 12, 2014 http://csg.csail.mit.edu/6.175 L20-7

Size of Linear Page Table With 32-bit addresses, 4-KB pages & 4-byte PTEs 2 20 PTEs, i.e, 4 MB page table per user 4 GB of swap space needed to back up the full virtual address space Larger Pages can reduce the overhead but cause Internal fragmentation (Not all memory in a page is used) Larger page-fault penalty (more time to read from disk) What about 64-bit virtual address space? Even 1MB pages would require 2 44 8-byte PTEs (35 TB!) Any saving grace? Page tables are sparsely populated and hence hierarchical organization can help November 12, 2014 http://csg.csail.mit.edu/6.175 L20-8

Hierarchical Page Table Virtual Address 31 22 21 12 11 p1 p2 offset 0 10-bit L1 index Root of the Page Table 10-bit L2 index p1 p2 offset (Processor Register) Level 1 Page Table page in primary memory page in secondary memory Level 2 Page Tables PTE of a nonexistent page Data Pages November 12, 2014 http://csg.csail.mit.edu/6.175 L20-9

Address Translation & Protection Virtual Address Kernel/User Mode Virtual Page No. (VPN) offset Read/Write Protection Check Address Translation Exception? Physical Address Physical Page No. (PPN) offset Every instruction access and data access needs address translation and protection checks Address translation is very expensive! In a one-level page table, each reference becomes two or more memory accesses A good VM design needs to be fast and space efficient November 12, 2014 http://csg.csail.mit.edu/6.175 L20-10

Translation Lookaside Buffers (TLB) Cache address translations in TLB TLB hit Single Cycle Translation TLB miss Page Table Walk to refill virtual address VPN offset V R W D tag PPN hit? physical address PPN offset November 12, 2014 http://csg.csail.mit.edu/6.175 L20-11

TLB Designs Typically 32-128 entries, usually fully associative Each entry maps a large page, hence less spatial locality across pages more likely that two entries conflict Sometimes larger TLBs (256-512 entries) are 4-8 way set-associative Random or FIFO replacement policy Process ID information in TLB? TLB Reach: Size of largest virtual address space that can be simultaneously mapped by TLB Example: 64 TLB entries, 4KB pages, one page per entry TLB Reach = 64 entries * 4 KB = 256 KB November 12, 2014 http://csg.csail.mit.edu/6.175 L20-12

Handling a TLB Miss Software (MIPS, Alpha) TLB miss causes an exception and the operating system walks the page tables and reloads TLB A privileged untranslated addressing mode is used for PT walk Hardware (SPARC v8, x86, PowerPC) A memory management unit (MMU) walks the page tables and reloads the TLB If a missing (data or PT) page is encountered during the TLB reloading, MMU gives up and signals a Page- Fault exception for the original instruction November 12, 2014 http://csg.csail.mit.edu/6.175 L20-13

Translation for Page Tables Can references to page tables cause TLB misses? User PTE Base User Page Table (in virtual space) User VA translation causes a TLB miss Page table walk: User PTE Base and appropriate bits from VA are used to obtain virtual address (VP) for the page table entry Suppose we get a TLB miss when we try to translate VP? Must know the physical address of the page table November 12, 2014 http://csg.csail.mit.edu/6.175 L20-14

Translation for Page Tables continued User PTE Base User Page Table (in virtual space) System PTE Base System Page Table (in physical space) On a TLB miss during a VP translation, OS adds System PTE Base to bits from VP to find physical address of page table entry for the VP A program that traverses the page table needs a no translation addressing mode November 12, 2014 http://csg.csail.mit.edu/6.175 L20-15

Handling a Page Fault When the referenced page is not in DRAM: The missing page is located (or created) It is brought in from disk, and page table is updated Another job may be run on the CPU while the first job waits for the requested page to be read from disk If no free pages are left, a page is swapped out approximate LRU replacement policy Since it takes a long time (msecs) to transfer a page, page faults are handled completely in software (OS) Untranslated addressing mode is essential to allow kernel to access page tables November 12, 2014 http://csg.csail.mit.edu/6.175 L20-16

Swapping a Page of a Page Table A PTE in primary memory contains primary or secondary memory addresses A PTE in secondary memory contains only secondary memory addresses a page of a PT can be swapped out only if none its PTE s point to pages in the primary memory Why? Don t want to cause a page fault during translation when the data is in memory November 12, 2014 http://csg.csail.mit.edu/6.175 L20-17

Address Translation: putting it all together Virtual Address TLB Lookup hardware hardware or software software miss hit Page Table Walk Protection Check the page is memory memory denied permitted Where? Page Fault (OS loads page) Update TLB SEGFAULT Protection Fault Physical Address (to cache) November 12, 2014 http://csg.csail.mit.edu/6.175 L20-18

Caching vs. Demand Paging secondary memory CPU cache primary memory CPU primary memory Caching Demand paging cache entry page frame cache block (~32 bytes) page (~4K bytes) cache miss rate (1% to 20%) page miss rate (<0.001%) cache hit (~1 cycle) page hit (~100 cycles) cache miss (~100 cycles) page miss (~5M cycles) a miss is handled a miss is handled in hardware mostly in software November 12, 2014 http://csg.csail.mit.edu/6.175 L20-19

Address Translation in CPU Pipeline PC Inst TLB Inst. Cache D Decode E M + Data TLB Data Cache W TLB miss? Page Fault? Protection violation? Software handlers need a restartable exception on page fault or protection violation Handling a TLB miss needs a hardware or software mechanism to refill TLB Need mechanisms to cope with the additional latency of a TLB: slow down the clock pipeline the TLB and cache access virtual address caches parallel TLB/cache access TLB miss? Page Fault? Protection violation? November 12, 2014 http://csg.csail.mit.edu/6.175 L20-20

Physical or Virtual Address Caches? CPU VA TLB Physical Cache PA Primary Memory Alternative: place the cache before the TLB VA CPU Virtual Cache TLB PA Primary Memory (StrongARM) one-step process in case of a hit (+) cache needs to be flushed on a context switch unless address space identifiers (ASIDs) included in tags (-) aliasing problems due to the sharing of pages (-) November 12, 2014 http://csg.csail.mit.edu/6.175 L20-21

Aliasing in Virtual-Address Caches Page Table Tag Data VA 1 Data Pages VA 1 1st Copy of Data at PA PA VA 2 2nd Copy of Data at PA VA 2 Two virtual pages share one physical page Virtual cache can have two copies of same physical data. Writes to one copy not visible to reads of other! General Solution: Disallow aliases to coexist in cache Software (i.e., OS) solution for direct-mapped cache VAs of shared pages must agree in cache index bits; this ensures all VAs accessing same PA will conflict in directmapped cache (early SPARCs) November 12, 2014 http://csg.csail.mit.edu/6.175 L20-22

VA Concurrent Access to TLB & Cache VPN L b Virtual Index PA TLB PPN Page Offset k Direct-map Cache 2 L blocks 2 b -byte block Tag hit? = Physical Tag Data Index L is available without consulting the TLB cache and TLB accesses can begin simultaneously Tag comparison is made after both accesses are completed Cases: L + b = k L + b < k L + b > k what happens here? Partially VA cache! November 12, 2014 http://csg.csail.mit.edu/6.175 L20-23

Virtual-Index Physical-Tag Caches: Associative Organization VA VPN L = k-b b W ways Virtual Index TLB k Direct-map 2 L blocks Direct-map 2 L blocks PA PPN Page Offset Phy. Tag Tag hit? = = After the PPN is known, W physical tags are compared Data Allows cache size to be greater than 2 L+b bytes November 12, 2014 http://csg.csail.mit.edu/6.175 L20-24

November 12, 2014 http://csg.csail.mit.edu/6.175 L20-25