Virtual memory. Hung-Wei Tseng

Similar documents
Virtual memory. Hung-Wei Tseng

Processor Design Pipelined Processor (II) Hung-Wei Tseng

Processor Design Pipelined Processor. Hung-Wei Tseng

cs470 - Computer Architecture 1 Spring 2002 Final Exam open books, open notes

COMP2611: Computer Organization. The Pipelined Processor

Virtual Memory. Virtual Memory

COMPUTER ORGANIZATION AND DESIGN

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

Chapter 4 The Processor 1. Chapter 4B. The Processor

ECE Sample Final Examination

Pipelined datapath Staging data. CS2504, Spring'2007 Dimitris Nikolopoulos

CS 465 Final Review. Fall 2017 Prof. Daniel Menasce

ECE260: Fundamentals of Computer Engineering

The Processor. Z. Jerry Shi Department of Computer Science and Engineering University of Connecticut. CSE3666: Introduction to Computer Architecture

ECS 154B Computer Architecture II Spring 2009

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

Virtual Memory, Address Translation

Do not start the test until instructed to do so!

ECE331: Hardware Organization and Design

Lecture 9 Pipeline and Cache

CS232 Final Exam May 5, 2001

CENG 3420 Lecture 06: Pipeline

ECE3055B Fall 2004 Computer Architecture and Operating Systems Final Exam Solution Dec 10, 2004

Perfect Student CS 343 Final Exam May 19, 2011 Student ID: 9999 Exam ID: 9636 Instructions Use pencil, if you have one. For multiple choice

Virtual Memory, Address Translation

Pipeline Data Hazards. Dealing With Data Hazards

ECE 2300 Digital Logic & Computer Organization. Caches

CPE 335 Computer Organization. Basic MIPS Pipelining Part I

Virtual Memory: From Address Translation to Demand Paging

Lecture 4: Review of MIPS. Instruction formats, impl. of control and datapath, pipelined impl.

EE557--FALL 1999 MIDTERM 1. Closed books, closed notes

14:332:331 Pipelined Datapath

Outline. A pipelined datapath Pipelined control Data hazards and forwarding Data hazards and stalls Branch (control) hazards Exception

EE557--FALL 1999 MAKE-UP MIDTERM 1. Closed books, closed notes

Computer Architecture CS372 Exam 3

ECE 313 Computer Organization FINAL EXAM December 14, This exam is open book and open notes. You have 2 hours.

Codeword[1] Codeword[0]

CSE Quiz 3 - Fall 2009

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

ECE331: Hardware Organization and Design

Virtual Memory: From Address Translation to Demand Paging

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

University of Jordan Computer Engineering Department CPE439: Computer Design Lab

