Learning to Play Well With Others

Similar documents
Learning to Play Well With Others

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

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

Virtual Memory: From Address Translation to Demand Paging

COSC3330 Computer Architecture Lecture 20. Virtual Memory

John Wawrzynek & Nick Weaver

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

Virtual Memory, Address Translation

Virtual Memory, Address Translation

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual to physical address translation

Virtual Memory. CS 3410 Computer System Organization & Programming

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

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

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

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

Computer Science 146. Computer Architecture

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

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

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

ECE 571 Advanced Microprocessor-Based Design Lecture 12

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

Memory Management. Goals of Memory Management. Mechanism. Policies

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

Modern Virtual Memory Systems. Modern Virtual Memory Systems

Chapter 8 Virtual Memory

VIRTUAL MEMORY II. Jo, Heeseung

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

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

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

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

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

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

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

ECE 571 Advanced Microprocessor-Based Design Lecture 13

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

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

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

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

ECE 598 Advanced Operating Systems Lecture 14

Computer Structure. X86 Virtual Memory and TLB

Introduction to Paging

Virtual memory. Hung-Wei Tseng

Virtual Memory. Motivation:

Virtual memory. Hung-Wei Tseng

Lecture 9 - Virtual Memory

Virtual Memory. Samira Khan Apr 27, 2017

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

Chapter 8. Virtual Memory

ADDRESS TRANSLATION AND TLB

Virtual Memory. CS 351: Systems Programming Michael Saelee

Virtual Memory Overview

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

ADDRESS TRANSLATION AND TLB

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

CSE 153 Design of Operating Systems

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CS 537 Lecture 6 Fast Translation - TLBs

Virtual memory Paging

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

Memory Hierarchy. Mehran Rezaei

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

Virtual Memory II CSE 351 Spring

Computer Systems. Virtual Memory. Han, Hwansoo

Virtual Memory - Objectives

ECE331: Hardware Organization and Design

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

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

Main Memory (Fig. 7.13) Main Memory

EECS 482 Introduction to Operating Systems

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

Virtual Memory. Computer Systems Principles

Virtual Memory Nov 9, 2009"

Chapter 8 Memory Management

Goals of memory management

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

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

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

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

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

Virtual Memory Fall /19/0. L21 Virtual Memory 1

EN1640: Design of Computing Systems Topic 06: Memory System

Computer Architecture and Engineering. CS152 Quiz #3. March 18th, Professor Krste Asanovic. Name:

238P: Operating Systems. Lecture 5: Address translation. Anton Burtsev January, 2018

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

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

Topic 18 (updated): Virtual Memory

CS399 New Beginnings. Jonathan Walpole

Processes and Virtual Memory Concepts

ECE232: Hardware Organization and Design

Memory Management. Dr. Yingwu Zhu

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

143A: Principles of Operating Systems. Lecture 6: Address translation. Anton Burtsev January, 2017

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

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

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

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

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

CS 318 Principles of Operating Systems

Transcription:

Virtual Memory 1

Learning to Play Well With Others (Physical) Memory 0x10000 (64KB) 0x00000

Learning to Play Well With Others malloc(0x20000) (Physical) Memory 0x10000 (64KB) 0x00000

Learning to Play Well With Others malloc(0x20000) (Physical) Memory 0x10000 (64KB) 0x00000

Learning to Play Well With Others (Physical) Memory 0x10000 (64KB) 0x00000

Learning to Play Well With Others (Physical) Memory 0x10000 (64KB) 0x00000

Learning to Play Well With Others (Physical) Memory 0x10000 (64KB) 0x00000

Learning to Play Well With Others (Physical) Memory 0x10000 (64KB) 0x00000

Learning to Play Well With Others Virtual Memory 0x10000 (64KB) 0x00000 Virtual Memory 0x10000 (64KB) 0x00000

Learning to Play Well With Others Virtual Memory 0x10000 (64KB) Physical Memory 0x00000 0x10000 (64KB) Virtual Memory 0x10000 (64KB) 0x00000 0x00000

Learning to Play Well With Others Virtual Memory 0x10000 (64KB) Physical Memory 0x00000 0x10000 (64KB) Virtual Memory 0x10000 (64KB) 0x00000 0x00000

