Another View of the Memory Hierarchy. Lecture #25 Virtual Memory I Memory Hierarchy Requirements. Memory Hierarchy Requirements

Similar documents
Memory Hierarchy Requirements. Three Advantages of Virtual Memory

UC Berkeley CS61C : Machine Structures

CS61C : Machine Structures

UC Berkeley CS61C : Machine Structures

Review. Manage memory to disk? Treat as cache. Lecture #26 Virtual Memory II & I/O Intro

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

UCB CS61C : Machine Structures

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

CS61C : Machine Structures

CS 61C: Great Ideas in Computer Architecture. Multiple Instruction Issue, Virtual Memory Introduction

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

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

CS 61C: Great Ideas in Computer Architecture. Virtual Memory III. Instructor: Dan Garcia

Saeid Nooshabadi. Overview. Page Table... COMP Translation Lookaside Buffer (TLB) Microprocessors and Embedded Systems

John Wawrzynek & Nick Weaver

ECE4680 Computer Organization and Architecture. Virtual Memory

Virtual Memory. Virtual Memory

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

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

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

ECE468 Computer Organization and Architecture. Virtual Memory

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Computer Systems. Virtual Memory. Han, Hwansoo

Virtual Memory Oct. 29, 2002

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

CS61C : Machine Structures

virtual memory Page 1 CSE 361S Disk Disk

CS61C : Machine Structures

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

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

Handout 4 Memory Hierarchy

CS 153 Design of Operating Systems Winter 2016

COSC 6385 Computer Architecture. - Memory Hierarchies (I)

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

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

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

CS61C : Machine Structures

CSE 560 Computer Systems Architecture

CSE 153 Design of Operating Systems

Virtual Memory - Objectives

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

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

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

ECE331: Hardware Organization and Design

CS61C Review of Cache/VM/TLB. Lecture 26. April 30, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)

CS152 Computer Architecture and Engineering Lecture 18: Virtual Memory

Processes and Virtual Memory Concepts

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

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

Chapter 8. Virtual Memory

Direct-Mapped Cache Terminology. Caching Terminology. TIO Dan s great cache mnemonic. Accessing data in a direct mapped cache

Virtual Memory Nov 9, 2009"

Virtual Memory II CSE 351 Spring

Carnegie Mellon. 16 th Lecture, Mar. 20, Instructors: Todd C. Mowry & Anthony Rowe

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

UC Berkeley CS61C : Machine Structures

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

Lecture 19: Virtual Memory: Concepts

Virtual Memory: From Address Translation to Demand Paging

Address spaces and memory management

14 May 2012 Virtual Memory. Definition: A process is an instance of a running program

Memory Hierarchy. Mehran Rezaei

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

Performance! (1/latency)! 1000! 100! 10! Capacity Access Time Cost. CPU Registers 100s Bytes <10s ns. Cache K Bytes ns 1-0.

CISC 360. Virtual Memory Dec. 4, 2008

Virtual Memory: From Address Translation to Demand Paging

CPE 631 Lecture 08: Virtual Memory

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

Computer Science 146. Computer Architecture

CS61C : Machine Structures

Topic 18: Virtual Memory

CSE 120 Principles of Operating Systems

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

16 Sharing Main Memory Segmentation and Paging

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

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

VIRTUAL MEMORY II. Jo, Heeseung

Virtual Memory: Concepts

Modern Computer Architecture

Topic 18 (updated): Virtual Memory

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Intro to Virtual Memory

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Recap: Memory Management

This Unit: Main Memory. Virtual Memory. Virtual Memory. Other Uses of Virtual Memory

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

CS450/550 Operating Systems

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

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

Virtual Memory. Physical Addressing. Problem 2: Capacity. Problem 1: Memory Management 11/20/15

www-inst.eecs.berkeley.edu/~cs61c/

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

Lecture 15: Virtual Memory

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

15 Sharing Main Memory Segmentation and Paging

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

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

UCB CS61C : Machine Structures

Transcription:

