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.

Slides:



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

COMP381 by M. Hamdi 1 Virtual Memory. COMP381 by M. Hamdi 2 Virtual Memory: The Problem For example: MIPS64 is a 64-bit architecture allowing an address.
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 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.
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!”
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 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.
Processes and 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 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.
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 Alan L. Cox Some slides adapted from CMU slides.
Computer Architecture Lecture 12: Virtual Memory I
Virtual Memory Chapter 8.
CS 704 Advanced Computer Architecture
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.
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!”
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
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!”
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:

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 for Memory Protection Suggested reading: 9.1~9.5

3 Physical Addressing Attributes of the main memory –Organized as an array of M contiguous byte-sized cells –Each byte has a unique physical address (PA) started from 0 physical addressing –A CPU use physical addresses to access memory Examples –Early PCs, DSP, embedded microcontrollers, and Cray supercomputers

4 A 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

5 Virtual Addressing Virtual addressing –the CPU accesses main memory by a virtual address (VA) The virtual address is converted to the appropriate physical address

6 Virtual Addressing Address translation –Converting a virtual address to a physical address –Requires close cooperation between the CPU hardware and the operating system HW: the memory management unit (MMU) –Dedicated hardware on the CPU chip to translate virtual addresses on the fly SW: A look-up table –Stored in main memory –Contents are managed by the operating system

7 A 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

8 Address Space –An ordered set of nonnegative integer addresses Linear Space –The integers in the address space are consecutive Linear address space: Ordered set of contiguous non-negative integer addresses: {0, 1, 2, 3 … }

9 Address Space N-bit Address Space –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 –one physical address, one (or more) virtual addresses

10 Address Space K=2 10 (Kilo), M=2 20 (Mega), G=2 30 (Giga), T=2 40 (Tera), P=2 50 (Peta), E=2 60 (Exa) #virtual address bits (n) #virtual address (N) Largest possible virtual address 8 64K T K-1 4G4G E16E-1 256T-1

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

12 Using Main Memory as a Cache DRAM SRAM Disk

13 Using Main Memory as a Cache DRAM vs. disk is more extreme than SRAM vs. DRAM –Access latencies: DRAM ~10X slower than SRAM Disk ~100,000X slower than DRAM –Bottom line: Design decisions made for DRAM caches driven by enormous cost of misses

14 Design Considerations Line size? (Large vs. Small) –Large, since disk better at transferring large blocks Associativity? (Full vs. Direct) –Full, to minimize miss rate Write through or write back? (WB vs. WT) –Write back, since can’t afford to perform small writes to disk

15 Page Virtual memory –Organized as an array of contiguous byte-sized cells stored on disk conceptually. –Each byte has a unique virtual address that serves as an index into the array –The contents of the array on disk are cached in main memory

16 Page The data on disk is partitioned into blocks –Serve as the transfer units between the disk and the main memory –virtual pages (VPs) –physical pages (PPs) or page frames 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

17 Page Attributes Unallocated: –Pages that have not yet been allocated (or created) by the VM system –Do not have any data associated with them –Do not occupy any space on disk.

18 Page Attributes Cached: –Allocated pages that are currently cached in physical memory. Uncached: –Allocated pages that are not cached in physical memory.

19 Page Table Each allocate page of virtual memory has entry in page table Mapping from virtual pages to physical pages –From uncached form to cached form Page table entry even if page not in memory –Specifies disk address OS retrieves information

20 Page Table Data : 1: N-1: X Object Name Location D: J: X:1 0 On Disk “Cache”Page Table

21 Page Table NULL Memory resident page table (physical page or disk address) Physical Memory Disk Storage (swap file or regular file system file) Valid Virtual Page Number PTE0 PTE9 PP0 PP5 VP4 VP1 VP2

22 Page Hits Memory Address Translation: Hardware converts virtual addresses to physical addresses via an OS-managed lookup table (page table) CPU 0: 1: N-1: 0: 1: P-1: Page Table Disk Virtual Addresses Physical Addresses

23 Page Faults Page table entry indicates virtual address not in memory OS exception handler invoked to move data from disk into memory –current process suspends, others can resume –OS has full control over placement, etc.

24 Page Faults Swapping or paging Swapped out or paged out Demand paging CPU Memory Page Table Disk Virtual Addresses Physical Addresses CPU Memory Page Table Disk Virtual Addresses Physical Addresses Before fault After fault

25 Servicing a Page Fault Processor Signals Controller –Read block of length P starting at disk address X and store starting at memory address Y disk Disk disk Disk Memory-I/O bus Processor Cache Memory I/O controller I/O controller Reg (1) Initiate Block Read

26 Servicing a Page Fault Read Occurs –Direct Memory Access (DMA) –Under control of I/O controller disk Disk disk Disk Memory-I/O bus Processor Cache Memory I/O controller I/O controller Reg (2) DMA Transfer

27 Servicing a Page Fault I / O Controller Signals Completion –Interrupt processor –OS resumes suspended process disk Disk disk Disk Memory-I/O bus Processor Cache Memory I/O controller I/O controller Reg (3) Read Done

Locality to the Rescue Again! 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

Locality to the Rescue Again! 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

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

VM as a Tool for Memory Management Key idea: each process has its own virtual address space –It can view memory as a simple linear array 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

VM as a Tool for Memory Management 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 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

VM as a Tool for Memory Management Sharing code and data among processes –Map virtual pages to the same physical page (e.g. 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

Simplifying Linking and Loading Linking –Each program has similar virtual address space –Code, stack, and shared libraries always start at the same address Kernel virtual memory Memory-mapped region for shared libraries Run-time heap (created by malloc ) User stack (created at runtime) Unused 0 %esp (stack pointer) Memory invisible to user code brk 0xc x x Read/write segment (. data,. bss ) Read-only segment (.init,. text,.rodata ) Loaded from the executable file

Simplifying Linking and Loading Loading –execve() allocates virtual pages for.text and.data sections = creates PTEs marked as invalid –The.text and.data sections are copied, page by page, on demand by the virtual memory system Kernel virtual memory Memory-mapped region for shared libraries Run-time heap (created by malloc ) User stack (created at runtime) Unused 0 %esp (stack pointer) Memory invisible to user code brk 0xc x x Read/write segment (. data,. bss ) Read-only segment (.init,. text,.rodata ) Loaded from the executable file

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

VM as a Tool for Memory Protection Extend PTEs with permission bits –The same physical page has different permission for different process 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

VM as a Tool for Memory Protection 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