Learning to Play Well With Others Virtual Memory 0x400000 (4MB) Physical Memory 0x00000 0x10000 (64KB) Virtual Memory 0xF000000 (240MB) 0x00000 Disk (GBs) 0x00000

Mapping Virtual-to-physical mapping Virtual --> virtual address space physical --> physical address space We will break both address spaces up into pages Typically 4KB in size, although sometimes large Use a page table to map between virtual pages and physical pages. The processor generates virtual addresses They are translated via address translation into physical addresses. 6

The Mapping Process Virtual address (32 bits) Virtual Page Number Page Offset (log(page size)) Virtual-to-physical map Physical Page Number Page Offset (log(page size)) Physical address (32 bits) 7

Two Problems With VM How do we store the map compactly? How do we translation quickly? 8

How Big is the map? 32 bit address space: 4GB of virtual addresses 1MPages Each entry is 4 bytes (a 32 bit physical address) 4MB of map 64 bit address space 16 exabytes of virtual address space 4PetaPages Entry is 8 bytes 64PB of map 9

Shrinking the map Only store the entries that matter (i.e.,. enough for your physical address space) 64GB on a 64bit machine 16M pages, 128MB of map This is still pretty big. Representing the map is now hard because we need a sparse representation. The OS allocates stuff all over the place. For security, convenience, or caching optimizations For instance: The stack is at the top of memory. The heap is at the bottom How do you represent this sparse map? 10

Hierarchical Page Tables Break the virtual page number into several pieces If each piece has N bits, build an 2 N -ary tree Only store the part of the tree that contain valid pages To do translation, walk down the tree using the pieces to select with child to visit. 11

Hierarchical Page Table Virtual Address 31 22 21 12 11 p1 p2 offset 0 10-bit L1 index Root of the Current Page Table 10-bit L2 index p2 offset p1 (Processor Register) Level 1 Page Table Level 2 Page Tables Parts of the map that exist Parts that don t Data Pages

Making Translation Fast Address translation has to happen for every memory access This potentially puts it squarely on the critical for memory operation (which are already slow) 13

Solution 1 : Use the Page Table We could walk the page table on every memory access Result: every load or store requires an additional 3-4 loads to walk the page table. Unacceptable performance hit. 14

Solution 2: TLBs We have a large pile of data (i.e., the page table) and we want to access it very quickly (i.e., in one clock cycle) So, build a cache for the page mapping, but call it a translation lookaside buffer or TLB 15

TLBs TLBs are small (maybe 128 entries), highlyassociative (often fully-associative) caches for page table entries. This raises the possibility of a TLB miss, which can be expensive To make them cheaper, there are hardware page table walkers -- specialized state machines that can load page table entries into the TLB without OS intervention This means that the page table format is now part of the big-a architecture. Typically, the OS can disable the walker and implement its own format. 16

Solution 3: Defer translating Accesses If we translate before we go to the cache, we have a physical cache, since cache works on physical addresses. Critical path = TLB access time + Cache access time CPU VA TLB Physical Cache Primary Memory Alternately, we could translate after the cache Translation is only required on a miss. This is a virtual cache PA VA CPU Virtual Cache TLB PA Primary Memory 17

The Danger Of Virtual Caches (1) Process A is running. It issues a memory request to address 0x10000 It is a miss, and 0x10000 is brought into the virtual cache A context switch occurs Process B starts running. It issues a request to 0x10000 Will B get the right data? 18

The Danger Of Virtual Caches (1) Process A is running. It issues a memory request to address 0x10000 It is a miss, and 0x10000 is brought into the virtual cache A context switch occurs Process B starts running. It issues a request to 0x10000 Will B get the right data? No! We must flush virtual caches on a context switch. 18

The Danger Of Virtual Caches (2) There is no rule that says that each virtual address maps to a different physical address. When this occurs, it is called aliasing Example: An alias exists in the cache 0x1000 Page Table 0xfff0000 Address 0x1000 Cache Data A 0x2000 0xfff0000 0x2000 A Store B to 0x1000 Page Table 0x1000 0xfff0000 Cache Address Data 0x1000 B 0x2000 0xfff0000 Now, a load from 0x2000 will return the wrong value 0x2000 A 19

