Virtual Memory Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs.

Slides:



Advertisements
Similar presentations
Fabián E. Bustamante, Spring 2007
Advertisements

Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
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.
Virtual Memory October 30, 2001 Topics Motivations for VM Address translation Accelerating translation with TLBs class19.ppt “The course that gives.
Virtual Memory October 29, 2007 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs class16.ppt.
Virtual Memory Topics Virtual Memory Access Page Table, TLB Programming for locality Memory Mountain Revisited.
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.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Virtual Memory: Concepts
Virtual & Dynamic Memory Management Summer 2014 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University.
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.
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 March 23, 2000 Topics Motivations for VM Address translation Accelerating address translation with TLBs Pentium II/III memory system
Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work.
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.
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!”
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Virtual Memory Topics Motivations for VM Address translation Accelerating translation with TLBs VM1 CS 105 “Tour of the Black Holes of Computing!”
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.
Virtual Memory CS740 October 13, 1998 Topics page tables TLBs Alpha 21X64 memory system.
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.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
University of Washington Indirection in Virtual Memory 1 Each process gets its own private virtual address space Solves the previous problems Physical.
Dynamic Memory Management Winter 2013 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University.
Alan L. Cox Virtual Memory Alan L. Cox Some slides adapted from CMU slides.
Virtual Memory Samira Khan Apr 25, 2017.
Section 9: Virtual Memory (VM)
Section 9: Virtual Memory (VM)
Today How was the midterm review? Lab4 due today.
Virtual Memory: Concepts CENG331 - Computer Organization
Virtual Memory.
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory I CSE 351 Autumn 2017
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!”
CSE 351 Section 10 The END…Almost 3/7/12
ECE Dept., University of Toronto
Instructors: Majd Sakr and Khaled Harras
Virtual Memory Nov 27, 2007 Slide Source:
Operating System Chapter 7. Memory Management
Virtual Memory II CSE 351 Winter 2018
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory I CSE 351 Winter 2019
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
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.
Instructor: Phil Gibbons
Presentation transcript:

Virtual Memory Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs

2 CMSC313-F’09 Programs Refer to Virtual Memory Addresses Programs Refer to Virtual Memory Addresses Conceptually very large array of bytes Actually implemented with hierarchy of different memory types System provides address space private to particular “process” Program being executed Program can clobber its own data, but not that of others Compiler + Run-Time System Control Allocation Compiler + Run-Time System Control Allocation Where different program objects should be stored All allocation within single virtual address space Byte-Oriented Memory Organization 000FFF

3 CMSC313-F’09 Simple Addressing Modes Normal(R)Mem[Reg[R]] Normal(R)Mem[Reg[R]] Register R specifies memory address movl (%ecx),%eax DisplacementD(R)Mem[Reg[R]+D] DisplacementD(R)Mem[Reg[R]+D] Register R specifies start of memory region Constant displacement D specifies offset movl 8(%ebp),%edx

4 CMSC313-F’09 How does everything fit? 32-bit addresses: ~4,000,000,000 (4 billion) bytes 64-bit addresses: ~16,000,000,000,000,000,000 (16 quintillion) bytes How to decide which memory to use in your program? What if another process stores data into your memory? How could you debug your program? Lets think on this: physical memory? 000FFF

5 CMSC313-F’09 So, we add a level of indirection One simple trick solves all three problems Each process gets its own private image of memory appears to be a full-sized private memory range This fixes “how to choose” and “others shouldn’t mess w/yours” surprisingly, it also fixes “making everything fit” Implementation: translate addresses transparently add a mapping function to map private addresses to physical addresses do the mapping on every load or store This mapping trick is the heart of virtual memory

6 CMSC313-F’09 Address Spaces A linear address space is an ordered set of contiguous nonnegative integer addresses: {0, 1, 2, 3, … } A virtual address space is a set of N = 2 n virtual addresses: {0, 1, 2, …, N-1} A physical address space is a set of M = 2 m (for convenience) physical addresses: {0, 1, 2, …, M-1} In a system based on virtual addressing, each byte of main memory has a physical address and a virtual address (or more)