CS61C L25 Virtual I (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #25 Virtual I 27-8-7 Scott Beamer, Instructor Another View of the Hierarchy Thus far{ Next: Virtual { Regs Instr. Operands Cache Blocks L2 Cache Blocks Disk Tape s Files Upper Level Faster Larger Lower Level CS61C L25 Virtual I (4) Hierarchy Requirements Hierarchy Requirements If Principle of Locality allows caches to offer (close to) speed of cache memory with size of DRAM memory, then recursively why not use at next level to give speed of DRAM memory, size of Disk memory? While we re at it, what other things do we need from our memory system? Allow multiple processes to simultaneously occupy memory and provide protection don t let one program read/write memory from another Address space give each program the illusion that it has its own private memory Suppose code starts at x4. But different processes have different code, both residing at the same. So each program has a different view of memory. CS61C L25 Virtual I (5) CS61C L25 Virtual I (6) Virtual Called Virtual Next level in the memory hierarchy: Provides program with illusion of a very large main memory: Working set of pages reside in main memory - others reside on disk. Also allows OS to share memory, protect programs from each other Today, more important for protection vs. just another level of memory hierarchy Each process thinks it has all the memory to itself (Historically, it predates caches) CS61C L25 Virtual I (7) Virtual to Address Translation Program operates in its virtual space Each program operates in its own virtual space; ~only program running Each is protected from the other OS can decide where each goes in memory Hardware (HW) provides virtual physical CS61C L25 Virtual I (8) virtual (inst. fetch load, store) HW physical (inst. fetch load, store) memory (incl. caches)

CS61C L25 Virtual I (9) Analogy Book title like virtual Library of Congress call number like physical Card catalogue like page table, from book title to call # On card for book, in local library vs. in another branch like valid bit indicating in main memory vs. on disk On card, available for 2-hour in library use (vs. 2-week checkout) like access rights Simple Example: Base and Bound Reg $base+ $bound $base User C User B User A OS CS61C L25 Virtual I (1) Enough space for User D, but discontinuous ( fragmentation problem ) Want: discontinuous Process size >> mem Addition not enough! use Indirection! Mapping Virtual to Divide into equal sized Virtual chunks (about 4 KB - 8 KB) Any chunk of Virtual Stack assigned to any chuck of ( page ) 64 MB Paging Organization (assume 1 KB pages) is unit Virtual Address of Address page page 1K 1K 124 page 1 1K Addr 124 page 1 1K Trans 248 page 2 1K 7168 page 7 1K MAP 31744 also unit of transfer from disk to physical memory page 31 Virtual 1K CS61C L25 Virtual I (11) CS61C L25 Virtual I (12) Virtual Mapping Function Cannot have simple function to predict arbitrary Use table lookup of s Number Offset Use table lookup ( Table ) for s: number is index Virtual Mapping Function Offset = Virtual Offset Number = Table[Virtual Number] (P.P.N. also called Frame ) CS61C L25 Virtual I (13) Address Mapping: Table Virtual Address: page no. offset Table Base Reg index into page table Table located in physical memory CS61C L25 Virtual I (14) Table V A.R. P. P. A. Val Access -id Rights Address. + Address

CS61C L25 Virtual I (15) Table A page table is an operating system structure which contains the of virtual es to physical locations There are several different ways, all up to the operating system, to keep this data around Each process running in the operating system has its own page table State of process is PC, all registers, plus page table OS changes page tables by changing contents of Table Base Register Requirements revisited Remember the motivation for VM: Sharing memory with protection Different physical pages can be allocated to different processes (sharing) A process can only touch pages in its own page table (protection) Separate spaces Since programs work only with virtual es, different programs can have different data/code at the same! What about the memory hierarchy? CS61C L25 Virtual I (16) Table Entry (PTE) Format Contains either Number or indication not in Main OS maps to disk if Not Valid (V = ) Table V A.R. P. P.N. Val Access -id Rights P.T.E. Number V A.R. P. P. N. If valid, also check if have permission to use page: Access Rights (A.R.) may be Read Only, Read/Write, Executable CS61C L25 Virtual I (17) Paging/Virtual Multiple Processes User A: Virtual Stack 64 MB A Table CS61C L25 Virtual I (18) B Table User B: Virtual Stack Comparing the 2 levels of hierarchy Cache version Block or Line Miss Block Size: 32-64B Virtual vers. Fault Size: 4K-8KB Placement: Fully Associative Direct Mapped, N-way Set Associative Replacement: LRU or Random Write Thru or Back Least Recently Used (LRU) Write Back Notes on Table Solves Fragmentation problem: all chunks same size, so all holes can be used OS must reserve Swap Space on disk for each process To grow a process, ask Operating System If unused pages, OS uses them first If not, OS swaps some old pages to disk (Least Recently Used to pick pages to swap) Each process has own Table Will add details, but Table is essence of Virtual CS61C L25 Virtual I (19) CS61C L25 Virtual I (2)

CS61C L25 Virtual I (21) Why would a process need to grow? ~ FFFF FFFF A program s hex space contains 4 regions: stack: local variables, grows downward heap: space requested for pointers via malloc() ; resizes dynamically, grows upward static data: variables declared outside main, does not grow or shrink code: loaded when program starts, does not change ~ hex stack heap static data code For now, OS somehow prevents accesses between stack and heap (gray hash lines). Virtual Problem #1 Map every 1 indirection via Table in memory per virtual 1 virtual memory accesses = 2 physical memory accesses SLOW! Observation: since locality in pages of data, there must be locality in virtual translations of those pages Since small is fast, why not use a small cache of virtual to physical translations to make translation fast? For historical reasons, cache is called a Translation Lookaside Buffer, or CS61C L25 Virtual I (22) Translation Look-Aside Buffers (s) s usually small, typically 128-256 entries Like any other cache, the can be direct mapped, set associative, or fully associative hit VA PA Processor Cache miss Lookup miss hit data Translation Main On miss, get page table entry from main memory Address Translation using Virtual Address VPN Tag INDEX Offset Data Cache Tag (Tag used just like in cache) Tag Tag Data Tag Data P. P. N. Number P. P. N. PPN Offset Address Tag INDEX Offset CS61C L25 Virtual I (23) CS61C L25 Virtual I (25) Typical Format What if not in? Dirty Ref Valid Access Tag # Rights just a cache on the page table s access time comparable to cache (much less than main memory access time) Dirty: since use write back, need to know whether or not to write page to disk when replaced Ref: Used to help calculate LRU on replacement Cleared by OS periodically, then checked to see if page was referenced CS61C L25 Virtual I (26) Option 1: Hardware checks page table and loads new Table Entry into Option 2: Hardware traps to OS, up to OS to decide what to do MIPS follows Option 2: Hardware knows nothing about page table CS61C L25 Virtual I (27)

CS61C L25 Virtual I (28) What if the data is on disk? We load the page off the disk into a free block of memory, using a DMA transfer (Direct Access special hardware support to avoid processor) Meantime we switch to some other process waiting to be run When the DMA is complete, we get an interrupt and update the process's page table So when we switch back to the task, the desired data will be in memory What if we don t have enough memory? We chose some other page belonging to a program and transfer it onto the disk if it is dirty If clean (disk copy is up-to-date), just overwrite that data in memory We chose the page to evict based on replacement policy (e.g., LRU) And update that program's page table to reflect the fact that its memory moved somewhere else If continuously swap between disk and memory, called Thrashing CS61C L25 Virtual I (29) Three Advantages of Virtual 1) Translation: Program can be given consistent view of memory, even though physical memory is scrambled Makes multiple processes reasonable Only the most important part of program ( Working Set ) must be in physical memory Contiguous structures (like stacks) use only as much physical memory as necessary yet still grow later Three Advantages of Virtual 2) Protection: Different processes protected from each other Different pages can be given special behavior (Read Only, Invisible to user programs, etc). Kernel data protected from User programs Very important for protection from malicious programs Far more viruses under Microsoft Windows Special Mode in processor ( Kernel mode ) allows processor to change page table/ 3) Sharing: Can map same physical page to multiple users ( Shared memory ) CS61C L25 Virtual I (3) CS61C L25 Virtual I (31) Peer Instruction And in conclusion A. Locality is important yet different for cache and virtual memory (VM): temporal locality for caches but spatial locality for VM B. Cache management is done by hardware (HW), page table management by the operating system (OS), but management is either by HW or OS C. VM helps both with security and cost ABC : FFF 1: FFT 2: FTF 3: FTT 4: TFF 5: TFT 6: TTF 7: TTT Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Table of s for each user vs. tag/data in cache is cache of Virtual addr trans Virtual allows protected sharing of memory between processes Spatial Locality means Working Set of s is all that must be in memory for process to run fairly well CS61C L25 Virtual I (32) CS61C L25 Virtual I (34)