CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago

Similar documents
Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5.

CS61C : Machine Structures

Computer Architecture. Lecture 8: Virtual Memory

CMSC Computer Architecture Lecture 10: Caches. Prof. Yanjing Li University of Chicago

Page 1. Why Care About the Memory Hierarchy? Memory. DRAMs over Time. Virtual Memory!

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5

Course Site: Copyright 2012, Elsevier Inc. All rights reserved.

The University of Adelaide, School of Computer Science 22 November Computer Architecture. A Quantitative Approach, Sixth Edition.

CMSC Computer Architecture Lecture 2: ISA. Prof. Yanjing Li Department of Computer Science University of Chicago

CMSC Computer Architecture Lecture 11: More Caches. Prof. Yanjing Li University of Chicago

Master Informatics Eng. 2017/18. A.J.Proença. Memory Hierarchy. (most slides are borrowed) AJProença, Advanced Architectures, MiEI, UMinho, 2017/18 1

Virtual Memory: From Address Translation to Demand Paging

Virtual Memory: From Address Translation to Demand Paging

Chapter 4 Threads. Operating Systems: Internals and Design Principles. Ninth Edition By William Stallings

Outline. CSCI 4730 Operating Systems. Questions. What is an Operating System? Computer System Layers. Computer System Layers

Multi-Threading. Hyper-, Multi-, and Simultaneous Thread Execution

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

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

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

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

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

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

virtual memory Page 1 CSE 361S Disk Disk

Virtual Memory. Samira Khan Apr 27, 2017

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

CMSC22200 Computer Architecture Lecture 9: Out-of-Order, SIMD, VLIW. Prof. Yanjing Li University of Chicago

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

n Explore virtualization concepts n Become familiar with cloud concepts

Computer Architecture Lecture 13: Virtual Memory II

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Appendix D. Controller Implementation

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Part A Datapath Design

Multiprocessors. HPC Prof. Robert van Engelen

Virtual Memory Oct. 29, 2002

Virtual Memory, Address Translation

Elementary Educational Computer

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

Chapter 4 The Datapath

CMSC Computer Architecture Lecture 15: Multi-Core. Prof. Yanjing Li University of Chicago

CMSC Computer Architecture Lecture 3: ISA and Introduction to Microarchitecture. Prof. Yanjing Li University of Chicago

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Single-Cycle Disadvantages & Advantages

The Magma Database file formats

K-NET bus. When several turrets are connected to the K-Bus, the structure of the system is as showns

CISC 360. Virtual Memory Dec. 4, 2008

Hash Tables. Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.

Topic 18: Virtual Memory

Virtual Memory Nov 9, 2009"

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

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

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

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

ECE232: Hardware Organization and Design

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

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

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

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

Computer Architecture ELEC3441

Uniprocessors. HPC Prof. Robert van Engelen

Topic 18 (updated): Virtual Memory

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

Virtual to physical address translation

CS 153 Design of Operating Systems Winter 2016

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

CMSC Computer Architecture Lecture 5: Pipelining. Prof. Yanjing Li University of Chicago

CSE 120 Principles of Operating Systems Spring 2017

COMPUTER ORGANIZATION AND DESIGN

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5. Large and Fast: Exploiting Memory Hierarchy

UNIVERSITY OF MORATUWA

Virtual Memory Review. Page faults. Paging system summary (so far)

CSE 120 Principles of Operating Systems

Threads and Concurrency in Java: Part 1

Python Programming: An Introduction to Computer Science

Threads and Concurrency in Java: Part 1

FAST BIT-REVERSALS ON UNIPROCESSORS AND SHARED-MEMORY MULTIPROCESSORS

Recall: What is an operating system? Very Brief History of OS. Very Brief History of OS. CS162 Operating Systems and Systems Programming Lecture 2

CS 318 Principles of Operating Systems

End Semester Examination CSE, III Yr. (I Sem), 30002: Computer Organization

Isn t It Time You Got Faster, Quicker?

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

Virtual Memory. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Computers and Scientific Thinking

Lecture 19: Virtual Memory: Concepts

Computer Structure. X86 Virtual Memory and TLB

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

Avid Interplay Bundle

Virtual Memory. Computer Systems Principles

CSE 351. Virtual Memory

Goals of the Lecture UML Implementation Diagrams

% Sun Logo for. X3T10/95-229, Revision 0. April 18, 1998

Architectural styles for software systems The client-server style

Computer Systems. Virtual Memory. Han, Hwansoo

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

Module Instantiation. Finite State Machines. Two Types of FSMs. Finite State Machines. Given submodule mux32two: Instantiation of mux32two

A Few Problems with Physical Addressing. Virtual Memory Process Abstraction, Part 2: Private Address Space

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Virtual Memory. CS 3410 Computer System Organization & Programming. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

Transcription:

CMSC 22200 Computer Architecture Lecture 12: Virtual Memory Prof. Yajig Li Uiversity of Chicago

A System with Physical Memory Oly Examples: most Cray machies early PCs Memory early all embedded systems Physical Addresses 0: 1: CPU CPU s load or store addresses used directly to access memory N-1: 2