The Danger Of Virtual Caches (2) Why are aliases useful? Example: Copy on write char * A memcpy(a, B, 100000) char * A Virtual address space Physical address space Virtual address space Physical address space My Big Data By Big Empty Buffer memcpy(a, B, 100000) My Big Data char * B; char * B; My Empty Buffer My Big Data memcpy(a, B, 100000) Unwriteable copy My Big Data Adjusting the page table is much faster for large copies The initial copy is free, and the OS will catch attempts to write to the copy, and do the actual copy lazily. There are also system calls that let you do this arbitrarily. 20

The Danger Of Virtual Caches (2) Why are aliases useful? Example: Copy on write char * A memcpy(a, B, 100000) char * A Two virtual addresses pointing the same physical address Virtual address space Physical address space Virtual address space Physical address space My Big Data By Big Empty Buffer memcpy(a, B, 100000) My Big Data char * B; char * B; My Empty Buffer My Big Data memcpy(a, B, 100000) Unwriteable copy My Big Data Adjusting the page table is much faster for large copies The initial copy is free, and the OS will catch attempts to write to the copy, and do the actual copy lazily. There are also system calls that let you do this arbitrarily. 20

Avoiding Aliases If the system has virtual caches, the operating system must prevent alias from occurring in the cache This means that any addresses that may alias must map to the same cache index. If VA1 and VA2 are aliases, VA1 mod (cache size) == VA2 mod (cache size) Since the OS controls the page map, and it creates any aliases that exist (e.g., via copy on write), it can ensure this property. 21

Solution (4): Virtually indexed physically tagged VA key idea: page offset bits are not translated and thus can be presented to the cache immediately VPN L = C-b b Virtual Index PA TLB PPN P Page Offset Direct-map Cache Size 2 C = 2 L+b Tag hit? Index L is available without consulting the TLB cache and TLB accesses can begin simultaneously Critical path = max(cache time, TLB time)!!! Tag comparison is made after both accesses are completed = Physical Tag Data Work if Cache Size Page Size (à C P) because then none of the cache inputs need to be translated (i.e., the index bits in physical and virtual addresses are the same)

(Physical) Memory 8GB

(Physical) Memory 8GB

(Physical) Memory 8GB

(Physical) Memory 8GB

(Physical) Memory 8GB

(Physical) Memory 8GB

(Physical) Memory 8GB

(Physical) Memory 8GB

(Physical) Memory 8GB

(Physical) Memory 8GB

Virtualizing Memory We need to make it appear that there is more memory than there is in a system Allow many programs to be running or at least ready to run at once (mostly) Absorb memory leaks (sometimes... if you are programming in C or C ++)

Page table with pages on disk Virtual Address 31 22 21 12 11 p1 p2 offset 0 10-bit L1 index Root of the Current Page Table 10-bit L2 index p2 offset p1 (Processor Register) Level 1 Page Table page in primary memory page on disk PTE of a nonexistent page Level 2 Page Tables Data Pages

The TLB With Disk TLB entries always point to memory, not disks 26

The Value of Paging Disk are really really slow. Paging is not very useful for expanding the active memory capacity of a system It s good for coarse grain context switching between apps And for dealing with memory leaks ;-) As a result, fast systems don t page. 27

The Future of Paging Non-volatile, solid-state memories significantly alter the trade-offs for paging. NAND-based SSDs can be between 10-100x faster than disk Is paging viable now? In what circumstances? 28

Other uses for VM VM provides us a mechanism for adding meta data to different regions of memory. The primary piece of meta data is the location of the data in physical ram. But we can support other bits of information as well 29

Other uses for VM VM provides us a mechanism for adding meta data to different regions of memory. The primary piece of meta data is the location of the data in physical ram. But we can support other bits of information as well Backing memory to disk next slide Protection Pages can be readable, writable, or executable Pages can be cachable or un-cachable Pages can be write-through or write back. Other tricks Arrays bounds checking Copy on write, etc. 30