Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Similar documents
CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

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

Virtual Memory II CSE 351 Spring

CSE 351. Virtual Memory

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

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

Translation Buffers (TLB s)

ECE 571 Advanced Microprocessor-Based Design Lecture 12

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Recap: Memory Management

ECE331: Hardware Organization and Design

Chapter 5 (Part II) Large and Fast: Exploiting Memory Hierarchy. Baback Izadi Division of Engineering Programs

Virtual to physical address translation

ECE 598 Advanced Operating Systems Lecture 14

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

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

CSE 120 Principles of Operating Systems

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

Virtual Memory: From Address Translation to Demand Paging

Virtual Memory: From Address Translation to Demand Paging

Virtual Memory. Virtual Memory

Computer Systems. Virtual Memory. Han, Hwansoo

CSE 120 Principles of Operating Systems Spring 2017

Virtual Memory. Samira Khan Apr 27, 2017

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

Virtual Memory, Address Translation

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

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

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

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

Processes and Virtual Memory Concepts

Basic Memory Management

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

Chapter 5 Large and Fast: Exploiting Memory Hierarchy (Part 2)

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

CS 153 Design of Operating Systems Winter 2016

Virtual Memory, Address Translation

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 7: Memory Organization Part II

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

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

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

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

VIRTUAL MEMORY II. Jo, Heeseung

Readings and References. Virtual Memory. Virtual Memory. Virtual Memory VPN. Reading. CSE Computer Systems December 5, 2001.

CS162 Operating Systems and Systems Programming Lecture 10 Caches and TLBs"

Virtual Memory. CS 3410 Computer System Organization & Programming

HY225 Lecture 12: DRAM and Virtual Memory

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

PROCESS VIRTUAL MEMORY PART 2. CS124 Operating Systems Winter , Lecture 19

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

Outlook. Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The Intel Pentium

Computer Architecture. Lecture 8: 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

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

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

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

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

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013

Address spaces and memory management

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Lecture 20: Multi-Cache Designs. Spring 2018 Jason Tang

LECTURE 12. Virtual Memory

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

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

Computer Architecture. R. Poss

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

Chapter 5 B. Large and Fast: Exploiting Memory Hierarchy

CS 153 Design of Operating Systems Winter 2016

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

ECE 571 Advanced Microprocessor-Based Design Lecture 13

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

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

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

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

Virtual Memory - Objectives

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

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

VM as a cache for disk

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

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

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

Virtual Memory Oct. 29, 2002

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

ECE 341. Lecture # 18

COS 318: Operating Systems. Virtual Memory and Address Translation

John Wawrzynek & Nick Weaver

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

CS/COE 1550

CS 318 Principles of Operating Systems

Computer Systems Architecture I. CSE 560M Lecture 18 Guest Lecturer: Shakir James

Memory Management. Goals of Memory Management. Mechanism. Policies

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

Transcription:

Lecture 21: Virtual Memory Spring 2018 Jason Tang 1

Topics Virtual addressing Page tables Translation lookaside buffer 2

Computer Organization Computer Processor Memory Devices Control Datapath Input Output Discussion thus far has concentrated upon the processor and then memory Will now start describing connection between processor and memory, processor and devices, and memory and devices 3

System Interconnect Processor Processor Processor MMU MMU MMU Snoop Tag Cache Tag and Data Snoop Tag Cache Tag and Data Snoop Tag Cache Tag and Data Memory-I/O Bus DRAM Disk Controller Network Interface I/O Bridge 4

Address Spaces Virtual Address (or logical address): address generated by CPU Physical Address: address calculated by memory management unit (MMU) DMA: direct memory access DMA Address (or bus address): addresses used by devices to send data between themselves DMA addresses do not always match physical address 5

Virtual Address Space Separation of logical memory from physical memory, to allow for process isolation Virtual address space usually much larger than physical memory From perspective of a running program on the processor, load and store instructions are performed relative to that program s virtual address space MMU maps between virtual and physical addresses Avoid need for contiguous memory blocks Allows programs to be loaded at any physical memory location (relocation) 6

Virtual Memory Cache Block Cache Miss Block Addressing Virtual Memory Page Page Fault Address Translation Operating System Concepts, Silberschatz, Galvin, and Gagne 7

Page Fault Handling Main memory can be considered as a cache of disk contents Upon a page fault, the system [sometimes] loads the missing data from a disk ( swap in ) Very costly, can take millions of cycles to process Pages should be large enough to reduce page fault rate Modified data are cached as memory pages and then later flushed to disk (write back), as that constant writing to disk is too slow (write through) When selecting a victim page to evict, LRU is most common algorithm 8

Virtual Addressing Address is broken into a virtual page number and a page offset MMU translates virtual page number to a physical page number Example: ARMv8-A has 64-bit virtual addresses, but only lower 48 bits (256 TiB) are used. Suppose that physical address space is only 40 bits (1 TiB), and a page is 4 KiB. Then: 63 48 47 12 11 0 Must be 0 Virtual Page Number Page Offset Translation 39 12 11 0 Physical Page Number Page Offset 9

