CPE432 Chapter 5A.1Dr. W. Abu-Sufah, UJ Chapter 5B:Virtual Memory Adapted from Slides by Prof. Mary Jane Irwin, Penn State University Read Section 5.4,

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.
CSE431 Chapter 5B.1Irwin, PSU, 2008 CSE 431 Computer Architecture Fall 2008 Chapter 5B: Exploiting the Memory Hierarchy, Part 2 Mary Jane Irwin (
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
CPEG3231 Virtual Memory. CPEG3232 Review: The memory hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory.
Virtual Memory Hardware Support
Caching IV Andreas Klappenecker CPSC321 Computer Architecture.
Cs 325 virtualmemory.1 Accessing Caches in Virtual Memory Environment.
The Memory Hierarchy (Lectures #24) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer Organization.
Virtual Memory Adapted from lecture notes of Dr. Patterson and Dr. Kubiatowicz of UC Berkeley.
CSCE 212 Chapter 7 Memory Hierarchy Instructor: Jason D. Bakos.
1 Lecture 20 – Caching and Virtual Memory  2004 Morgan Kaufmann Publishers Lecture 20 Caches and 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.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
Review CPSC 321 Andreas Klappenecker Announcements Tuesday, November 30, midterm exam.
Recap. The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of the.
1 Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
The Memory Hierarchy II CPSC 321 Andreas Klappenecker.
ECE 232 L27.Virtual.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 27 Virtual.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
©UCB CS 162 Ch 7: Virtual Memory LECTURE 13 Instructor: L.N. Bhuyan
1  2004 Morgan Kaufmann Publishers Chapter Seven.
1 SRAM: –value is stored on a pair of inverting gates –very fast but takes up more space than DRAM (4 to 6 transistors) DRAM: –value is stored as a charge.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy (Part II)
11/10/2005Comp 120 Fall November 10 8 classes to go! questions to me –Topics you would like covered –Things you don’t understand –Suggestions.
1 CSE SUNY New Paltz Chapter Seven Exploiting Memory Hierarchy.
Lecture 33: Chapter 5 Today’s topic –Cache Replacement Algorithms –Multi-level Caches –Virtual Memories 1.
CPE432 Chapter 5A.1Dr. W. Abu-Sufah, UJ Chapter 5A: Exploiting the Memory Hierarchy, Part 1 Adapted from Slides by Prof. Mary Jane Irwin, Penn State University.
Caching & Virtual Memory Systems Chapter 7  Caching l To address bottleneck between CPU and Memory l Direct l Associative l Set Associate  Virtual Memory.
CSE431 L22 TLBs.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 22. Virtual Memory Hardware Support Mary Jane Irwin (
Lecture 19: Virtual Memory
Lecture 15: Virtual Memory EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer Engineering Spring 2014, Dr.
Lecture 10 Memory Hierarchy and Cache Design Computer Architecture COE 501.
CS 224 Spring 2011 Chapter 5B Computer Organization CS224 Chapter 5B: Exploiting the Memory Hierarchy, Part 2 Spring 2011 With thanks to M.J. Irwin, D.
CSIE30300 Computer Architecture Unit 08: Cache Hsin-Chou Chi [Adapted from material by and
1 Virtual Memory Main memory can act as a cache for the secondary storage (disk) Advantages: –illusion of having more physical memory –program relocation.
1  1998 Morgan Kaufmann Publishers Recap: Memory Hierarchy of a Modern Computer System By taking advantage of the principle of locality: –Present the.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
Virtual Memory Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University.
Computer Organization CS224 Fall 2012 Lessons 45 & 46.
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
CS.305 Computer Architecture Memory: Caches Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available.
CPE232 Cache Introduction1 CPE 232 Computer Organization Spring 2006 Cache Introduction Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin.
1 Chapter Seven CACHE MEMORY AND VIRTUAL MEMORY. 2 SRAM: –value is stored on a pair of inverting gates –very fast but takes up more space than DRAM (4.
1  2004 Morgan Kaufmann Publishers Chapter Seven Memory Hierarchy-3 by Patterson.
CS.305 Computer Architecture Memory: Virtual Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available.
1  1998 Morgan Kaufmann Publishers Chapter Seven.
Memory Hierarchy and Caches. Who Cares about Memory Hierarchy? Processor Only Thus Far in Course CPU-DRAM Gap 1980: no cache in µproc; level cache,
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”
Summary of caches: The Principle of Locality: –Program likely to access a relatively small portion of the address space at any instant of time. Temporal.
1 Chapter Seven. 2 SRAM: –value is stored on a pair of inverting gates –very fast but takes up more space than DRAM (4 to 6 transistors) DRAM: –value.
CS203 – Advanced Computer Architecture Virtual Memory.
CS161 – Design and Architecture of Computer
CMSC 611: Advanced Computer Architecture
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
Lecture 12 Virtual Memory.
Virtual Memory.
CS 704 Advanced Computer Architecture
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.
Chapter 4 Large and Fast: Exploiting Memory Hierarchy Part 2 Virtual Memory 박능수.
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Virtual Memory 4 classes to go! Today: Virtual Memory.
CPE 631 Lecture 05: Cache Design
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Virtual Memory Overcoming main memory size limitation
CSC3050 – Computer Architecture
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
Presentation transcript:

CPE432 Chapter 5A.1Dr. W. Abu-Sufah, UJ Chapter 5B:Virtual Memory Adapted from Slides by Prof. Mary Jane Irwin, Penn State University Read Section 5.4, 5.6, 5.12

CPE432 Chapter 5A.2Dr. W. Abu-Sufah, UJ How is the Hierarchy Managed?  registers  memory l by compiler (programmer?)  cache  main memory l by the cache controller hardware  main memory  disks l by the operating system (virtual memory) l virtual to physical address mapping assisted by the hardware (TLB) l by the programmer (files)

CPE432 Chapter 5A.3Dr. W. Abu-Sufah, UJ Review: The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of the memory at each level Inclusive– what is in L1$ is a subset of what is in L2$ is a subset of what is in MM that is a subset of is in SM 4-8 bytes (word) 1 to 4 blocks 1,024+ bytes (disk sector = page) 8-32 bytes (block)  Take advantage of the principle of locality to present the user with as much memory as is available in the cheapest technology at the speed offered by the fastest technology

CPE432 Chapter 5A.4Dr. W. Abu-Sufah, UJ Virtual Memory  Use main memory as a “cache” for secondary memory l Allows efficient and safe sharing of memory among multiple programs l Provides the ability to easily run programs larger than the size of physical memory l Simplifies loading a program for execution by providing for code relocation (i.e., the code can be loaded anywhere in main memory)  What makes it work? – again the Principle of Locality l A program is likely to access a relatively small portion of its address space during any period of time

CPE432 Chapter 5A.5Dr. W. Abu-Sufah, UJ Virtual Memory (cont.)  Each program is compiled into its own address space – a “virtual” address space l During run-time each virtual address must be translated to a physical address (an address in main memory)

CPE432 Chapter 5A.6Dr. W. Abu-Sufah, UJ Two Programs Sharing Physical Memory Program 1 virtual address space main memory  A program’s address space is divided into pages (all one fixed size) or segments (variable sizes) l The starting location of each page (either in main memory or in secondary memory) is contained in the program’s page table Program 2 virtual address space

CPE432 Chapter 5A.7Dr. W. Abu-Sufah, UJ Address Translation Virtual Address (VA) Page offsetVirtual page number Page offsetPhysical page number Physical Address (PA) Translation  So each memory request first requires an address translation from the virtual space to the physical space l A virtual memory miss (i.e., when the page is not in physical memory) is called a page fault  A virtual address is translated to a physical address by a combination of hardware and software

CPE432 Chapter 5A.8Dr. W. Abu-Sufah, UJ Address Translation Mechanisms Base Address of Physical Page Main memory Disk storage Virtual page # V Page Table (in main memory) Offset Physical page # Offset Page table register

CPE432 Chapter 5A.9Dr. W. Abu-Sufah, UJ Virtual Addressing with a Cache  Thus it takes an extra memory access to translate a VA to a PA CPU Trans- lation Cache Main Memory VAPA miss hit data  This makes memory accesses very expensive (if every access was really two accesses)  The hardware fix is to use a Translation Lookaside Buffer (TLB) – a small cache that keeps track of recently used address mappings to avoid having to do a page table lookup

CPE432 Chapter 5A.10Dr. W. Abu-Sufah, UJ Making Address Translation Fast Base Address of Physical Page Main memory Disk storage Virtual page # V TagV TLB Page Table (in physical memory) Page table register Base Address of Physical Page

CPE432 Chapter 5A.11Dr. W. Abu-Sufah, UJ Translation Lookaside Buffers (TLBs)  Just like any other cache, the TLB can be organized as fully associative, set associative, or direct mapped V Virtual Page # Physical Page # Dirty Ref Access  TLB access time is typically smaller than cache access time (because TLBs are much smaller than caches) l TLBs are typically not more than 512 entries even on high end machines

CPE432 Chapter 5A.12Dr. W. Abu-Sufah, UJ A TLB in the Memory Hierarchy  A TLB miss – is it a page fault or merely a TLB miss? l If the page is loaded into main memory, then the TLB miss can be handled by loading the translation information from the page table into the TLB -Takes 10’s of cycles to find and load the translation info into the TLB CPU TLB Lookup Cache Main Memory VAPA miss hit data Trans- lation hit miss ¾ t ¼ t Page Table in Main Memory

CPE432 Chapter 5A.13Dr. W. Abu-Sufah, UJ A TLB in the Memory Hierarchy  A TLB miss – is it a page fault or merely a TLB miss? l If the page is not in main memory, then it’s a true page fault -Takes 1,000,000’s of cycles to service a page fault  TLB misses are much more frequent than true page faults CPU TLB Lookup Cache Main Memory VAPA miss hit data Trans- lation hit miss ¾ t ¼ t Page Table in Main Memory

CPE432 Chapter 5A.14Dr. W. Abu-Sufah, UJ TLB Event Combinations TLBPage Table CachePossible? Under what circumstances? Hit Miss Hit MissHitMiss HitMissMiss/ Hit Miss Hit Yes – what we want! Yes – although the page table is not checked if the TLB hits Yes – TLB miss, PA in page table Yes – TLB miss, PA in page table, but data not in cache Yes – page fault Impossible – TLB translation not possible if page is not present in memory Impossible – data not allowed in cache if page is not in memory

CPE432 Chapter 5A.15Dr. W. Abu-Sufah, UJ Some Virtual Memory Design Parameters Paged VMTLBs Total size16,000 to 250,000 pages 16 to 512 entries Total size (KB)250,000 to 1,000,000, to 16 Block size (B)4000 to 64,0004 to 8 Hit time0.5 to 1 clock cycle Miss penalty (clocks)10,000,000 to 100,000, to 100 Miss rates % to % 0.01% to 1%

CPE432 Chapter 5A.16Dr. W. Abu-Sufah, UJ Two Machines’ TLB Parameters Intel NehalemAMD Barcelona Address sizes48 bits (vir); 44 bits (phy)48 bits (vir); 48 bits (phy) Page size4KB TLB organizationL1 TLB for instructions and L1 TLB for data per core; both are 4-way set assoc.; LRU L1 ITLB has 128 entries, L2 DTLB has 64 entries L2 TLB (unified) is 4-way set assoc.; LRU L2 TLB has 512 entries TLB misses handled in hardware L1 TLB for instructions and L1 TLB for data per core; both are fully assoc.; LRU L1 ITLB and DTLB each have 48 entries L2 TLB for instructions and L2 TLB for data per core; each are 4-way set assoc.; round robin LRU Both L2 TLBs have 512 entries TLB misses handled in hardware

CPE432 Chapter 5A.17Dr. W. Abu-Sufah, UJ Reducing Translation Time  Can overlap the cache access with the TLB access l Works when the high order bits of the VA are used to access the TLB while the low order bits are used as index into cache TagData = TagData = Cache HitDesired word VA Tag PA Tag TLB Hit 2-way Associative Cache Index PA Tag Block offset Page offsetVirtual page # This only works as long as the address bits used to index into the cache do not change as the result of VA translation

CPE432 Chapter 5A.18Dr. W. Abu-Sufah, UJ Section 5.5: A Common Framework for Memory Hierarchies

CPE432 Chapter 5A.19Dr. W. Abu-Sufah, UJ 4 Questions for the Memory Hierarchy  Q1: Where can a entry be placed in the upper level? (Entry placement) l e.g. Where can a main memory block be placed in cache? (direct mapped or set associative or fully associative)  Q2: How is a entry found if it is in the upper level? (Entry identification) l e.g. how is a main memory block found if it is in cache ?  Q3: Which entry should be replaced on a miss? (Entry replacement) l e.g. Which cache block should be replaced on a cache miss ?  Q4: What happens on a write? (Write strategy)

CPE432 Chapter 5A.20Dr. W. Abu-Sufah, UJ Q1&Q2 # of setsEntries (blocks) per set Direct mapped# of entries (blocks)1 Set associative(# of entries)/ associativity Associativity (typically 2 to 16) Fully associative1# of entries (blocks) Location method# of comparisons Direct mappedIndex1 Set associativeIndex the set; compare set’s tags Degree of associativity Fully associativeCache/MM: Compare all entries’ tags MM/SM: Separate lookup (page) table # of entries/set 0 Q1: Where to place an entry in the higher level? Q2: How to find if an entry is in the higher level?

CPE432 Chapter 5A.21Dr. W. Abu-Sufah, UJ Q3: Which entry should be replaced on a miss?  Easy for direct mapped – only one choice  Set associative or fully associative l Random l LRU (Least Recently Used)  For a 2-way set associative, random replacement has a miss rate about 1.1 times higher than LRU  LRU is too costly to implement for high levels of associativity (> 4-way) since tracking the usage information is costly

CPE432 Chapter 5A.22Dr. W. Abu-Sufah, UJ Q4: What happens on a write?  Write-through – The information is written to the entry in the current memory level and to the entry in the next level of the memory hierarchy l Always combined with a write buffer so write waits to next level memory can be eliminated (as long as the write buffer doesn’t fill)

CPE432 Chapter 5A.23Dr. W. Abu-Sufah, UJ Q4: What happens on a write? (cont. I)  Write-back – The information is written only to the entry in the current memory level. The modified entry is written to next level of memory only when it is replaced. l Need a dirty bit to keep track of whether the entry is clean or dirty l Virtual memory systems always use write-back of dirty pages to disk

CPE432 Chapter 5A.24Dr. W. Abu-Sufah, UJ Q4: What happens on a write? (cont. II)  Pros and cons of each? l Pros of Write-through: read misses don’t result in writes; easier to implement l Pros of Write-back: writes run at the speed of the cache; repeated writes require only ONE write to lower level

CPE432 Chapter 5A.25Dr. W. Abu-Sufah, UJ Section 5.12 Concluding Remarks

CPE432 Chapter 5A.26Dr. W. Abu-Sufah, UJ Summary & Conclusions  Fast memories are small, large memories are slow l We really want fast, large memories -Caching gives this illusion  The Principle of Locality: l A program is likely to access a relatively small portion of the address space at any instant of time. -Temporal Locality: Locality in Time -Spatial Locality: Locality in Space  Memory hierarchy l L1 cache  L2 cache  …  DRAM memory  disk

CPE432 Chapter 5A.27Dr. W. Abu-Sufah, UJ Summary & Conclusions (cont.)  Caches, TLBs, Virtual Memory all understood by examining how they deal with the four questions l Where can entry be placed? l How is entry found? l What entry is replaced on miss? l How are writes handled?  Page tables map virtual address to physical address l TLBs are important for fast translation  Memory system design is critical for multiprocessors (e.g. multicore microprocessors)