University of Washington Indirection in Virtual Memory 1 Each process gets its own private virtual address space Solves the previous problems Physical.

Slides:



Advertisements
Similar presentations
EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
Advertisements

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.
Virtual Memory October 25, 2006 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs class16.ppt.
Carnegie Mellon 1 Virtual Memory: Concepts : Introduction to Computer Systems 15 th Lecture, Oct. 14, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
Today Virtual memory (VM) Overview and motivation
Virtual Memory Nov 27, 2007 Slide Source: Topics Motivations for VM Address translation Accelerating translation with TLBs class12.ppt.
Virtual Memory October 29, 2007 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs class16.ppt.
Virtual Memory May 19, 2008 Topics Motivations for VM Address translation Accelerating translation with TLBs EECS213.
Carnegie Mellon 1 Virtual Memory: Concepts / : Introduction to Computer Systems 16 th Lecture, Oct. 21, 2014 Instructors: Greg Ganger, Greg.
Virtual Memory Topics Motivations for VM Address translation Accelerating translation with TLBs CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory: Concepts
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
University of Washington Today Lab 5 out  Puts a *lot* together: pointers, debugging, C, etc.
Carnegie Mellon 1 Saint Louis University Virtual Memory CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant.
Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work.
1 Seoul National University Virtual Memory: Systems.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
1 Virtual Memory. 2 Outline Pentium/Linux Memory System Core i7 Suggested reading: 9.6, 9.7.
1 Virtual Memory: Concepts Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaron.
Carnegie Mellon 1 Virtual Memory: Concepts Instructor: Rabi Mahapatra (TAMU) Slides: Randy Bryant and Dave O’Hallaron (CMU)
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
Virtual Memory April 3, 2001 Topics Motivations for VM Address translation Accelerating translation with TLBs class20.ppt.
University of Amsterdam Computer Systems – virtual memory Arnoud Visser 1 Computer Systems Virtual Memory.
Virtual Memory Additional Slides Slide Source: Topics Address translation Accelerating translation with TLBs class12.ppt.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Virtual Memory.  Next in memory hierarchy  Motivations:  to remove programming burdens of a small, limited amount of main memory  to allow efficient.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Concepts Slides adapted from Bryant.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Concepts CENG331 - Computer Organization.
Virtual Memory Topics Motivations for VM Address translation Accelerating translation with TLBs CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
Virtual Memory Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs.
Virtual Memory October 14, 2008 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs lecture-14.ppt.
CSE 153 Design of Operating Systems Winter 2015 Lecture 11: Paging/Virtual Memory Some slides modified from originals by Dave O’hallaron.
1 Virtual Memory (I). 2 Outline Physical and Virtual Addressing Address Spaces VM as a Tool for Caching VM as a Tool for Memory Management VM as a Tool.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
1 Virtual Memory. 2 Outline Virtual Space Address translation Accelerating translation –with a TLB –Multilevel page tables Different points of view Suggested.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Systems CSCE312: Computer Organization.
Alan L. Cox Virtual Memory Alan L. Cox Some slides adapted from CMU slides.
Computer Architecture Lecture 12: Virtual Memory I
Virtual Memory Samira Khan Apr 27, 2017.
Virtual Memory Samira Khan Apr 25, 2017.
Section 9: Virtual Memory (VM)
CS703 - Advanced Operating Systems
Section 9: Virtual Memory (VM)
Today How was the midterm review? Lab4 due today.
Virtual Memory III CSE 351 Spring 2017
CS 704 Advanced Computer Architecture
Virtual Memory.
CS 105 “Tour of the Black Holes of Computing!”
CSE 153 Design of Operating Systems Winter 2018
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory II CSE 351 Autumn 2016
CSE 153 Design of Operating Systems Winter 2018
Virtual Memory: Concepts /18-213/14-513/15-513: Introduction to Computer Systems 17th Lecture, October 23, 2018.
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory II CSE 410 Winter 2017
Instructors: Majd Sakr and Khaled Harras
Virtual Memory Nov 27, 2007 Slide Source:
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Virtual Memory II CSE 351 Winter 2018
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
Instructor: Phil Gibbons
Presentation transcript:

University of Washington Indirection in Virtual Memory 1 Each process gets its own private virtual address space Solves the previous problems Physical memory Virtual memory Process 1 Process n mapping

University of Washington A System Using Virtual Addressing 2 Physical addresses are completely invisible to programs. Used in all modern desktops, laptops, servers, smartphones… One of the great ideas in computer science 0: 1: M-1: Main memory MMU 2: 3: 4: 5: 6: 7: Physical address (PA) Data word 8:... CPU Virtual address (VA) CPU Chip Memory Management Unit