7 CMSC313-F’09 A System Using Physical Addressing Used by many embedded microcontrollers in devices like cars, elevators, and digital picture frames 0: 1: M -1: Main memory CPU 2: 3: 4: 5: 6: 7: Physical address (PA) 4 Data word 8:...

8 CMSC313-F’09 A System Using Virtual Addressing One of the great ideas in computer science  used by all modern desktop and laptop microprocessors... 0: 1: M-1: Main memory CPU 2: 3: 4: 5: 6: 7: Virtual address (VA) 4100 Data word Physical address (PA) 4 CPU chip MMU Address translation

9 CMSC313-F’09 Why Virtual Memory? (1) VM allows efficient use of limited main memory (RAM) Use RAM as a cache for the parts of a virtual address space some non-cached parts stored on disk some (unallocated) non-cached parts stored nowhere Keep only active areas of virtual address space in memory transfer data back and forth as needed (2) VM simplifies memory management for programmers Each process gets a full, private linear address space (3) VM isolates address spaces One process can’t interfere with another’s memory because they operate in different address spaces User process cannot access privileged information different sections of address spaces have different permissions

10 CMSC313-F’09 (1) VM as a Tool for Caching Virtual memory is an array of N contiguous bytes  think of the array as being stored on disk The contents of the array on disk are cached in physical memory (DRAM cache) PP 2 m-p -1 Physical memory Empty Uncached VP 0 VP 1 VP 2 n-p -1 Virtual memory Unallocated Cached Uncached Unallocated Cached Uncached PP 0 PP 1 Empty Cached 0 N-1 M-1 0 Virtual pages (VP's) stored on disk Physical pages (PP's) cached in DRAM

11 CMSC313-F’09 DRAM Cache Organization DRAM cache organization driven by the enormous miss penalty DRAM is about 10x slower than SRAM Disk is about 100,000x slower than DRAM to get first byte, though fast for next byte DRAM cache properties Large page (block) size (typically 4-8 KB) Fully associative Any virtual page can be placed in any physical page Requires a “large” mapping function – different from CPU caches Highly sophisticated replacement algorithms Too complicated and open-ended to be implemented in hardware Write-back rather than write-through

12 CMSC313-F’09 Reminder: MMU checks the cache One of the great ideas in computer science  used by all modern desktop and laptop microprocessors MMU Physical address (PA)... 0: 1: M-1: Main memory Virtual address (VA) CPU 2: 3: 4: 5: 6: 7: 4100 Data word 4 CPU chip Address translation

13 CMSC313-F’09 How? Page Tables A page table is an array of page table entries (PTEs) that maps virtual pages to physical pages Per-process kernel data structure in DRAM null Memory resident page table (DRAM) Physical memory (DRAM) VP 7 VP 4 Virtual memory (disk) Valid Physical page number or disk address PTE 0 PTE 7 PP 0 VP 2 VP 1 PP 3 VP 1 VP 2 VP 4 VP 6 VP 7 VP 3

14 CMSC313-F’09 Address Translation with a Page Table Virtual page number (VPN)Virtual page offset (VPO) VIRTUAL ADDRESS Physical page number (PPN) PHYSICAL ADDRESS 0p–1pm–1 n–10p–1p Page table base register (PTBR) If valid=0 then page not in memory (page fault) ValidPhysical page number (PPN) The VPN acts as index into the page table Page table Physical page offset (PPO)

15 CMSC313-F’09 Page Hits A page hit is a reference to a VM word that is in physical (main) memory null Memory resident page table (DRAM) Physical memory (DRAM) VP 7 VP 4 Virtual memory (disk) Valid Physical page number or disk address PTE 0 PTE 7 PP 0 VP 2 VP 1 PP 3 VP 1 VP 2 VP 4 VP 6 VP 7 Virtual address VP 3

