Carnegie Mellon 1 Saint Louis University Virtual Memory CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant.

Slides:



Advertisements
Similar presentations
Virtual Memory October 25, 2006 Topics Address spaces Motivations for virtual memory Address translation Accelerating translation with TLBs class16.ppt.
Advertisements

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 Oct. 21, 2003 Topics Motivations for VM Address translation Accelerating translation with TLBs class17.ppt “The course that gives.
Virtual Memory Nov 27, 2007 Slide Source: Topics Motivations for VM Address translation Accelerating translation with TLBs class12.ppt.
Virtual Memory Topics Motivations for VM Address translation Accelerating translation with TLBs CS213.
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 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
Virtual & Dynamic Memory Management Summer 2014 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University.
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.
Carnegie Mellon 1 Odds and Ends Intro to x86-64 Memory Layout.
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.  Next in memory hierarchy  Motivations:  to remove programming burdens of a small, limited amount of main memory  to allow efficient.
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!”
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 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.
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.
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.
1 Virtual Memory. 2 Outline Case analysis –Pentium/Linux Memory System –Core i7 Suggested reading: 9.7.
Virtual Memory Samira Khan Apr 25, 2017.
Section 9: Virtual Memory (VM)
Virtual Memory: Systems
Section 9: Virtual Memory (VM)
Today How was the midterm review? Lab4 due today.
Virtual Memory: Concepts CENG331 - Computer Organization
CS 704 Advanced Computer Architecture
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.
Virtual Memory: Systems
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory II CSE 410 Winter 2017
CSE 351 Section 10 The END…Almost 3/7/12
ECE Dept., University of Toronto
Instructors: Majd Sakr and Khaled Harras
Pentium III / Linux Memory System April 4, 2000
Virtual Memory Nov 27, 2007 Slide Source:
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
Instructor: Phil Gibbons
Presentation transcript:

Carnegie Mellon 1 Saint Louis University Virtual Memory CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O’Hallaron’s slides

Carnegie Mellon 2 Saint Louis University Data Representation in Memory Memory organization within a process Virtual vs. Physical memory  Fundamental Idea and Purpose  Page Mapping  Address Translation  Per-Process Mapping and Protection

Carnegie Mellon 3 Saint Louis University Recall: Basic Memory Organization Byte-Addressable Memory  Conceptually a very large array, with a unique address for each byte  Processor width determines address range:  32-bit processor has 2 32 unique addresses  64-bit processor has 2 64 unique addresses Where does a given process reside in memory?  depends upon the perspective… –virtual memory:process can use most any virtual address –physical memory:location controlled by OS 0x0000xFFF

Carnegie Mellon 4 Saint Louis University Virtual Address Space for IA32 (x86) Linux All processes have the same uniform view of memory Stack  Runtime stack (8MB limit)  E. g., local variables Heap  Dynamically allocated storage  When call malloc(), calloc(), new() Data  Statically allocated data  E.g., global variables, arrays, structures, etc. Text  Executable machine instructions  Read-only data 0xFFFFFFFF 0x Stack Text Data Heap 0x MB not drawn to scale

Carnegie Mellon 5 Saint Louis University Memory Allocation Example char big_array[1<<24]; /* 16 MB */ char huge_array[1<<28]; /* 256 MB */ int beyond; char *p1, *p2, *p3, *p4; int useless() { return 0; } int main() { p1 = malloc(1 <<28); /* 256 MB */ p2 = malloc(1 << 8); /* 256 B */ p3 = malloc(1 <<28); /* 256 MB */ p4 = malloc(1 << 8); /* 256 B */ /* Some print statements... */ } Stack Text Data Heap not drawn to scale Where does everything go? 0xFF…F 0x00…0 0x08…0

Carnegie Mellon 6 Saint Louis University Addresses in IA32 (x86) $esp0xffffbcd0 p3 0x p1 0x p40x1904a110 p20x1904a008 &p20x &beyond 0x big_array 0x huge_array 0x main()0x080483c6 useless() 0x address range ~2 32 Stack Text Data Heap not drawn to scale malloc() is dynamically linked address determined at runtime 0xFFFFFFFF 0x x x

Carnegie Mellon 7 Saint Louis University Addresses in x86-64 $rsp0x00007ffffff8d1f8 p3 0x00002aaabaadd010 p1 0x00002aaaaaadc010 p40x p20x &p20x a60 &beyond 0x a44 big_array 0x a80 huge_array 0x a50 main()0x useless() 0x address range ~2 47 0x00007F…F 0x000000…0 Stack Text Data Heap 0x000030…0 not drawn to scale malloc() is dynamically linked address determined at runtime

Carnegie Mellon 8 Saint Louis University Detailed Virtual Address Space for a Linux Process Kernel code and data Shared libraries Runtime heap ( malloc(), etc. ) Program code (.init,.text) Initialized data (.data) Uninitialized data (.bss) User stack 0 % esp Process virtual memory brk Kernel virtual memory 0x (32) 0x (64) Read-only data (.rodata)

Carnegie Mellon 9 Saint Louis University Data Representation in Memory Memory organization within a process Virtual vs. Physical memory  Fundamental Idea and Purpose  Page Mapping  Address Translation  Per-Process Mapping and Protection

Carnegie Mellon 10 Saint Louis University Contrast: System Using Physical Addressing Used in “simple” systems like 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) Data word 8:... 4

Carnegie Mellon 11 Saint Louis University Contrast: System Using Virtual Addressing Used in all modern servers, desktops, and laptops 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