DAT (cont d) Assume a page size of 256 bytes. physical addresses. Note: Virtual address (page #) is not stored, but is used as an index into the table

EECS 322 Computer Architecture Improving Memory Access: the Cache

Inside out of your computer memories (III) Hung-Wei Tseng

Learning to Play Well With Others

COEN-4730 Computer Architecture Lecture 3 Review of Caches and Virtual Memory

CSE 141 Computer Architecture Spring Lectures 17 Virtual Memory. Announcements Office Hour

MEMORY HIERARCHY BASICS. B649 Parallel Architectures and Programming

Pipelined processors and Hazards

ECE232: Hardware Organization and Design

Lecture 3: The Processor (Chapter 4 of textbook) Chapter 4.1

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

2-Level Page Tables. Virtual Address Space: 2 32 bytes. Offset or Displacement field in VA: 12 bits

Chapter 4. The Processor

Virtual Memory 3. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. P & H Chapter 5.4

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

CS232 Final Exam May 5, 2001

The Processor (3) Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Chapter 4 The Processor 1. Chapter 4A. The Processor

Lecture 9. Pipeline Hazards. Christos Kozyrakis Stanford University

Topic 18 (updated): Virtual Memory

VIRTUAL MEMORY II. Jo, Heeseung

THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY Computer Organization (COMP 2611) Spring Semester, 2014 Final Examination

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

Pipelining. Ideal speedup is number of stages in the pipeline. Do we achieve this? 2. Improve performance by increasing instruction throughput ...

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

Pipeline Hazards. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Computer and Information Sciences College / Computer Science Department Enhancing Performance with Pipelining

LECTURE 9. Pipeline Hazards

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

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

COSC3330 Computer Architecture Lecture 20. Virtual Memory

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner

ECE260: Fundamentals of Computer Engineering

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

data block 0, word 0 block 0, word 1 block 1, word 0 block 1, word 1 block 2, word 0 block 2, word 1 block 3, word 0 block 3, word 1 Word index cache

Department of Computer and IT Engineering University of Kurdistan. Computer Architecture Pipelining. By: Dr. Alireza Abdollahpouri

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

Computer Structure. X86 Virtual Memory and TLB

ADDRESS TRANSLATION AND TLB

Spring 2016 :: CSE 502 Computer Architecture. Caches. Nima Honarmand

Address Translation. Tore Larsen Material developed by: Kai Li, Princeton University

ADDRESS TRANSLATION AND TLB

Caches (Writing) P & H Chapter 5.2 3, 5.5. Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

CISC 662 Graduate Computer Architecture Lecture 16 - Cache and virtual memory review

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

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

ECE 2300 Digital Logic & Computer Organization. More Caches Measuring Performance

Chapter 4. The Processor

Design a MIPS Processor (2/2)

Computer Architecture Computer Science & Engineering. Chapter 4. The Processor BK TP.HCM

John Wawrzynek & Nick Weaver

Topic 18: Virtual Memory

Virtual Memory - Objectives

Translation Buffers (TLB s)

COMPUTER ORGANIZATION AND DESIGN

Transcription:

Virtual memory Hung-Wei Tseng

Why virtual memory How VM works VM and cache Outline 4

Virtual memory 5

Scenario I An application is design on machine A with memory size X. Can we safely execute the same application on another machine B with memory size Y? physical memory of machine A Application physical memory of machine B? 6

Scenario II Both application A and application B would like to use the same machine Each application should not touch data of the other. This is called protection in OS Application A Physical memory of the machine Application B 7

Why Virtual Memory? Every process runs on virtual memory space Process: a running program in the operating system virtual memory memory. Physical memory caches memory pages from Single program can exceed the size of physical Multiple processes can share a single main memory. virtual address space of program A virtual address space of program B 8

Memory Hierarchy Fastest, Most Expensive CPU $ Main Memory Secondary Storage Main memory is a cache for Virtual Memory A: Fully Associative B: page size! S: (Since it s FA) Replacement policies? LRU, random... Operating system manages the mapping between physical and virtual VM addresses Biggest 9

How VM works

Virtual memory An abstraction of memory space available for programs/software/programmer Programs execute using virtual memory address The operating system and hardware work together to handle the mapping between virtual memory addresses and real/physical memory addresses

Address translation Processor uses virtual addresses, main memory uses physical memory addresses Virtual address space is organized into pages The system references the page table to translate addresses each process has its own page table the page table content is maintained by OS VA: valid virtual page # offset PA: physical page # offset 2

Hierarchical page table Break the virtual page number into several pieces If one piece has N bits, build an 2N -ary tree Only store the part of the tree that contain valid pages valid Walk down the tree to translate the virtual address level index level 2 index offset physical page # offset 4

Hierarchical page table valid 5

Page fault When the referenced memory page is not mapped to physical memory The processor raises an exception and transfers the control (change the PC) to operating system code that handles the page fault LRU or other page replacement policies to decide the evicting page Fetch the demanding page from secondary storage (hard drive, SSD) Transfer the control back to the original program Could be slow! The access time of hard drive is more than 6ms 6

PC Pipeline with exception PCWrite PCSrc m ux IF/IDWrite hazard detection unit IF/ID ID/EX EX/MEM MEM/WB Control m ux ID/EX.MemRead WB ME EX m ux m ux WB ME WB RegWrite 4 Add Shi> le> 2 Add RegWrite Cause EPC MemWrite Read Address Instruc(on Memory inst[3:] inst[5:] inst[25:2] inst[2:6] 6 Read Reg Register Read Reg 2 File Write Reg Write Data signextend 32 Read Data Read Data 2 m ux ForwardA m ux RegDst ForwardB m ux Zero ALU ALUop Address Write Data Data Memory MemRead Read Data MemtoReg m ux ForwardA ForwardB forwarding unit ALUSrc 7

VM & Cache 9

Cache + Virtual Memory Processor Processor. VA $ PA 3. 2. PA Too slow! main memory 5 ns+ lantency TLB: Translation Look-aside Buffer a cache of page table small, high-associativity miss penalty: access to page table in main memory $. VA TLB 2. PA TLB increase the hit time! main memory 2

Cache+Virtual Memory Processor Virtual Cache The cache also uses virtual addresses Address translation is required only when miss.. VA TLB $. VA 2. PA main memory 2

Problems of Virtual Cache Multiple processes accessing to the same virtual address Process A accessed x. Process B also want to access x Flush the cache when context switch Attach PID to cache virtual addresses of A x huge overhead in multiprogrammed systems increase hardware costs virtual addresses of B? x cache x 22

Problems of Virtual Cache Alias: A physical address maps to different virtual addresses Two copies of data in cache due to copy on write. One may get the wrong data if the other is modified. virtual address x x3 cache x x3 physical address xff also points to xff 23

Virtually indexed, physically tagged cache. VA 2. PA TLB Processor = miss $ main memory. VA 2. PA Force aliasing virtual addresses mapped to the same cache location. The cache uses the index field to place data blocks Page offset remains the same in virtual and physical addresses index field must be inside the page offset to guarantee that aliasing are mapped to the same place Cache stores tag fields of physical addresses 24

Virtually indexed, physically tagged cache page number page offset tag index offset memory address: # of bits in page offset == # bits in index and offset TLB virtual page # physical page # valid dirty tag Cache array data C = ABS lg(s)+lg(b) = 2 =? if A = (DM cache) C = *(2 2 ) = 4KB Stores the tag of physical addresses, which is also the physical page #! hit? miss? 25

Virtually indexed, physically tagged cache Force aliasing virtual addresses mapped to the same cache location. Cache stores tag fields of physical addresses the physical tag is also the physical page number! virtual page # TLB physical page # page offset $ index+block offset physical tag == physical page # C = ABS lg(s)+lg(b) = 2 if A = (DM cache) C = *(2 2 ) = 4KB physical page # offset 29

9 bits index, 6 bits offset AMD Phenom II 64KB D-L cache, 64B block, 2-way associative. Windows 7 has 4KB page size Page offset 2 bits How to achieve virtually indexed, physically tagged? Check a total of 8 possible location. Invalid all aliasing blocks and fetch new from low level hierarchy. 3