16 CMSC313-F’09 Page Faults A page fault is caused by a reference to a VM word that is not in physical (main) memory Example: An instruction references a word contained in VP 3, a miss that triggers a page fault exception null Memory resident page table (DRAM) Physical memory (DRAM) VP 7 VP 4 Virtual memory (disk) Valid Physical page number or disk address PTE 0 PTE 7 PP 0 VP 2 VP 1 PP 3 VP 1 VP 2 VP 4 VP 6 VP 7 Virtual address VP 3

17 CMSC313-F’09 Handling a Page Fault null Memory resident page table (DRAM) Physical memory (DRAM) VP 7 VP 3 Virtual memory (disk) Valid Physical page number or disk address PTE 0 PTE 7 PP 0 VP 2 VP 1 PP 3 VP 1 VP 2 VP 4 VP 6 VP 7 Virtual address VP 3 The kernel’s page fault handler selects VP 4 as the victim and replaces it with a copy of VP 3 from disk (demand paging) When the offending instruction restarts, it executes normally, without generating an exception..

18 CMSC313-F’09 Why does it work? Locality Virtual memory works because of locality At any point in time, programs tend to access a set of active virtual pages called the working set Programs with better temporal locality will have smaller working sets If (working set size < main memory size) Good performance for one process after compulsory misses If ( SUM(working set sizes) > main memory size ) Thrashing: Performance meltdown where pages are swapped (copied) in and out continuously

19 CMSC313-F’09 (2) VM as a Tool for Memory Mgmt Key idea: each process has its own virtual address space It can view memory as a simple linear array Mapping function scatters addresses through physical memory Well chosen mappings simplify memory allocation and management Virtual Address Space for Process 1: Physical Address Space (DRAM) VP 1 VP 2 PP 2 Address Translation 0 0 N-1 0 M-1 VP 1 VP 2 PP 7 PP 10 (e.g., read-only library code)... Virtual Address Space for Process 2:

20 CMSC313-F’09 Simplifying Sharing and Allocation Memory allocation Each virtual page can be mapped to any physical page A virtual page can be stored in different physical pages at different times – the program never knows Sharing code and data among processes Map virtual pages to the same physical page (PP 7) Virtual Address Space for Process 1: Physical Address Space (DRAM) VP 1 VP 2 PP 2 Address Translation 0 0 N-1 0 M-1 VP 1 VP 2 PP 7 PP 10 (e.g., read-only library code)... Virtual Address Space for Process 2:

21 CMSC313-F’09 IA32 Linux Memory Layout Stack Stack Runtime stack (8MB limit) Heap Heap Dynamically allocated storage When call malloc(), calloc(), new() Data Data Statically allocated data E.g., arrays & strings declared in code Text Text Executable machine instructions Read-only Upper 2 hex digits of address FF 00 Stack Text Data Heap 08 From class08.ppt

22 CMSC313-F’09 Simplifying Linking and Loading Kernel virtual memory Memory mapped region for shared libraries Run-time heap (created at runtime by malloc) User stack (created at runtime) Unused 0 %esp (stack ptr) Memory invisible to user code brk 0xc x x Read/write segment (.data,.bss ) Read-only segment (.init,.text,.rodata ) Loaded from executable file Linking Each program has similar virtual address space Code, stack, and shared libraries always start at the same address Loading execve() maps PTEs to the appropriate location in the executable binary file The.text and.data sections are copied, page by page, on demand by the virtual memory system.

23 CMSC313-F’09 (3)VM as a Tool for Memory Protection Extend PTEs with permission bits Page fault handler checks these before remapping If violated, send process SIGSEGV (segmentation fault) Page tables with permission bits Process i: AddressREADWRITE PP 6YesNo PP 4Yes PP 2Yes VP 0: VP 1: VP 2: Process j: PP 0 Physical memory Yes PP 4 PP 6 PP 9 SUP No Yes AddressREADWRITE PP 9YesNo PP 6Yes PP 11Yes SUP No Yes No VP 0: VP 1: VP 2: PP 2 PP 11

24 CMSC313-F’09 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 programming Simplifies protection by providing a convenient interpositioning point to check permissions