University of Washington Address Translation With a Page Table 3 Virtual page number (VPN)Virtual page offset (VPO) Physical page number (PPN) Physical page offset (PPO) Virtual address (VA) Physical address (PA) Valid Physical page number (PPN) Page table Valid bit = 0: page not in memory (page fault) This feels familiar…

University of Washington VM for Managing Multiple Processes Key abstraction: each process has its own virtual address space  It can view memory as a simple linear array With virtual memory, this simple linear virtual address space need not be contiguous in physical memory  Process needs to store data in another VP? Just map it to any PP! 4 Virtual Address Space for Process 1: Physical Address Space (DRAM) 0 N-1 (e.g., read-only library code) Virtual Address Space for Process 2: VP 1 VP N-1 VP 1 VP 2... PP 2 PP 6 PP M-1 Address translation

University of Washington VM for Protection and Sharing The mapping of VPs to PPs provides a simple mechanism to protect memory and to share memory between processes.  Sharing: just map virtual pages in separate address spaces to the same physical page (here: PP 6)  Protection: process simply can’t access physical pages to which none of its virtual pages are mapped (here: Process 2 can’t access PP 2). 5 Virtual Address Space for Process 1: Physical Address Space (DRAM) 0 N-1 (e.g., read-only library code) Virtual Address Space for Process 2: VP 1 VP N-1 VP 1 VP 2... PP 2 PP 6 PP M-1 Address translation

University of Washington Memory Protection Within a Single Process Can we use virtual memory to control read/write/execute permissions? How? 6

University of Washington Memory Protection Within a Single Process Extend page table entries with permission bits MMU checks these permission bits on every memory access  If violated, raises exception and OS sends SIGSEGV signal to process (segmentation fault) 7 Process i: Physical Page NumWRITEEXEC PP 6No PP 4NoYes PP 2Yes Process j: No READ Yes No Yes WRITEEXEC PP 9YesNo PP 6No PP 11YesNo READ No Yes No VP 0: VP 1: VP 2: VP 0: VP 1: VP 2: Physical Address Space PP 2 PP 4 PP 6 PP 8 PP 9 PP 11 Yes Valid Physical Page Num

University of Washington Terminology context switch  Switch between processes on the same CPU. page in  Move pages of virtual memory from disk to physical memory. page out  Move pages of virtual memory from physical memory to disk. thrash  Total working set size of processes is larger than physical memory. Most time is spent paging in and out instead of doing useful computation. (I find all these terms useful when talking to other computer scientists about my brain…) 8

University of Washington Address Translation: Page Hit 9 1) Processor sends virtual address to MMU (memory management unit) 2-3) MMU fetches PTE from page table in cache/memory 4) MMU sends physical address to cache/memory 5) Cache/memory sends data word to processor MMU Cache/ Memory PA Data CPU VA CPU Chip PTEA PTE

University of Washington Address Translation: Page Fault 10 1) Processor sends virtual address to MMU 2-3) MMU fetches PTE from page table in cache/memory 4) Valid bit is zero, so MMU triggers page fault exception 5) Handler identifies victim (and, if dirty, pages it out to disk) 6) Handler pages in new page and updates PTE in memory 7) Handler returns to original process, restarting faulting instruction MMU Cache/ Memory CPU VA CPU Chip PTEA PTE Disk Page fault handler Victim page New page Exception 6 7

University of Washington Hmm… Translation Sounds Slow! The MMU accesses memory twice: once to first get the PTE for translation, and then again for the actual memory request from the CPU  The PTEs may be cached in L1 like any other memory word  But they may be evicted by other data references  And a hit in the L1 cache still requires 1-3 cycles What can we do to make this faster? 11

University of Washington Speeding up Translation with a TLB Solution: add another cache! 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  Modern Intel processors: 128 or 256 entries in TLB  Much faster than a page table lookup in cache/memory 12

University of Washington TLB Hit 13 MMU Cache/ Memory PA Data CPU VA CPU Chip PTE A TLB hit eliminates a memory access TLB VPN 3

University of Washington TLB Miss 14 MMU Cache/ Memory PA Data CPU VA CPU Chip PTE TLB VPN 4 PTEA 3 A TLB miss incurs an additional memory access (the PTE) Fortunately, TLB misses are rare. Does a TLB miss require disk access?

University of Washington Simple Memory System Example (small) Addressing  14-bit virtual addresses  12-bit physical address  Page size = 64 bytes VPO PPOPPN VPN Virtual Page Number Virtual Page Offset Physical Page Number Physical Page Offset

University of Washington Simple Memory System Page Table Only showing first 16 entries (out of 256 = 2 8 ) What about a real address space? Read more in the book… 16 10D0F 1110E 12D0D 0–0C 0–0B 1090A ValidPPNVPN 0–07 0– – – ValidPPNVPN

