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

Similar documents
Virtual Memory Oct. 29, 2002

CISC 360. Virtual Memory Dec. 4, 2008

virtual memory Page 1 CSE 361S Disk Disk

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

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

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

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

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

Virtual Memory Nov 9, 2009"

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

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

Computer Systems. Virtual Memory. Han, Hwansoo

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

Processes and Virtual Memory Concepts

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

CSE 560 Computer Systems Architecture

CSE 153 Design of Operating Systems

Virtual Memory. Alan L. Cox Some slides adapted from CMU slides

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Topic 18: Virtual Memory

This lecture. Virtual Memory. Virtual memory (VM) CS Instructor: Sanjeev Se(a

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

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

Virtual Memory: Concepts

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

University of Washington Virtual memory (VM)

Virtual Memory: Concepts

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

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

EE108B Lecture 13. Caches Wrap Up Processes, Interrupts, and Exceptions. Christos Kozyrakis Stanford University

Pentium/Linux Memory System March 17, 2005

Announcements. EE108B Lecture 13. Caches Wrap Up Processes, Interrupts, and Exceptions. Measuring Performance. Memory Performance

CS 261 Fall Mike Lam, Professor. Virtual Memory

Memory System Case Studies Oct. 13, 2008

18-447: Computer Architecture Lecture 16: Virtual Memory

VM as a cache for disk

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

Lecture 19: Virtual Memory: Concepts

Virtual Memory II CSE 351 Spring

P6/Linux Memory System Nov 11, 2009"

Virtual Memory: Systems

Topic 18 (updated): Virtual Memory

Foundations of Computer Systems

CSE 351. Virtual Memory

Understanding the Design of Virtual Memory. Zhiqiang Lin

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Virtual Memory. Samira Khan Apr 27, 2017

Virtual Memory: Concepts

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

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

Virtual Memory. Computer Systems Principles

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

CSE 120 Principles of Operating Systems

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

Virtual Memory: From Address Translation to Demand Paging

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

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

Computer Architecture. Lecture 8: Virtual Memory

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

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

Virtual Memory: From Address Translation to Demand Paging

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

CS 153 Design of Operating Systems

Intel P6 (Bob Colwell s Chip, CMU Alumni) The course that gives CMU its Zip! Memory System Case Studies November 7, 2007.

ECE4680 Computer Organization and Architecture. Virtual Memory

Intel P The course that gives CMU its Zip! P6/Linux Memory System November 1, P6 memory system. Review of abbreviations

CS 153 Design of Operating Systems

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

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

CIS Operating Systems Memory Management Cache and Demand Paging. Professor Qiang Zeng Spring 2018

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

ECE468 Computer Organization and Architecture. Virtual Memory

Chapter 8. Virtual Memory

Virtual Memory. Virtual Memory

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

CSE 120 Principles of Operating Systems Spring 2017

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

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

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

Memory Management! Goals of this Lecture!

Virtual Memory. CS 351: Systems Programming Michael Saelee

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2017

Virtual Memory. CS 3410 Computer System Organization & Programming

Translation Buffers (TLB s)

The memory of a program. Paging and Virtual Memory. Swapping. Paging. Physical to logical address mapping. Memory management: Review

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

Virtual Memory I. CSE 351 Spring Instructor: Ruth Anderson

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

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Virtual Memory: Systems

VIRTUAL MEMORY: CONCEPTS

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

CS 153 Design of Operating Systems Winter 2016

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

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

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

Handout 4 Memory Hierarchy

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

COS 318: Operating Systems. Virtual Memory and Address Translation

Transcription:

class8.ppt 5-23 The course that gives CMU its Zip! Virtual Oct. 29, 22 Topics Motivations for VM Address translation Accelerating translation with TLBs Motivations for Virtual Use Physical DRAM as a Cache for the Disk Address space of a process can exceed physical memory size Sum of address spaces of multiple processes can exceed physical memory Simplify Management Multiple processes resident in main memory. Each process with its own address space Only active code and data is actually in memory Allocate more memory to process as needed. Provide Protection One process can t interfere with another. because they operate in different address spaces. User process cannot access privileged information different sections of address spaces have different permissions. 2 5-23, S 3 Why VM Works? Motivation #: DRAM a Cache for Disk Full address space is quite large: 32-bit addresses: ~4,,, (4 billion) bytes 64-bit addresses: ~6,,,,,, (6 quintillion) bytes Disk storage is ~3X cheaper than DRAM storage 8 GB of DRAM: ~ $33, 8 GB of disk: ~ $ To access large amounts of data in a cost-effective manner, the bulk of the data must be stored on disk 4 MB: ~$5 SRAM GB: ~$2 DRAM 8 GB: ~$ Disk 3 5-23, S 3 4 5-23, S 3

Levels in Hierarchy DRAM vs. SRAM as a Cache size: speed: $/Mbyte: line size: regs 32 B ns 8 B cache 8 B C a c h e 32 B 4 KB disk disk Register Cache Disk 32 KB-4MB 2 ns $25/MB 32 B 24 MB 3 ns $.2/MB 4 KB virtual memory GB 8 ms $./MB DRAM vs. disk is more extreme than SRAM vs. DRAM Access latencies: DRAM ~X slower than SRAM Disk ~,X slower than DRAM Importance of exploiting spatial locality: First byte is ~,X slower than successive bytes on disk» vs. ~4X improvement for page-mode vs. regular accesses to DRAM Bottom line: Design decisions made for DRAM caches driven by enormous cost of misses larger, slower, cheaper SRAM DRAM Disk 5 5-23, S 3 6 5-23, S 3 Impact of Properties on Design If DRAM was to be organized similar to an SRAM cache, how would we set the following design parameters? Line size? Large, since disk better at transferring large blocks Associativity? High, to mimimize miss rate Write through or write back? Write back, since can t afford to perform small writes to disk What would the impact of these choices be on: miss rate Extremely low. << % hit time Must match cache/dram performance miss latency Very high. ~2ms tag storage overhead Low, relative to block size 7 5-23, S 3 Locating an Object in a Cache SRAM Cache stored with cache line Maps from cache block to memory blocks From cached to uncached form Save a few bits by only storing tag tag for block not in cache Hardware retrieves information can quickly match against multiple tags Cache Object Name X = X? 8 5-23, S 3 : : N-: Data D 243 X 7 J 5

Locating an Object in Cache (cont.) DRAM Cache Each allocated page of virtual memory has entry in page table Mapping from virtual pages to physical pages From uncached form to cached form Page table entry even if page not in memory Specifies disk address Only way to indicate where to find page OS retrieves information Object Name X D: Page Table Location J: On Disk X: Data 9 5-23, S 3 : : N-: Cache 243 7 5 A System with Physical Only Examples: most Cray machines, early PCs, nearly all embedded systems, etc. Physical generated by the correspond directly to bytes in physical memory 5-23, S 3 : : N-: A System with Virtual Examples: workstations, servers, modern PCs, etc. Virtual Page Table : : P-: Physical Disk Address Translation: Hardware converts es to physical addresses via OS-managed lookup table (page table) 5-23, S 3 : : N-: Page Faults (like Cache Misses ) What if an object is on disk rather than in memory? Page table entry indicates not in memory OS exception handler invoked to move data from disk into memory current process suspends, others can resume OS has full control over placement, etc. Virtual Before fault Page Table Physical Disk 2 5-23, S 3 Virtual After fault Page Table Physical Disk

Servicing a Page Fault Processor Signals Controller Read block of length P starting at disk address X and store starting at memory address Y Read Occurs Direct Access (DMA) Under control of I/O controller I / O Controller Signals Completion Interrupt processor OS resumes suspended process Processor Reg Cache Cache () Initiate Block Read (3) Read Done -I/O bus bus (2) DMA Transfer I/O I/O controller disk Disk disk Disk 3 5-23, S 3 Motivation #2: Management Multiple processes can reside in physical memory. How do we resolve address conflicts? what if two processes access something at the same address? Linux/x86 process memory image %esp kernel virtual memory stack mapped region forshared libraries runtime heap (via malloc) uninitialized data (.bss) initialized data (.data) program text (.text) forbidden memory invisible to user code the brk ptr 4 5-23, S 3 Solution: Separate Virt. Addr. Spaces Virtual and physical address spaces divided into equal-sized blocks blocks are called pages (both virtual and physical) Each process has its own space operating system controls how virtual pages as assigned to physical memory Virtual Address Space for Process : Virtual Address Space for Process 2: N- N- VP VP 2... VP VP 2... Address Translation Physical Address Space (DRAM) 5 5-23, S 3 M- PP 2 PP 7 PP (e.g., read/only library code) Contrast: Macintosh Model MAC OS 9 Does not use traditional virtual memory Shared Address Space P Pointer Table Process P Handles Process P2 P2 Pointer Table All program objects accessed through handles Indirect reference through pointer table Objects stored in shared global address space 6 5-23, S 3 A B C D E

Macintosh Management Allocation / Deallocation Similar to free-list management of malloc/free Compaction Can move any object and just update the (unique) pointer in pointer table Shared Address Space P Pointer Table B Process P A Handles P2 Pointer Table C Process P2 D E 7 5-23, S 3 Mac vs. VM-Based Mgmt Allocating, deallocating, and moving memory: can be accomplished by both techniques Block sizes: Mac: variable-sized may be very small or very large VM: fixed-size size is equal to one page (4KB on x86 Linux systems) Allocating contiguous chunks of memory: Mac: contiguous allocation is required VM: can map contiguous range of es to disjoint ranges of physical addresses Protection Mac: wild write by one process can corrupt another s data 8 5-23, S 3 Modern Operating System MAC OS X Virtual memory with protection Preemptive multitasking Other versions of MAC OS require processes to voluntarily relinquish control Based on MACH OS Developed at CMU in late 98 s Motivation #3: Protection Page table entry contains access rights information hardware enforces this protection (trap into OS if violation occurs) Process i: VP : VP : VP 2: Page Tables Read? Write? Physical Addr PP 9 PP 4 XXXXXXX : : Process j: VP : VP : Read? Write? Physical Addr PP 6 PP 9 N-: VP 2: XXXXXXX 9 5-23, S 3 2 5-23, S 3

VM Address Translation VM Address Translation: Hit Virtual Address Space V = {,,, N} Physical Address Space P = {,,, M} M < N Address Translation MAP: V P U { } For a: MAP(a) = a if data at a at physical address a in P MAP(a) = if data at a not in physical memory» Either invalid or stored on disk Processor a Hardware Addr Trans Mechanism a' Main part of the physical address on-chip memory mgmt unit (MMU) 2 5-23, S 3 22 5-23, S 3 VM Address Translation: Miss Processor a Hardware Addr Trans Mechanism a' page fault fault handler Main part of the physical address on-chip memory mgmt unit (MMU) Secondary memory OS performs this transfer (only if miss) VM Address Translation Parameters P = 2 p = page size (bytes). N = 2 n = Virtual address limit M = 2 m = Physical address limit n p p virtual page number address translation m p p physical page number physical address Page offset bits don t change as a result of translation 23 5-23, S 3 24 5-23, S 3

Page Tables Virtual Page Number resident page table (physical page or disk address) Physical Disk Storage (swap file or regular file system file) Address Translation via Page Table page table base register acts as table index if valid= then page not in memory n p p virtual page number () m physical page number () p p physical address valid access physical page number () 25 5-23, S 3 26 5-23, S 3 Page Table Operation Translation Separate (set of) page table(s) per process forms index into page table (points to a page table entry) page table base register acts as table index n p p virtual page number () valid access physical page number () Page Table Operation Computing Physical Address Page Table Entry (PTE) provides information about page if (valid bit = ) then the page is in memory.» Use physical page number () to construct address if (valid bit = ) then the page is on disk» Page fault page table base register acts as table index n p p virtual page number () valid access physical page number () if valid= then page not in memory m p p physical page number () physical address if valid= then page not in memory m p p physical page number () 27 5-23, S 3 physical address 28 5-23, S 3

Page Table Operation Checking Protection Access rights field indicate allowable access e.g., read-only, read-write, execute-only typically support multiple protection modes (e.g., kernel vs. user) Protection violation fault if user doesn t have necessary permission page table base register acts as table index if valid= then page not in memory n p p virtual page number () valid access physical page number () m p p physical page number () 29 physical address 5-23, S 3 Integrating VM and Cache VA PA miss Translation Cache data hit Main Most Caches were Physically Addressed Accessed by physical addresses Allows multiple processes to have blocks in cache at same time Allows multiple processes to share pages Cache doesn t need to be concerned with protection issues Access rights checked as part of address translation Perform Address Translation Before Cache Lookup But this could involve a memory access itself (of the PTE) Of course, page table entries can also become cached 3 5-23, S 3 Speeding up Translation with a TLB Address Translation with a TLB Translation Lookaside Buffer (TLB) Small hardware cache in MMU Maps virtual page numbers to physical page numbers Contains complete page table entries for small number of pages hit VA PA miss TLB Lookup Cache miss Translation hit Main TLB hit valid n p p virtual page number tag physical page number... = physical address tag index valid tag data byte offset TLB Cache data cache hit = data 3 5-23, S 3 32 5-23, S 3

Simple System Example Simple System Page Table Addressing 4-bit es 2-bit physical address Page size = 64 bytes 3 2 9 8 7 6 5 4 3 2 VPO (Virtual Page Number) (Virtual Page Offset) 9 8 7 6 5 4 3 2 Only show first 6 entries 28 2 33 3 2 4 5 6 6 7 8 9 A B C D E F 3 7 9 2D D (Physical Page Number) PPO (Physical Page Offset) 33 5-23, S 3 34 5-23, S 3 Simple System TLB TLB 6 entries 4-way associative TLBT TLBI 3 2 9 8 7 6 5 4 3 2 Simple System Cache Cache 6 lines 4-byte line size Direct mapped CT CI CO 9 8 7 6 5 4 3 2 VPO PPO Set 2 3 3 3 2 7 2D 9 2 8 3 D D 4 6 A 34 7 A 3 2 2 Idx 2 3 4 5 6 7 9 5 B 36 32 D 3 6 B 99 43 36 B 2 6D 72 C2 B2 23 4 8F F DF B3 8 9 D 3 Idx 8 9 A B C D E F 24 2D 2D B 2 6 3 4 B 3A 93 4 83 B 5 96 77 B2 5 DA 34 B B3 89 3B 5 D3 35 5-23, S 3 36 5-23, S 3

Address Translation Example # Virtual Address x3d4 TLBT TLBI 3 2 9 8 7 6 5 4 3 2 Address Translation Example #2 Virtual Address xb8f TLBT TLBI 3 2 9 8 7 6 5 4 3 2 VPO VPO TLBI TLBT TLB Hit? Page Fault? : Physical Address CT CI CO 9 8 7 6 5 4 3 2 TLBI TLBT TLB Hit? Page Fault? : Physical Address CT CI CO 9 8 7 6 5 4 3 2 PPO PPO Offset CI CT Hit? Byte: Offset CI CT Hit? Byte: 37 5-23, S 3 38 5-23, S 3 Address Translation Example #3 Virtual Address x4 TLBT TLBI 3 2 9 8 7 6 5 4 3 2 VPO TLBI TLBT TLB Hit? Page Fault? : Physical Address CT CI CO 9 8 7 6 5 4 3 2 PPO Offset CI CT Hit? Byte: 39 5-23, S 3 Multi-Level Page Tables Given: 4KB (2 2 ) page size 32-bit address space 4-byte PTE Problem: Would need a 4 MB page table! 2 2 *4 bytes Common solution multi-level page tables e.g., 2-level table (P6) Level table: 24 entries, each of which points to a Level 2 page table. Level 2 table: 24 entries, each of which points to a page Level Table Level 2 Tables 4 5-23, S 3...

Main Themes Programmer s View Large flat address space Can allocate large blocks of contiguous addresses Processor owns machine Has private address space Unaffected by behavior of other processes System View User space created by mapping to set of pages Need not be contiguous Allocated dynamically Enforce protection during address translation OS manages many processes simultaneously Continually switching among processes Especially when one must wait for resource» E.g., disk I/O to handle page fault 4 5-23, S 3