1 Virtual Memory. 2 Outline Virtual Space Address translation Accelerating translation –with a TLB –Multilevel page tables Different points of view Suggested.

Slides:



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

C SINGH, JUNE 7-8, 2010IWW 2010, ISATANBUL, TURKEY Advanced Computers Architecture, UNIT 2 Advanced Computers Architecture Virtual Memory By Rohit Khokher.
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 Chapter 8.
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
Virtual Memory October 2, 2000
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 Chapter 8.
Recitation 7 Greg Reshko Office Hours: Wed 2:00-3:00PM March 31 st, 2003.
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!”
– 1 – , F’02 Conventional DRAM Organization d x w DRAM: dw total bits organized as d supercells of size w bits cols rows internal row.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Virtual Memory: Concepts
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
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.
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!”
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.
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 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.
1 Virtual Memory. 2 Outline Case analysis –Pentium/Linux Memory System –Core i7 Suggested reading: 9.7.
Computer Architecture Lecture 12: Virtual Memory I
Virtual Memory Chapter 8.
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.
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!”
Instructors: Majd Sakr and Khaled Harras
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!”
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

2 Outline Virtual Space Address translation Accelerating translation –with a TLB –Multilevel page tables Different points of view Suggested reading: 10.1~10.6 TLB: Translation lookaside buffers

Physical and Virtual Addressing

4 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 Contiguous: 临近的

5 Physical Addressing Figure 10.1 P693

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

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

8 Figure 10.2 P694

Address Space

10 Address Space –An ordered set of nonnegative integer addresses Linear Space –The integers in the address space are consecutive N-bit address space

11 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 Practice Problem 10.1 P695

12 Address Space Data objects and their attributes –Bytes vs. addresses Each data object can have multiple independent addresses

VM as a Tool for Caching

14 Using Main Memory as a Cache P695 DRAM SRAM Disk

DRAM Cache Organization

16 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

17 Design Considerations Line size? –Large, since disk better at transferring large blocks Associativity? –High, to minimize miss rate Write through or write back? –Write back, since can’t afford to perform small writes to disk

Page Tables

19 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

20 Page P695 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) Also referred to as page frames

21 Page Attributes P695 1) 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.

22 Page Attributes 2) Cached: –Allocated pages that are currently cached in physical memory. 3) Uncached: –Allocated pages that are not cached in physical memory.

23 Page Figure 10.3 P696

24 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

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

26 Page Table Memory resident page table (physical page or disk address) Physical Memory Disk Storage (swap file or regular file system file) Valid Virtual Page Number

Page Hits

28 Page Hits Figure 10.5 P698 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

Page Faults

30 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. Suspend: 悬挂

31 Page Faults Swapping or paging Swapped out or paged out (from DRAM to Disk) Demand paging (Waiting until the last moment to swap in a page, when a miss occurs) CPU Memory Page Table Disk Virtual Addresses Physical Addresses CPU Memory Page Table Disk Virtual Addresses Physical Addresses Before fault After fault Figure 10.6 P699Figure 10.7 P699

32 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

33 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

34 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 Resumes: 再继续, 重新开始

Allocating Pages

36 Allocating Pages P700 The operating system allocates a new page of virtual memory, for example, as a result of calling malloc. Figure 10.8 P700

Locality to the Rescue Again Rescue: 解救

38 Locality P700 The principle of locality promises that at any point in time they will tend to work on a smaller set of active pages, known as working set or resident set. Initial overhead where the working set is paged into memory, subsequent references to the working set result in hits, with no additional disk traffic.

39 Locality-2 P700 If the working set size exceeds the size of physical memory, then the program can produce an unfortunate situation known as thrashing, where the pages are swapped in and out continuously. Thrash: 鞭打

VM as a Tool for Memory Management

41 A Tool for Memory Management Separate virtual address space –Each process has its own virtual address space Simplify linking, sharing, loading, and memory allocation

Simplifying Linking

43 A Tool for Memory 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: Figure 10.9 P701

44 A Tool for Memory Management kernel virtual memory Memory mapped region for shared libraries runtime heap (via malloc) program text (.text) initialized data (.data) uninitialized data (.bss) stack forbidden %esp memory invisible to user code the “brk” ptr Linux/x86 process memory image Figure P702 0xc xbfffffff 0x x

Simplifying Sharing

46 Simplifying Sharing In some instances, it is desirable for processes to share code and data. –The same operating system kernel code –Make calls to routines in the standard C library The operating system can arrange for multiple process to share a single copy of this code by mapping the appropriate virtual pages in different processes to the same physical pages

Simplifying Memory Allocation

48 Simplifying Memory Allocation A simple mechanism for allocating additional memory to user processes. Page table work.

Simplifying Loading

50 Simplifying Loading Load executable and shared object files into memory. Memory mapping……mmap

VM as a Tool for Memory Protection

52 A Tool for Memory Protection Page table entry contains access rights information –hardware enforces this protection (trap into OS if violation occurs)