Carnegie Mellon 12 Saint Louis University Address Spaces Linear address space: Ordered set of contiguous non-negative integer addresses: {0, 1, 2, 3 … } Virtual address space: Set of N = 2 n virtual addresses {0, 1, 2, 3, …, N-1} Physical address space: Set of M = 2 m physical addresses {0, 1, 2, 3, …, M-1} Clean distinction between data (bytes) and their attributes (addresses) Each object can now have multiple addresses Every byte in main memory: one physical address; one (or more) virtual addresses

Carnegie Mellon 13 Saint Louis University Why Virtual Memory (VM)? Uses main memory efficiently  Use DRAM as a cache for the parts of a virtual address space Simplifies memory management  Each process gets the same uniform linear address space Isolates address spaces  One process can’t interfere with another’s memory  User program cannot access privileged kernel information

Carnegie Mellon 14 Saint Louis University Data Representation in Memory Memory organization within a process Virtual vs. Physical memory  Fundamental Idea and Purpose  Page Mapping  Address Translation  Per-Process Mapping and Protection

Carnegie Mellon 15 Saint Louis University VM as a Tool for Caching Virtual memory – array of N contiguous bytes stored on disk. The contents of the array on disk are cached in physical memory (DRAM cache)  These cache blocks are called pages (size is P = 2 p bytes) 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 (VPs) stored on disk Physical pages (PPs) cached in DRAM

Carnegie Mellon 16 Saint Louis University DRAM as a Cache for Disk Disk has enormous miss penalty  DRAM is only about 10x slower than SRAM  Disk is much slower than DRAM: about 10,000x slower Consequences  Highly sophisticated algorithms used for organizing DRAM effectively  cache memory has relatively simple mechanisms  Large page (block) size: typically 4-8 KB, sometimes 4 MB  Fully associative  any VP can be placed in any PP

Carnegie Mellon 17 Saint Louis University 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

Carnegie Mellon 18 Saint Louis University Page Hit Page hit:  reference to VM word that is in physical memory (DRAM cache hit) 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 Virtual address

Carnegie Mellon 19 Saint Louis University Page Fault Page fault:  reference to VM word that is not in physical memory (DRAM miss) 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 Virtual address

Carnegie Mellon 20 Saint Louis University Handling Page Fault Page miss causes page fault (an 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 VP 3 Virtual address

Carnegie Mellon 21 Saint Louis University Handling Page Fault Page miss causes page fault (an exception) Page fault handler selects a victim to be evicted (here VP 4) 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 Virtual address

Carnegie Mellon 22 Saint Louis University Handling Page Fault Page miss causes page fault (an exception) Page fault handler selects a victim to be evicted (here VP 4) 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 VP 3 Virtual address

Carnegie Mellon 23 Saint Louis University Handling Page Fault Page miss causes page fault (an exception) Page fault handler selects a victim to be evicted (here VP 4) Offending instruction is restarted: page hit! 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 VP 3 Virtual address

Carnegie Mellon 24 Saint Louis University Data Representation in Memory Memory organization within a process Virtual vs. Physical memory  Fundamental Idea and Purpose  Page Mapping  Address Translation  Per-Process Mapping and Protection

Carnegie Mellon 25 Saint Louis University VM Address Translation Virtual Address Space  V = {0, 1, …, N–1} Physical Address Space  P = {0, 1, …, M–1} Address Translation  map: V  P U {  }  For virtual address a:  map(A) = A’ if virtual address A stored in physical address A’ of P  map(A) =  if data at virtual address A is not in physical memory –Either invalid or stored on disk

Carnegie Mellon 26 Saint Louis University Simple Memory System Example Addressing  14-bit virtual addresses  12-bit physical address  Page size = 64 bytes = 2 6 (6-bit page offset addr) VPO PPOPPN VPN Virtual Page Number Virtual Page Offset Physical Page Number Physical Page Offset

Carnegie Mellon 27 Saint Louis University Simple Memory System Page Table Only show first 16 entries (out of 256) 10D0F 1110E 12D0D 0–0C 0–0B 1090A ValidPPNVPN 0–07 0– – – ValidPPNVPN

Carnegie Mellon 28 Saint Louis University Address Translation Example #1 Virtual Address: 0x0020 VPN _____Page Table:Valid? ___PPN: ____Location:____________ Physical Address VPO VPN PPO PPN x00Y0x Main Memory

Carnegie Mellon 29 Saint Louis University Address Translation Example #2 Virtual Address: 0x0256 VPN _____Page Table:Valid? ___PPN: ____Location:____________ Physical Address VPO VPN PPO PPN x09Y0x Main Memory

Carnegie Mellon 30 Saint Louis University Data Representation in Memory Memory organization within a process Virtual vs. Physical memory  Fundamental Idea and Purpose  Page Mapping  Address Translation  Per-Process Mapping and Protection

Carnegie Mellon 31 Saint Louis University VM as a Tool for Memory Management Key idea:each process has its own virtual address space  viewed as a simple linear array  mapping function scatters addresses through physical memory Can share code and data among processes  Map virtual pages to the same physical page (here: PP 6) 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

Carnegie Mellon 32 Saint Louis University 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) Process i: AddressREADWRITE PP 6YesNo PP 4Yes PP 2Yes VP 0: VP 1: VP 2: Process j: Yes SUP No Yes AddressREADWRITE PP 9YesNo PP 6Yes PP 11Yes SUP No Yes No VP 0: VP 1: VP 2: Physical Address Space PP 2 PP 4 PP 6 PP 8 PP 9 PP 11