Memory Maps In a set-associative cache, a particular memory block is mapped into some particular set With paging, the operating system maintains the memory mappings between virtual addresses and physical addresses Multiple virtual addresses map to the same physical address to support shared memory Multiple physical addresses map to the same virtual address to support process forking (or after a copy-on-write page has been modified) 10

Page Table Stored in main memory Page Table Register set to address of the beginning of page table Operating system maintains a different page table for each process Each entry in table gives a mapping between a virtual and physical address If a computed load/store virtual address does not have an entry within table, then MMU raises an exception 11

Page Table Every page table entry has control flags: 47 12 11 Virtual Page Number Page Offset 0 Valid Bit: If set, then proceed with memory access; otherwise raise exception Page Table Register Valid Dirty 36 Physical Page Number Dirty Bit: Set by hardware when page is modified 39 28 Physical Page Number 12 11 0 Page Offset In simplest case, virtual page number is an index number into page table 12

Page Table Size Many architectures default to 4 KiB pages (12 bits) For a 32-bit virtual address, that means upper 20 bits give a virtual page number, and lower 12 bits are an offset into the resulting physical page To fully utilize a 4 GiB address space (32 bits), number of page table entries is If each page table entry is 32 bits (4 bytes), then entire page table requires 2 22 bytes = 4 MiB (which is greater than a page itself) Need to either increase page sizes ( huge pages ), or use multi-level paging 13

Multi-Level Page Table Instead of using virtual page number as an index into a single page table, split those bits to specify a first level and second level page Example: For a 32-bit virtual address with 4 KiB pages, let the first 10 bits index into a first level page table. The entry in there gives the physical address of the second level page table. Let the next 10 bits index into that second level page table. Use the entry in the second page table to get the final physical page number. 32-bit address: 1K PTEs 4 bytes 4KB 10 10 12 P1 index P2 index page offset 4 bytes 14

ARMv8-A Multi-Level Page Table ARMv8-A has 64-bit virtual addresses, and allows for various page sizes For 4 KiB pages ( granules ), bits [47:39] specifies one of 512 entries within L0 table; each entry gives an address of a L1 table. Because each entry is 8 bytes, 512 8 = 4096 bytes, which is the page size. Bits [38:30] gives index within L1 table, bits [29:21] gives index with L2 table, bits [20:12] gives index within L3 table. For 64 KiB pages, bits [47:42] are index into L1 table, bits [41:29] are index into L2 table, and then bits [28:16] are index into L3 table. Bits [15:0] are the page offset. ARM Cortex-A Series Programmer s Guide, 12.4.2 15

ARMv8-A Multi-Level Page Table ARM Cortex-A Series Programmer s Guide, 12.3 16

TLB Each lookup into a page table incurs more memory overhead Translation Lookaside Buffer (TLB): translation cache within MMU that stores recent lookups TLB Hit: Translation of a virtual address resolved by a cached TLB entry TLB size is limited, so MMU replaces old TLBs (either automatically or via software) when a new one is cached Like normal cache, TLB entries can be invalidated to force a refetch of the page table entries 17

TLB Lookup Operating System Concepts, Silberschatz, Galvin, and Gagne 18

TLB and Cache Example Virtual address 31 30 29 15 14 13 12 11 10 9 8 3 2 1 0 Virtual page number Page offset 20 12 Upon TLB miss, perform external table walk to resolve physical page number TLB TLB hit Valid Dirty Tag Physical page number 20 Physical page number Page offset Physical address Physical address tag Cache index 16 14 2 Byte offset Valid Tag Data Upon cache miss, fill cache block with data from memory Cache 32 Cache hit Data 19

TLB and Cache Virtual address TLB hit and cache hit are independent TLB access TLB miss exception No TLB hit? Yes Physical address A TLB entry must exist before cache can be accessed No Write? Yes Page table itself can be cached Try to read data from cache No Write access bit on? Yes Cache miss stall No Cache hit? Yes Write protection exception Write data into cache, update the tag, and put the data and the address into the write buffer Deliver data to the CPU 20

Memory Exceptions Summary Cache miss: referenced block not in cache; needs to be fetch from main memory TLB miss: referenced page of virtual address needs to be check in page table Page fault: reference page not in main memory (may need to load from disk) Cache TLB Page Condition miss hit hit Possible, but page table is unchecked if TLB hits hit miss hit TLB miss, but entry found in page table and data in cache miss miss hit TLB miss, but entry found in page table and date miss in cache miss miss miss TLB miss, followed by page fault; data missed in cache miss hit miss Impossible: to translation possible if page not in memory hit hit miss Impossible: to translation possible if page not in memory hit miss miss Impossible: data cannot be cached if page is not in memory 21

Memory Protection Bits Page table entries support protection bits in addition to valid and dirty bits: Read-only or read-write Executable or non-executable User mode or privileged mode Memory Region Stack Heap Text Constants Protection RW, NX RW, NX RO, X RO, NX Operating system uses protection bits to enforce separation of data between system and user processes 22

Handling TLB Misses and Page Faults TLB Miss: handled by hardware Check if page is in memory and is valid update TLB Raise page fault exception if page is not in memory Page Fault: handled by operating system OS exception handler determines cause of page fault If OS needs to load referenced data from disk, it will restart instruction after disk I/O completes; until then process is suspended 23