53 A Tool for Memory Protection Page Tables Process i: Physical AddrRead?Write? PP 9YesNo PP 4Yes XXXXXXX No VP 0: VP 1: VP 2: Process j: 0: 1: N-1: Memory Physical AddrRead?Write? PP 6Yes PP 9YesNo XXXXXXX No VP 0: VP 1: VP 2:

54 A Tool for Memory Protection Figure P704

Address Translation

56 Address Translation Processor Hardware Addr Trans Mechanism fault handler Main Memory Secondary memory a a'  page fault physical address OS performs this transfer (only if miss) virtual addresspart of the on-chip memory mgmt unit (MMU)

57 Address Translation Figure P705 Parameters –P = 2 p = page size (bytes). –N = 2 n = Virtual address limit –M = 2 m = Physical address limit

58 Address Translation P705 virtual page numberpage offset virtual address physical page numberpage offset physical address 0p–1 address translation pm–1 n–10p–1p Notice that the page offset bits don't change as a result of translation

59 Address Translation via Page Table virtual page number (VPN)page offset virtual address physical page number (PPN)page offset physical address 0p–1pm–1 n–10p–1p page table base register (PTBR) if valid=0 then page not in memory valid physical page number (PPN) access VPN acts as table index Figure P705

Putting it Together: End-to-End Address Translation

61 Simple Memory System Example Addressing –14-bit virtual addresses –12-bit physical address –Page size = 64 bits VPO PPOPPN VPN (Virtual Page Number) (Virtual Page Offset) (Physical Page Number) (Physical Page Offset) Figure P712

62 Simple Memory System Page Table Only show first 16 entries VPNPPNValidVPNPPNValid – A B–0 04–00C– D2D1 06–00E111 07–00F0D1 Figure P712 (b)

63 Address Translation Example P714 Virtual Address 0x03D VPO VPN VPN: 0x0f Page Fault? No PPN: 0x0D VPO: 0x14 PA: 0x PPOPPN

64 Page Hits Figure (a) P706 VA: virtual address. PTEA: page table entry address. PTE: page table entry. PA: physical address.

65 Page Faults Figure (b) P706

Integrating Caches and VM

67 Integrating Caches and VM CPU Trans- lation Cache Main Memory VAPA miss hit data

68 Integrating Caches and VM Most Caches “Physically Addressed” –Accessed by physical addresses –Allows multiple processes to have blocks in cache at same time –Allows multiple processes to share pages –Cache doesn’t need to be concerned with protection issues Access rights checked as part of address translation

69 Integrating Caches and VM Perform Address Translation Before Cache Lookup –But this could involve a memory access itself (of the PTE) –Of course, page table entries can also become cached

70 Figure P708

Speeding up Address Translation with a TLB

72 Speeding up Translation with a TLB “Translation Lookaside Buffer” (TLB) –Small hardware cache in MMU –Maps virtual page numbers to physical page numbers

73 Figure (a) P709

74 Speeding up Translation with a TLB Figure P708

75 Speeding up Translation with a TLB virtual address virtual page number page offset physical address n–10p–1p validphysical page numbertag validtagdata = cache hit tagbyte offset index = TLB hit TLB Cache...

76 TLB –16 entries –4-way associative VPO VPN TLBI TLBT SetTagPPNValidTagPPNValidTagPPNValidTagPPNValid 003–0090D100– D102–004–00A–0 202–008–006–003–0 307–0030D10A34102–0 Simple Memory System TLB Figure (a) P712

77 Address Translation Example P714 Virtual Address 0x03D VPO VPN VPN: 0x0f TLBI: 0x03 TLBT: 0x03 TLB Hit? yes Page Fault? No PPN: 0x0D VPO: 0x14 PA: 0x PPOPPN

78 Simple Memory System Cache Cache –16 lines –4-byte line size –Direct mapped

79 Simple Memory System Cache PPOPPN CO CI CT IdxTagValidB0B1B2B3IdxTagValidB0B1B2B A ––––92D0–––– 21B A2D19315DA3B 3360––––B0B0–––– D8F09C120–––– 50D13672F01DD ––––E BD C2DF03F140–––– Figure (c) P713

80 Address Translation Example P714 PA: 0x PPOPPN CO CI CT Offset: 0x0 CI: 0x05 CT: 0x0D Hit? Yes Byte: 0x36

Multi Level Page Tables

82 Multi-Level Page Tables Given: –4KB (2 12 ) page size –32-bit address space –4-byte PTE Problem: –Would need a 4 MB page table! 2 20 *4 bytes

83 Multi-Level Page Tables Common solution –multi-level page tables –e.g., 2-level table (P6) Level 1 table: 1024 entries, each of which points to a Level 2 page table. Level 2 table: 1024 entries, each of which points to a page Level 1 Table... Level 2 Tables

84 Multi-Level Page Tables Figure P710

85 Multi-Level Page Tables Figure P711