Chap. 7.4: Virtual Memory. CS61C L35 VM I (2) Garcia © UCB Review: Caches Cache design choices: size of cache: speed v. capacity direct-mapped v. associative.

Slides:



Advertisements
Similar presentations
Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission.
Advertisements

1 Lecture 13: Cache and Virtual Memroy Review Cache optimization approaches, cache miss classification, Adapted from UCB CS252 S01.
Virtual Memory main memory can act as a cache for secondary storage motivation: Allow programs to use more memory that there is available transparent to.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
CSIE30300 Computer Architecture Unit 10: Virtual Memory Hsin-Chou Chi [Adapted from material by and
Virtual Memory Hardware Support
Cs 325 virtualmemory.1 Accessing Caches in Virtual Memory Environment.
Virtual Memory Adapted from lecture notes of Dr. Patterson and Dr. Kubiatowicz of UC Berkeley.
CS61C L35 VM I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
CSCE 212 Chapter 7 Memory Hierarchy Instructor: Jason D. Bakos.
CS61C L34 Virtual Memory I (1) Garcia, Spring 2007 © UCB 3D chips from IBM  IBM claims to have found a way to build 3D chips by stacking them together.
CS 61C L24 VM II (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
Virtual Memory Adapted from lecture notes of Dr. Patterson and Dr. Kubiatowicz of UC Berkeley and Rabi Mahapatra & Hank Walker.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 34 – Virtual Memory II Jim Cicconi of AT&T says that the surge of video.
Virtual Memory.
S.1 Review: The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of.
CS 61C L23 VM I (1) A Carle, Summer 2006 © UCB inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #23: VM I Andy Carle.
COMP3221 lec36-vm-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 13: Virtual Memory - I
Recap. The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of the.
CS 61C L24 VM II (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #24: VM II Andy Carle.
CS61C L25 Virtual Memory I (1) Beamer, Summer 2007 © UCB Scott Beamer, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #25.
COMP 3221: Microprocessors and Embedded Systems Lectures 27: Virtual Memory - II Lecturer: Hui Wu Session 2, 2005 Modified.
CS61C L19 VM © UC Regents 1 CS61C - Machine Structures Lecture 19 - Virtual Memory November 3, 2000 David Patterson
The Memory Hierarchy II CPSC 321 Andreas Klappenecker.
CS 61C L35 Caches IV / VM I (1) Garcia, Fall 2004 © UCB Andy Carle inst.eecs.berkeley.edu/~cs61c-ta inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
CS 61C L25 VM III (1) Garcia, Spring 2004 © UCB TA Chema González www-inst.eecs/~cs61c-td inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
CS61C L35 Virtual Memory II (1) Garcia, Spring 2007 © UCB Hardware repair?!  This technology allows you to “patch” your hardware after it has been installed.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 35 – Virtual Memory III Researchers at three locations have recently added.
ECE 232 L27.Virtual.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 27 Virtual.
CS61C L34 Virtual Memory II (1) Garcia, Fall 2006 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c UC Berkeley.
CS61C L36 VM II (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
CS61C L33 Virtual Memory I (1) Garcia, Fall 2006 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c UC Berkeley.
©UCB CS 162 Ch 7: Virtual Memory LECTURE 13 Instructor: L.N. Bhuyan
CS 430 – Computer Architecture 1 CS 430 – Computer Architecture Virtual Memory William J. Taffe using slides of David Patterson.
Cs 61C L18 Cache2.1 Patterson Spring 99 ©UCB CS61C Improving Cache Memory and Virtual Memory Introduction Lecture 18 April 2, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 33 – Virtual Memory I OCZ has released a 1 TB solid state drive (the biggest.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy (Part II)
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 34 – Virtual Memory II Researchers at Stanford have developed “nanoscale.
©UCB CS 161 Ch 7: Memory Hierarchy LECTURE 24 Instructor: L.N. Bhuyan
COMP3221 lec37-vm-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 13: Virtual Memory - II
CS61C L37 VM III (1)Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
Lecture 33: Chapter 5 Today’s topic –Cache Replacement Algorithms –Multi-level Caches –Virtual Memories 1.
CS 61C L7.1.2 VM II (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture VM II Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
Lecture 19: Virtual Memory
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
1  1998 Morgan Kaufmann Publishers Recap: Memory Hierarchy of a Modern Computer System By taking advantage of the principle of locality: –Present the.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 35 – Virtual Memory III ”The severity of the decline in the market is further evidence.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
Review (1/2) °Caches are NOT mandatory: Processor performs arithmetic Memory stores data Caches simply make data transfers go faster °Each level of memory.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
1  2004 Morgan Kaufmann Publishers Chapter Seven Memory Hierarchy-3 by Patterson.
Csci 136 Computer Architecture II – Virtual Memory
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
3/1/2002CSE Virtual Memory Virtual Memory CPU On-chip cache Off-chip cache DRAM memory Disk memory Note: Some of the material in this lecture are.
CS203 – Advanced Computer Architecture Virtual Memory.
CS161 – Design and Architecture of Computer
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
Lecture 12 Virtual Memory.
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.
Morgan Kaufmann Publishers
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Review (1/2) Caches are NOT mandatory:
Csci 211 Computer System Architecture – Review on Virtual Memory
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSC3050 – Computer Architecture
Albert Chae, Instructor
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

Chap. 7.4: Virtual Memory

CS61C L35 VM I (2) Garcia © UCB Review: Caches Cache design choices: size of cache: speed v. capacity direct-mapped v. associative for N-way set assoc: choice of N block replacement policy 2nd level cache? Write through v. write back? Use performance model to pick between choices, depending on programs, technology, budget,...

CS61C L35 VM I (3) Garcia © UCB Another View of the Memory Hierarchy Regs L2 Cache Memory Disk Tape Instr., Operands Blocks Pages Files Upper Level Lower Level Faster Larger Cache Blocks Thus far { { Next: Virtual Memory

Recall: illusion of memory Programmer ’ s view about memory Unlimited amount of fast memory How to create the above illusion? 無限大的快速記憶體 Scene: library Book shelf desk books

Virtual memory 虛擬記憶體 Create an illusion of unlimited memory Motivation A collection of programs running at once on a machine Total memory required by all programs > the amount of main memory available Allow a single user program to exceed the size of primary memory Software solution: programmers divided programs into pieces, called overlays 多個程式同時執行,大於主記憶體 單一程式大於主記憶體

Process The state of a program is called a process State of a program: Program counter (PC), registers, page table, … To allow another program to use the CPU, we must save this state Context switching OS (operating system) changes from running process P1 to running process P2 行程

CS61C L35 VM I (7) Garcia © UCB Simple Example: Base and Bound Reg 0  OS User A User B User C $base $base+ $bound Want discontinuous mapping Process size >> mem Addition not enough! => What to do? Enough space for User D, but discontinuous (“fragmentation problem”)

Virtual memory system Main memory as a cache for the secondary storage (disk) cache Disk Cache for disk How to map to disk?

More about Virtual Memory Called “ Virtual Memory ” Also allows OS to share memory, protect programs from each other Today, more important for protection vs. just another level of memory hierarchy Each process thinks it has all the memory to itself Historically, it predates caches

CS61C L35 VM I (10) Garcia © UCB Mapping Virtual Memory to Physical Memory 0 Physical Memory  Virtual Memory CodeStatic Heap Stack 64 MB Divide into equal sized chunks (about 4 KB - 8 KB) 0 Any chunk of Virtual Memory assigned to any chuck of Physical Memory (“page”)

CS61C L35 VM I (11) Garcia © UCB Paging Organization (assume 1 KB pages) Addr Trans MAP Page is unit of mapping page 0 1K Virtual Memory Virtual Address page 1 page 31 1K 2048 page 2... page Physical Address Physical Memory 1K page 1 page 7...

VM address translation (1) Page size=2 12 Virtual address Physical address Address space=2 32 =4GB Address space=2 30 =1GB How to translate virtual addresses ? Ans: Direct mapped, set-associative, full-associative?

VM address translation (2) Each program has its own page table 2 20 Address translation: Full-associative

CS61C L35 VM I (14) Garcia © UCB Paging/Virtual Memory Multiple Processes User B: Virtual Memory  Code Static Heap Stack 0 Code Static Heap Stack A Page Table B Page Table User A: Virtual Memory  0 0 Physical Memory 64 MB

Page fault (~cache miss) Virtual Page number

Key issues in VM Page fault penalty takes millions of cycles Pages should be large enough to amortize the high access time 32-64KB Reduce the page fault rate: full-associative placement Use clever algorithm to replace pages while page faults occur LRU (least recently used) ? Use write-back instead of write-through

Make the address translation faster Motivation: page tables are stored in main memory Load/store virtual address Page table Physical address In memory Main memory data 2 memory accesses !!! Use a cache to store page table

Translation-lookaside buffer (TLB) TLB miss

CS61C L35 VM I (19) Garcia © UCB VM, TLB, and cache TLBs usually small, typically entries Like any other cache, the TLB can be direct mapped, set associative, or fully associative Processor VA Cache miss hit data TLB Lookup PA hit miss Main Memory Trans- lation On TLB miss, get page table entry from main memory

VM, TLB, and caches … … 1 0 Virtual address TLB cache

Protection with Virtual memory VM allows the sharing of a single main memory by multiple processes OS place the page tables in the address space of OS Independent virtual pages map to disjoint physical page User process can not change the page table mapping

CS61C L35 VM I (22) Garcia © UCB Comparing the 2 levels of hierarchy Cache VersionVirtual Memory vers. Block or LinePage MissPage Fault Block Size: 32-64BPage Size: 4K-8KB Placement:Fully Associative Direct Mapped, N-way Set Associative Replacement: Least Recently Used LRU or Random(LRU) Write Thru or BackWrite Back

CS61C L36 VM II (23)Garcia © UCB Review: 4 Qs for any Memory Hierarchy °Q1: Where can a block be placed? One place (direct mapped) A few places (set associative) Any place (fully associative) °Q2: How is a block found? Indexing (as in a direct-mapped cache) Limited search (as in a set-associative cache) Full search (as in a fully associative cache) Separate lookup table (as in a page table) °Q3: Which block is replaced on a miss? Least recently used (LRU) Random °Q4: How are writes handled? Write through (Level never inconsistent w/lower) Write back (Could be “dirty”, must have dirty bit)

CS61C L36 VM II (24)Garcia © UCB °Block 12 placed in 8 block cache: Fully associative Direct mapped 2-way set associative -Set Associative Mapping = Block # Mod # of Sets Block no. Fully associative: block 12 can go anywhere Block no. Direct mapped: block 12 can go only into block 4 (12 mod 8) Block no. Set associative: block 12 can go anywhere in set 0 (12 mod 4) Set 0 Set 1 Set 2 Set 3 Q1: Where block placed in upper level?

CS61C L36 VM II (25)Garcia © UCB °Direct indexing (using index and block offset), tag compares, or combination °Increasing associativity shrinks index, expands tag Block offset Block Address Tag Index Q2: How is a block found in upper level? Set Select Data Select

CS61C L36 VM II (26)Garcia © UCB °Easy for Direct Mapped °Set Associative or Fully Associative: Random LRU (Least Recently Used) Miss Rates Associativity:2-way 4-way 8-way SizeLRU Ran LRU Ran LRU Ran 16 KB5.2%5.7% 4.7%5.3% 4.4%5.0% 64 KB1.9%2.0% 1.5%1.7% 1.4%1.5% 256 KB1.15%1.17% 1.13% 1.13% 1.12% 1.12% Q3: Which block replaced on a miss?

CS61C L36 VM II (27)Garcia © UCB Q4: What to do on a write hit? °Write-through update the word in cache block and corresponding word in memory °Write-back update word in cache block allow memory word to be “stale” => add ‘dirty’ bit to each line indicating that memory be updated when block is replaced => OS flushes cache before I/O !!! °Performance trade-offs? WT: read misses cannot result in writes WB: no writes of repeated writes

Short conclusion of VM Virtual memory Cache between memory and disk VM allows A program to expand its address space Sharing of main memory among multiple processes To reduce page fault Large pages – use spatial locality Full associative mapping OS use clever replacement method (LRU, … )