From Address Translation to Demand Paging

Slides:



Advertisements
Similar presentations
Virtual Memory Basics.
Advertisements

EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
May 7, A Real Problem  What if you wanted to run a program that needs more memory than you have?
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
1 A Real Problem  What if you wanted to run a program that needs more memory than you have?
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Virtual Memory I Steve Ko Computer Sciences and Engineering University at Buffalo.
1 COMP 206: Computer Architecture and Implementation Montek Singh Mon., Nov. 17, 2003 Topic: Virtual Memory.
Memory Management (II)
Computer ArchitectureFall 2008 © November 10, 2007 Nael Abu-Ghazaleh Lecture 23 Virtual.
Computer ArchitectureFall 2007 © November 21, 2007 Karem A. Sakallah Lecture 23 Virtual Memory (2) CS : Computer Architecture.
Lecture 19: Virtual Memory
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
1 Some Real Problem  What if a program needs more memory than the machine has? —even if individual programs fit in memory, how can we run multiple programs?
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Computer Architecture Lecture 12: Virtual Memory I
Virtual Memory Chapter 8.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.
CMSC 611: Advanced Computer Architecture
Bernhard Boser & Randy Katz
Virtual Memory Chapter 7.4.
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
From Address Translation to Demand Paging
CS703 - Advanced Operating Systems
From Address Translation to Demand Paging
Today How was the midterm review? Lab4 due today.
CS 704 Advanced Computer Architecture
Some Real Problem What if a program needs more memory than the machine has? even if individual programs fit in memory, how can we run multiple programs?
Memory Hierarchy Virtual Memory, Address Translation
CSE 153 Design of Operating Systems Winter 2018
CS 61C: Great Ideas in Computer Architecture Lecture 23: Virtual Memory Krste Asanović & Randy H. Katz 11/12/2018.
Virtual Memory and Interrupts
CS 105 “Tour of the Black Holes of Computing!”
Translation Lookaside Buffer
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Contents Memory types & memory hierarchy Virtual memory (VM)
CSE451 Virtual Memory Paging Autumn 2002
Virtual Memory Prof. Eric Rotenberg
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2004 Page Tables, TLBs, and Other Pragmatics Hank Levy 1.
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CS 105 “Tour of the Black Holes of Computing!”
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CS 105 “Tour of the Black Holes of Computing!”
CSE 451: Operating Systems Winter 2005 Page Tables, TLBs, and Other Pragmatics Steve Gribble 1.
CSE 153 Design of Operating Systems Winter 2019
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
Translation Buffers (TLBs)
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Virtual Memory.
Cache writes and examples
Review What are the advantages/disadvantages of pages versus segments?
Instructor: Phil Gibbons
Virtual Memory 1 1.
Presentation transcript:

From Address Translation to Demand Paging Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November 6, 2017 http://csg.csail.mit.edu/6.175

Modern Virtual Memory Systems Illusion of a large, private, uniform store OS useri Protection & Privacy Each user has one private and one or more shared address spaces page table  name space Demand Paging Provides the ability to run programs larger than the primary memory Hides differences in machine configurations Swapping Store Primary Memory VA PA mapping TLB The price of VM is address translation on each memory reference November 6, 2017 http://csg.csail.mit.edu/6.175

Names for Memory Locations Physical Memory (DRAM) Address Mapping ISA machine language address virtual address physical address Machine language address as specified in machine code Virtual address ISA specifies translation of machine code address into virtual address of program variable (sometime called effective address) Physical address operating system maps virtual address into physical memory addresses November 6, 2017 http://csg.csail.mit.edu/6.175

Paged Memory Systems Processor generated address can be interpreted as a pair <page number, offset> A page table contains the physical address of the base of each page page number offset 1 2 3 Address Space of User-1 Page Table Page (4kB) Page descriptor (4-8B) Relaxes the contiguous allocation requirement. Page tables make it possible to store the pages of a program non-contiguously November 6, 2017 http://csg.csail.mit.edu/6.175

Private Address Space per User Page Table free OS pages Physical Memory User 1 VA1 Page Table User 2 VA1 Each user has a page table which contains an entry for each user page System has a “Page” Table that has an entry for each user (not shown) There is a PT Base register which points to the page table of the current user OS resets the PT Base register whenever the user changes; requires consulting the System Page Table November 6, 2017 http://csg.csail.mit.edu/6.175

Suppose all Pages and Page Tables reside in memory Physical Page Number + PT User 1 VPN offset PT Base Reg Virtual Page Number PT User 2 System PT Base PTB Useri System PT Translation: PPN = Mem[PT Base + VPN] PA = PPN + offset All links represent physical addresses; no VA to PA translation On user switch PT Base Reg := System PT Base + new User ID It requires two DRAM accesses to access one data word or instruction! November 6, 2017 http://csg.csail.mit.edu/6.175

VM Implementation Issues How to reduce memory access overhead What if all the pages can’t fit in DRAM What if the user page table can’t fit in DRAM What if the System page table can’t fit in DRAM Beyond the scope of this subject A good VM design needs to be fast and space efficient November 6, 2017 http://csg.csail.mit.edu/6.175

Page Table Entries and Swap Space VPN PPN DPN Page Table Data word Data Pages All the pages of all the users may not fit in DRAM and therefore, DRAM is backed up by swap space on disk (Disk is not shown) Page Table Entry (PTE) contains: A bit to indicate if the page exists PPN (physical page number) for a memory-resident page DPN (disk page number) for a page on the disk Protection and usage bits Offset Virtual address PT Base Reg VPN Offset November 6, 2017 http://csg.csail.mit.edu/6.175