Difficulties of Direct Physical Addressig Programmer eeds to maage physical memory space Icoveiet & hard, especially with multiple processes Difficult to support code ad data relocatio Processes come ad go; fragmetatio issues How to provide protectio & isolatio? How to support data/code sharig across processes? Also, ISA ca have a address space greater tha the physical memory size E.g., a 64-bit address space with byte addressability What if you do ot have eough physical memory? 3

Abstractio: Virtual vs. Physical Memory Programmer sees virtual memory Ca assume the memory is private ad very large Reality: Physical memory size is much smaller tha what the programmer assumes ad ca be shared The system (system software + hardware, cooperatively) maps virtual memory addresses to physical memory The system automatically maages the physical memory space trasparetly to the programmer 4

Virtual Memory: Basic Mechaism Idea: Idirectio (i addressig) Address geerated by each istructio i a program is a virtual address i.e., it is ot the physical address used to address mai memory A address traslatio mechaism maps virtual address to a physical address The hardware coverts virtual addresses ito physical addresses via a OS-maaged lookup table (page table) Reuires Hardware + Software support! 5

Virtual Pages, Physical Frames Virtual address space divided ito pages Physical address space divided ito frames A virtual page is mapped to A physical frame, if the page is i physical memory A locatio i disk, otherwise If a accessed virtual page is ot i memory, but o disk Geerates page fault Virtual memory system brigs the page ito a physical frame ad adjusts the mappig à called demad pagig Page table: mappig of virtual pages to physical frames 6

Page Size What is the graularity of maagemet of physical memory? Specified by the ISA Today: 4KB, 8KB, 4MB, 2GB, Small ad large pages mixed together Large vs. small pages: may tradeoffs Size of the Page Table Number of page faults Trasfer overhead from disk to memory Iteral fragmetatio 7

A System with Virtual Memory Memory Virtual Addresses Page Table 0: 1: Physical Addresses 0: 1: CPU P-1: N-1: Disk Physical memory is a cache for pages stored o disk I fact, it is a fully associative cache i moder systems (a virtual page ca be mapped to ay physical frame) 8

Beefits of Virtual Memory Automatic maagemet Programmer does ot eed to kow the physical size of memory or maage it à A small physical memory ca appear as a huge oe to the programmer à Life is easier for the programmer Each process has its ow mappig from virtual à physical addresses, which eables Code ad data to be located aywhere i physical memory (efficiet use of physical memory) Isolatio/separatio of code ad data of differet processes i physical processes (protectio ad isolatio) Code ad data sharig betwee multiple processes (sharig) 9

Page Tables ad Address Traslatio

Virtual to Physical Address Traslatio Parameters P = 2 p = page size (bytes) N = 2 = Virtual-address limit M = 2 m = Physical-address limit 1 p p 1 0 virtual page umber, VPN page offset virtual address address traslatio m 1 p p 1 0 physical frame umber, PFN page offset physical address Page offset bits do t chage as a result of traslatio 11

Address Traslatio Usig Page Table Page Table cotais a etry for each virtual page Called Page Table Etry (PTE) What is i a PTE? A valid bit à to idicate validity/presece i physical memory PFN for the correspodig VPN à to support traslatio Cotrol bits to support replacemet Dirty bit idicate if we eed to write back Protectio bits to eable access cotrol ad protectio 12

Page Table is Per Process Each process has its ow virtual address space Illusio of full address space for each program Simplifies memory allocatio ad sharig Which table to use is idicated by the page table base register (PTBR) Virtual Address Space for Process 1: Virtual Address Space for Process 2: 0 N-1 0 VP 1 VP 2... VP 1 VP 2... Address Traslatio N-1 M-1 0 PP 2 PP 7 PP 10 Physical Address Space (DRAM) (e.g., read/oly library code) 13

Page Table Access Page Table Base Register (PTBR, CR3 i x86) Specifies the address of the page table Must cotai a physical address! PTBR is part of a process s cotext Just like PC, status registers, geeral purpose registers Needs to be loaded whe the process is cotext-switched i 14

Address Traslatio Illustrated Separate (set of) page table(s) per process VPN is used to idex ito page table (poits to a page table etry) Page Table Etry (PTE) provides iformatio about page page table base register (per process) virtual address 1 p p 1 0 virtual page umber (VPN) page offset valid physical frame umber (PFN) VPN acts as table idex if valid=0 the page ot i memory (page fault) m 1 p p 1 physical frame umber (PFN) physical address page offset 0 15

Page Table Eables Memory Protectio à Virtual memory system serves two fuctios Address traslatio (for illusio of large physical memory) Access cotrol (protectio) Not every process is allowed to access every page E.g., OS code ad data structures should be accessible by system software oly, i.e., reuire supervisor level privilege to access Idea: Store access cotrol iformatio o a page basis i the process s page table Eforce access cotrol at the same time as traslatio 16