University of Washington Simple Memory System TLB 16 entries 4-way associative virtual page offset virtual page number TLB index TLB tag 0–021340A10D030–073 0–030–060–080–022 0–0A0–040–0212D –0010D090–030 ValidPPNTagValidPPNTagValidPPNTagValidPPNTagSet TLB ignores page offset. Why?

University of Washington Simple Memory System Cache 16 lines, 4-byte block size Physically addressed Direct mapped physical page offsetphysical page number cache offset cache index cache tag 03DFC ––––0316 1DF D5 098F6D –––– B2 –––– B3B2B1B0ValidTagIdx ––––014F D31B E D ––––012C ––––00BB 3BDA159312DA –––– A1248 B3B2B1B0ValidTagIdx

University of Washington Virtual Address: 0x03D4 virtual page #___ TLB index___ TLB tag ____ TLB Hit? __ Page Fault? __ physical page #: ____ Address Translation Example # page offset virtual page number TLB index TLB tag x0F30x03 Y N0x0D 0–021340A10D030–073 0–030–060–080–022 0–0A0–040–0212D –0010D090–030 ValidPPNTagValidPPNTagValidPPNTagValidPPNTagSet TLB

University of Washington Physical Address: 0x354 cache offset___ cache index___cache tag____ Hit? __ Byte: ____ Address Translation Example # physical page offset physical page number cache offset cache index cache tag x50x0D Y0x36 Cache

University of Washington virtual page #___ TLB index___ TLB tag ____ TLB Hit? __ Page Fault? __ physical page #: ____ Address Translation Example #2 Virtual Address: 0x0B8F x2E20x0B N ?TBD page offset virtual page number TLB index TLB tag 0–021340A10D030–073 0–030–060–080–022 0–0A0–040–0212D –0010D090–030 ValidPPNTagValidPPNTagValidPPNTagValidPPNTagSet TLB

University of Washington virtual page #___ TLB index___ TLB tag ____ TLB Hit? __ Page Fault? __ physical page #: ____ Address Translation Example #3 Virtual Address: 0x x000 N page offset virtual page number TLB index TLB tag 0–021340A10D030–073 0–030–060–080–022 0–0A0–040–0212D –0010D090–030 ValidPPNTagValidPPNTagValidPPNTagValidPPNTagSet TLB

University of Washington virtual page #___ TLB index___ TLB tag ____ TLB Hit? __ Page Fault? __ physical page #: ____ Address Translation Example #3 Virtual Address: 0x x000 N N0x28 page offset virtual page number TLB index TLB tag 10D0F 1110E 12D0D 0–0C 0–0B 1090A ValidPPNVPN 0–07 0– – – ValidPPNVPN Page table

University of Washington Address Translation Example #3 Physical Address: 0xA20 cache offset___ cache index___cache tag____ Hit? __ Byte: ____ x80x28NMem physical page offset physical page number cache offset cache index cache tag Cache

University of Washington Summary Programmer’s view of virtual memory  Each process has its own private linear address space  Cannot be corrupted by other processes System view of virtual memory  Uses memory efficiently by caching virtual memory pages  Efficient only because of locality  Simplifies memory management and sharing  Simplifies protection by providing a convenient interpositioning point to check permissions 25

University of Washington Memory System Summary L1/L2 Memory Cache  Purely a speed-up technique  Behavior invisible to application programmer and (mostly) OS  Implemented totally in hardware Virtual Memory  Supports many OS-related functions  Process creation, task switching, protection  Operating System (software)  Allocates/shares physical memory among processes  Maintains high-level tables tracking memory type, source, sharing  Handles exceptions, fills in hardware-defined mapping tables  Hardware  Translates virtual addresses via mapping tables, enforcing permissions  Accelerates mapping via translation cache (TLB) 26

University of Washington Memory System Summary L1/L2 Memory Cache  Controlled by hardware  Programmer cannot control it  Programmer can write code in a way that takes advantage of it Virtual Memory  Controlled by OS and hardware  Programmer cannot control mapping to physical memory  Programmer can control sharing and some protection  via OS functions (not in 351) 27

University of Washington 28

University of Washington Disk Servicing a Page Fault (1) Processor signals disk controller  Read block of length P starting at disk address X  Store starting at memory address Y (2) Read occurs  Direct Memory Access (DMA)  Under control of I/O controller (3) Controller signals completion  Interrupts processor  OS resumes suspended process 29 Disk Memory-I/O bus Processor Cache Memory I/O controller I/O controller Reg (2) Direct Memory Address Transfer (1) Initiate Block Read (3) Read Done