Translation Lookaside Buffers (TLB) virtual address VPN offset V R W D tag PPN hit? TLB Mode = Kernel/User Op = Read/Write Protection Check PPN offset physical address Exception? Keep some of the (VPN,PPN) translations in a cache (TLB) No need to put (VPN, DPN) in TLB Every instruction fetch and data access needs address translation and protection checks TLB miss causes an access to the page table to refill the TLB 3 memory references 2 page faults (disk accesses) + .. Actually used in IBM before paged memory. November 6, 2017 http://csg.csail.mit.edu/6.175

TLB Designs Typically 32-128 entries, usually fully associative Effectively no spatial locality across pages Large TLBs (256-512 entries) are usually 4-8 way set-associative Switching users is expensive because TLB has to be flushed Handling a TLB miss: “Walk” the page table; if the page is in memory, reload the TLB otherwise cause a page fault, i.e., missing-page exception page faults are always handled in software but page walks are usually handled in hardware using a memory management unit (MMU) RISC-V has no TLB miss exceptions and thus, mandates hardware MMU Sometimes TLB entries contain User IDs To avoid flushing TLB on a user change November 6, 2017 http://csg.csail.mit.edu/6.175

TLB Reach The size of largest number of physical pages that can be accessed via a TLB Example: 64 TLB entries, 4KB pages, one page per entry TLB Reach = 64 entries * 4 KB = 256 KB small relative to typical DRAM size ==> many DRAM resident pages can’t be accessed without a TLB refill Use several different page sizes (4KB, 2MB, 1GB, ...), i.e., use TLB entries more efficiently Each size, requires a different split of a virtual address into (VPN, Offset) Fast TLB refills for DRAM-resident pages by doing the refills in hardware To avoid flushing TLB on a user change solutions November 6, 2017 http://csg.csail.mit.edu/6.175

Handling a Page Fault When the referenced page is not in DRAM: The missing page is located (or created) It is brought in from disk, and page table is updated Another job may be run on the CPU while the first job waits for the requested page to be read from disk If no free space left in DRAM, a page has to be swapped out using some replacement policy Popular policy “approximate LRU” Since it takes a long time (msecs) to transfer a page, page faults are handled completely in software (OS) November 6, 2017 http://csg.csail.mit.edu/6.175

Address Translation: putting it all together Virtual Address hardware hardware or software software TLB Lookup miss hit Page Table Walk the page is Ï memory Î memory Protection Check denied permitted Need to restart instruction. Soft and hard page faults. Page Fault (OS loads page) Update TLB Resume the instruction Protection Fault Seg fault Physical Address (to cache) Where? November 6, 2017 http://csg.csail.mit.edu/6.175

RISC-V Virtual Memory Privileged ISA v. 1.9.1 November 6, 2017 http://csg.csail.mit.edu/6.175

RISC-V Privilege Levels Needed for protection – User programs can’t exercise some hardware capabilities User-mode (U) – addresses are virtual, access to devices only through system calls Supervisor-mode (S) – addresses are typically virtual addresses, can switch page-table in use (sptbr) Machine-mode (M) – all addresses are physical addresses, has access to all addresses including memory-mapped IO devices CSR No VA to PA translation November 6, 2017 http://csg.csail.mit.edu/6.175

RISC-V Memory Maps Machine-Mode Physical Addresses DRAM Boot ROM MMIO Debug Unit Machine-Mode Physical Addresses DRAM User-Mode Virtual Addresses Only part of the address space is DRAM Demand Paging makes the entire address space look like DRAM November 6, 2017 http://csg.csail.mit.edu/6.175

RISC-V Sv32 Virtual Addressing Mode Virtual Addresses: Physical Addresses: VPN[0] page offset VPN[1] 12 bits 10 bits 1st level PT Index 2st level PT Index User PT is organized as a two-level tree instead of a linear table with 220 entries PPN[0] page offset PPN[1] 12 bits 10 bits For large pages, PPN[0] is the page number and the offset is calculated by combing page offset and PPN[1] November 6, 2017 http://csg.csail.mit.edu/6.175

Sv32 Page Table Entries PPN[0] SW Reserved PPN[1] D A G U X W R V 2 bits 10 bits 12 bits Dirty – This page has been written to Accessed - This page has been accessed Global – Mapping exists in all virtual address spaces User – User-mode programs can access this page eXecute – This page can be executed Write – This page can be written to Read – This page can be read from Valid – This page valid and in memory November 6, 2017 http://csg.csail.mit.edu/6.175

Sv32 Page Table Entries PPN[0] SW Reserved PPN[1] D A G U X W R V 2 bits 10 bits 12 bits If V = 1, but X, W, R == 0, PPN[] points to the 2nd level page table If V = 0, page is either invalid or in disk. If in disk, the OS can reuse bits in the PTE to store the disk address (or part of it). Disk Address G U X W R 26 bits November 6, 2017 http://csg.csail.mit.edu/6.175

RISC-V Pipeline with VM PC D E M W Inst TLB Inst. Cache Decode Data TLB Data Cache + translation, page fault or segfault translation, page fault or segfault miss miss Page Table Walker Page Table Walker memory accesses memory accesses On a fault, an exception is raised and the OS takes over November 6, 2017 http://csg.csail.mit.edu/6.175

SFence.VM Instruction Privileged instruction to synchronize TLB translation Flushes stale TLB translations Ensures that stores to data cache are seen by hardware page table walker A similar instruction (Fence.I) is needed to support self-modifying code November 6, 2017 http://csg.csail.mit.edu/6.175

Final comments Virtual memory is a an essential feature of almost all processors except for the smallest processors that are used in the embedded space Significant verification effort is required to boot an Operating system on a processor because of virtual memory Precise exceptions are essential to implement VM systems Performance is usually not an issue, and therefore sometimes exceptions are implemented using microcode November 6, 2017 http://csg.csail.mit.edu/6.175