Access Cotrol Type of access Read, write, execute Privilege level Defied by ISA, e.g., supervisor vs. user PTE cotais protectio bits which specify which accesses ca be made to this page at what privilege level Check bits o each access If violated, geerate exceptio (Access Protectio exceptio) What type of access is reuested? Privilege level of the ruig process Protectio bits i PTE Access Cotrol Logic Access allowed? 17

Memory Access Cotrol Bits i Page Tables Page Tables Memory Process i: VP 0: VP 1: Read? Write? Yes Yes No Yes Physical Addr PP 6 PP 4 PP 0 PP 2 VP 2: No No XXXXXXX PP 4 PP 6 Process j: VP 0: VP 1: VP 2: Read? Write? Yes Yes No Yes No No Physical Addr PP 6 PP 9 XXXXXXX PP 8 PP 10 PP 12 18

Virtual Memory Maagemet Mechaism

Both HW ad SW Support Reuired Page tables are located i memory, maaged by OS Hardware utilizes the iformatio i page table to perform fast address traslatio The hardware compoet is called the MMU (memory maagemet uit) 20

System Software (OS) Jobs for VM Keepig track of which physical frames are free Populate page table by allocatig free physical frames to virtual pages (o demad) Implemet page replacemet policy Whe o physical frame is free, what should be swapped out? Chage page tables o cotext switch To use the ruig thread s page table Hadle page faults Implemet other VM tricks Sharig pages betwee processes (e.g., shared libraries) Copy-o-write ad other optimizatios 21

Hardware Jobs for VM Address Traslatio (Page Hit) 22

HW ad SW: Page Fault Hadlig Note: page-fault hader routie is implemeted by the OS 23

I/O Operatio i Page Fault Hadler (1) Processor sigals cotroller Read block of legth P startig at disk address X ad store startig at memory address Y Processor Reg (1) Iitiate Block Read (3) Read Doe (2) Read occurs Direct Memory Access (DMA) by I/O cotroller CPU are free to ru other programs (3) I/O Cotroller sigals completio Iterrupt processor OS resumes suspeded process Cache Memory-I/O bus Memory (2) DMA Trasfer I/O cotroller Disk Disk 24

Page Fault ( A Miss i Physical Memory ) Resolved Before fault Memory After fault Memory CPU Virtual Addresses Page Table Physical Addresses CPU Virtual Addresses Page Table Physical Addresses Disk Disk

Virtual Memory System Desig Cosideratios

Three Major Issues I. How large is the page table ad how do we store ad access it? II. How ca we speed up traslatio & access cotrol check? III. Virtual memory ad cache iteractio 27

Page Table Size 64-bit VPN PO 52-bit 12-bit page table 28-bit cocat 40-bit PA 64-bit VA, 40-bit PA, 4KB pages à how large is the page table? 2 52 etries x ~4 bytes» 16PetaBytes Ad that is for just oe process! Page table too large to fit i physical memory!! 28

Solutio: Multi-Level Page Tables Example from x86 architecture 10 10 12 The process may ot be usig the etire VM space! Oly the first-level page table has to be i physical memory Remaiig levels are i virtual memory (but get cached i physical memory whe accessed) 29

Multi-Level Page Protectio X86 Example 30

Virtual Memory Issue II How fast do we eed the address traslatio to be? How ca we make it fast? Idea: Use a hardware structure that caches PTEs à Traslatio lookaside buffer (TLB) 31

Speedig up Traslatio with a TLB Essetially a small cache of recet address traslatios Avoids goig to the page table o every referece What happes o cotext switch? Idex = lower bits of VPN Tag = uused bits of VPN (+ process ID sometimes) Data = a page-table etry Status = valid, dirty The usual cache desig choices (associativity, replacemet policy, multi-level, etc.) all apply to TLB. 32

TLB Examples Typical umbers: 16 512 PTEs, 0.5 1 cycle for hit, 10 100 cycles for miss, 0.01% 1% miss rate

TLB Misses The TLB is small; it caot hold all PTEs Some traslatios will ievitably miss i the TLB TLB miss idicates Page preset, but PTE ot i TLB Page ot preset O TLB miss, access memory to fid the appropriate PTE Called walkig the page directory/table Large performace pealty Who hadles TLB misses? Hardware or software?

Hadlig TLB Misses Approach #1. Hardware-Maaged (e.g., x86) The hardware does the page walk The hardware fetches the PTE ad iserts it ito the TLB If the TLB is full, the etry replaces aother etry based o replacemet policy Doe trasparetly to system software Approach #2. Software-Maaged (e.g., MIPS) The hardware raises a exceptio The operatig system does the page walk The operatig system fetches the PTE The operatig system iserts/evicts etries i the TLB

Tradeoffs Hardware-Maaged TLB Pro: No exceptio o TLB miss. Istructio simply waits Pro: Idepedet istructios may cotiue Pro: No extra istructios/data brought ito caches Co: Page directory/table orgaizatio is etched ito the system: OS has little flexibility Software-Maaged TLB Pro: The OS ca defie page table/directory orgaizatio Pro: More sophisticated TLB replacemet policies are possible Co: Need to geerate a exceptio à performace overhead due to pipelie flush, exceptio hadler executio, extra istructios brought to caches