Cache performance Outline

Similar documents
Types of Cache Misses: The Three C s

Classification Steady-State Cache Misses: Techniques To Improve Cache Performance:

Memory Hierarchy 3 Cs and 6 Ways to Reduce Misses

Improving Cache Performance. Dr. Yitzhak Birk Electrical Engineering Department, Technion

Improving Cache Performance. Reducing Misses. How To Reduce Misses? 3Cs Absolute Miss Rate. 1. Reduce the miss rate, Classifying Misses: 3 Cs

Lecture 9: Improving Cache Performance: Reduce miss rate Reduce miss penalty Reduce hit time

Lecture 16: Memory Hierarchy Misses, 3 Cs and 7 Ways to Reduce Misses. Professor Randy H. Katz Computer Science 252 Fall 1995

DECstation 5000 Miss Rates. Cache Performance Measures. Example. Cache Performance Improvements. Types of Cache Misses. Cache Performance Equations

Lecture 16: Memory Hierarchy Misses, 3 Cs and 7 Ways to Reduce Misses Professor Randy H. Katz Computer Science 252 Spring 1996

Computer Architecture Spring 2016

Lecture 7: Memory Hierarchy 3 Cs and 7 Ways to Reduce Misses Professor David A. Patterson Computer Science 252 Fall 1996

Cache Performance! ! Memory system and processor performance:! ! Improving memory hierarchy performance:! CPU time = IC x CPI x Clock time

Lecture 19: Memory Hierarchy Five Ways to Reduce Miss Penalty (Second Level Cache) Admin

Memory Cache. Memory Locality. Cache Organization -- Overview L1 Data Cache

Cache Performance! ! Memory system and processor performance:! ! Improving memory hierarchy performance:! CPU time = IC x CPI x Clock time

Lecture 11 Reducing Cache Misses. Computer Architectures S

Chapter-5 Memory Hierarchy Design

CISC 662 Graduate Computer Architecture Lecture 18 - Cache Performance. Why More on Memory Hierarchy?

NOW Handout Page # Why More on Memory Hierarchy? CISC 662 Graduate Computer Architecture Lecture 18 - Cache Performance

CPE 631 Lecture 06: Cache Design

Aleksandar Milenkovich 1

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier

Cache Memory: Instruction Cache, HW/SW Interaction. Admin

EITF20: Computer Architecture Part4.1.1: Cache - 2

CMSC 611: Advanced Computer Architecture. Cache and Memory

Memory Hierarchy Design. Chapter 5

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

CS 152 Computer Architecture and Engineering. Lecture 8 - Memory Hierarchy-III

Chapter 5. Topics in Memory Hierachy. Computer Architectures. Tien-Fu Chen. National Chung Cheng Univ.

Lec 12 How to improve cache performance (cont.)

Announcements. ! Previous lecture. Caches. Inf3 Computer Architecture

Copyright 2012, Elsevier Inc. All rights reserved.

L2 cache provides additional on-chip caching space. L2 cache captures misses from L1 cache. Summary

Memory Hierarchies 2009 DAT105

Cache Performance (H&P 5.3; 5.5; 5.6)

NOW Handout Page 1. Review: Who Cares About the Memory Hierarchy? EECS 252 Graduate Computer Architecture. Lec 12 - Caches

Lecture 11. Virtual Memory Review: Memory Hierarchy

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

CSE 502 Graduate Computer Architecture. Lec Advanced Memory Hierarchy

CS 152 Computer Architecture and Engineering. Lecture 8 - Memory Hierarchy-III

Reducing Miss Penalty: Read Priority over Write on Miss. Improving Cache Performance. Non-blocking Caches to reduce stalls on misses

Outline. 1 Reiteration. 2 Cache performance optimization. 3 Bandwidth increase. 4 Reduce hit time. 5 Reduce miss penalty. 6 Reduce miss rate

CS/ECE 250 Computer Architecture

CSE 502 Graduate Computer Architecture

CSE 502 Graduate Computer Architecture. Lec Advanced Memory Hierarchy and Application Tuning

Lec 11 How to improve cache performance

CS 152 Computer Architecture and Engineering. Lecture 8 - Memory Hierarchy-III

Aleksandar Milenkovich 1

Advanced optimizations of cache performance ( 2.2)

EITF20: Computer Architecture Part4.1.1: Cache - 2

COSC 6385 Computer Architecture. - Memory Hierarchies (II)

LRU. Pseudo LRU A B C D E F G H A B C D E F G H H H C. Copyright 2012, Elsevier Inc. All rights reserved.

Chapter 5 Memory Hierarchy Design. In-Cheol Park Dept. of EE, KAIST

Lecture-18 (Cache Optimizations) CS422-Spring

Recap: The Big Picture: Where are We Now? The Five Classic Components of a Computer. CS152 Computer Architecture and Engineering Lecture 20.

Advanced Caching Techniques (2) Department of Electrical Engineering Stanford University

CHAPTER 4 MEMORY HIERARCHIES TYPICAL MEMORY HIERARCHY TYPICAL MEMORY HIERARCHY: THE PYRAMID CACHE PERFORMANCE MEMORY HIERARCHIES CACHE DESIGN

Topics. Digital Systems Architecture EECE EECE Need More Cache?

CS422 Computer Architecture

Pick a time window size w. In time span w, are there, Multiple References, to nearby addresses: Spatial Locality

CS3350B Computer Architecture

Performance (1/latency) Capacity Access Time Cost. CPU Registers 100s Bytes <1 ns. Cache K Bytes M Bytes 1-10 ns.01 cents/byte

TDT Coarse-Grained Multithreading. Review on ILP. Multi-threaded execution. Contents. Fine-Grained Multithreading

COSC4201. Chapter 5. Memory Hierarchy Design. Prof. Mokhtar Aboelaze York University

Virtual memory why? Virtual memory parameters Compared to first-level cache Parameter First-level cache Virtual memory. Virtual memory concepts

Adapted from David Patterson s slides on graduate computer architecture

Graduate Computer Architecture. Handout 4B Cache optimizations and inside DRAM

LECTURE 4: LARGE AND FAST: EXPLOITING MEMORY HIERARCHY

COSC4201. Chapter 4 Cache. Prof. Mokhtar Aboelaze York University Based on Notes By Prof. L. Bhuyan UCR And Prof. M. Shaaban RIT

MEMORY HIERARCHY DESIGN. B649 Parallel Architectures and Programming

Memory Hierarchy Basics. Ten Advanced Optimizations. Small and Simple

Q3: Block Replacement. Replacement Algorithms. ECE473 Computer Architecture and Organization. Memory Hierarchy: Set Associative Cache

Levels in a typical memory hierarchy

Page 1. Memory Hierarchies (Part 2)

Advanced Caching Techniques

Advanced Caching Techniques

5008: Computer Architecture

Computer Architecture A Quantitative Approach, Fifth Edition. Chapter 2. Memory Hierarchy Design. Copyright 2012, Elsevier Inc. All rights reserved.

Memory Hierarchy Computing Systems & Performance MSc Informatics Eng. Memory Hierarchy (most slides are borrowed)

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

Memory Hierarchy Computing Systems & Performance MSc Informatics Eng. Memory Hierarchy (most slides are borrowed)

CS 2461: Computer Architecture 1

10/16/2017. Miss Rate: ABC. Classifying Misses: 3C Model (Hill) Reducing Conflict Misses: Victim Buffer. Overlapping Misses: Lockup Free Cache

Cache Optimisation. sometime he thought that there must be a better way

CSF Improving Cache Performance. [Adapted from Computer Organization and Design, Patterson & Hennessy, 2005]

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

CS 252 Graduate Computer Architecture. Lecture 8: Memory Hierarchy

Outline. EECS 252 Graduate Computer Architecture. Lec 16 Advanced Memory Hierarchy. Why More on Memory Hierarchy? Review: 6 Basic Cache Optimizations

Graduate Computer Architecture. Handout 4B Cache optimizations and inside DRAM

! 11 Advanced Cache Optimizations! Memory Technology and DRAM optimizations! Virtual Machines

Caching Basics. Memory Hierarchies

Memory Hierarchy Basics

Copyright 2012, Elsevier Inc. All rights reserved.

Computer Architecture. A Quantitative Approach, Fifth Edition. Chapter 2. Memory Hierarchy Design. Copyright 2012, Elsevier Inc. All rights reserved.

Chapter 2: Memory Hierarchy Design Part 2

Memory hierarchy review. ECE 154B Dmitri Strukov

COSC 6385 Computer Architecture - Memory Hierarchy Design (III)

Copyright 2012, Elsevier Inc. All rights reserved.

Memories. CPE480/CS480/EE480, Spring Hank Dietz.

Transcription:

Cache performance 1 Outline Metrics Performance characterization Cache optimization techniques 2 Page 1

Cache Performance metrics (1) Miss rate: Neglects cycle time implications Average memory access time (AMAT): AMAT = Hit time + (Miss Rate X Miss Penalty) miss penalty is the extra time it takes to handle a miss (above the 1 cycle hit cost) Example: 1 cycle hit cost 10 cycle miss penalty (11 cycles total for a miss) Program has 10% miss rate Average memory access time = 1.0 + 10% * 10 = 2.0 3 Cache performance: example Two cache options: a) 16 KB instruction + 16 KB data b) 32 KB unified cache (instructions + data) Information: Hit = 1 cycle, miss = 50 cycles Load/store = 1 extra cycle on the unified cache (single-port) 75% of memory references are fetches Miss rate info: Cache size I-cache D-cache Unified 1KB 3.0 % 24.6% 13.3% 2KB 2.3% 20.6% 9.8% 4KB 1.8% 16.0% 7.2% 8KB 1.1% 10.2% 4.6% 16KB 0.6% 6.5% 2.9% 32KB 0.4% 4.8% 2.0% 64KB 0.1% 3.8% 1.3% 4 Page 2

Cache performance: example (2) Comparing miss rates a) Split cache: Miss rate instruction (16KB) = 0.6% Miss rate data (16KB) = 6.5% Overall miss rate = 0.75*0.6 + 0.25*6.5 = 2.07 b) Unified cache Miss rate (32KB) = 2.00 Comparing cycle time penalty a) AMAT = 0.75*(1 + 0.6%*50) + 0.25*(1+6.5%*50) = 2.05 b) AMAT = 0.75*(1 + 0.6%*50)+ 0.25*(1+1+6.5%*50) = 2.24 5 Cache Performance metrics (2) CPU time: the ultimate metric CPU time = execution + memory access CPU time = (CPU execution cycles + Memory stall cycles) x T cycle Assuming that all memory stalls are due to caches: Memory stall cycles = # Reads x Read miss rate x Read miss penalty + # Writes x Write miss rate x Write miss penalty Combining reads and writes together: Memory stall cycles = Memory accesses x Miss rate x Miss penalty 6 Page 3

Cache Performance metrics (3) Factoring instruction count IC CPU time = IC x (CPI exec + Mem. accesses per instruction x Miss rate x Miss penalty) x T cycle Measuring miss rate as misses per instruction Misses per instruction = Memory accesses per instruction x Miss rate CPU time = IC x(cpi exec + Misses per instruction x Miss penalty) x T cycle 7 Cache Performance metrics Summarizing: Miss rates AMAT Hit time + (Miss Rate X Miss Penalty) CPU time IC x(cpi exec + Misses per instruction x Miss penalty) x T cycle 8 Page 4

Improving Cache Performance AMAT = Hit time + (Miss Rate X Miss Penalty) 1. Reduce the miss rate 2. Reduce the miss penalty 3. Reduce the time to hit in the cache 9 Reducing misses 10 Page 5

Classifying Misses: The 3 C s Compulsory: The first access to a block is not in the cache, so the block must be brought into the cache. Also called cold start misses or first reference misses Misses even in an Infinite Cache Capacity will occur due to blocks being discarded and later retrieved, if the cache cannot contain all the blocks needed during execution of a program Conflict Occur in set associative or direct mapped caches because a block can be discarded and later retrieved if too many blocks map to its set. Also called collision misses or interference misses Invalidation other process (e.g., I/O) updates memory 11 3Cs Absolute Miss Rate (SPEC92) 0.14 0.12 0.1 0.08 0.06 0.04 0.02 1-way 2-way 4-way Conflict 8-way Capacity X 0 Compulsory vanishingly small 1 2 4 8 16 Cache Size (KB) 32 64 128 Compulsory 12 Page 6

0.14 0.12 0.1 0.08 0.06 0.04 0.02 0 2:1 Cache Rule miss rate 1-way associative cache size X miss rate 2-way associative cache size X/2 1-way 2-way 4-way Conflict 8-way Capacity 1 2 4 8 16 32 64 128 Cache Size (KB) Compulsory 13 3Cs Relative Miss Rate Conflict 100% 80% 60% 1-way 2-way 4-way 8-way 40% Capacity 20% 0% 1 2 4 8 Flaws: for fixed block size 16 Cache Size (KB) 32 64 128 Compulsory 14 Page 7

How Can we Reduce Misses? Intuitively: Capacity misses are reduced by increasing cache size Conflict misses are reduced by increasing associativity Compulsory misses cannot be reduced Except by prefetching (achieved with larger block sizes) Specific optimizations: 1. Larger block sizes 2. Higher associativity 3. Smart indexing 4. Victim caches 5. HW prefetching 6. Compiler optimizations 15 Larger Block Sizes (1) Larger blocks reduce the number of compulsory misses because more data is brought into the cache on each miss High degree of spatial locality! Drawbacks: Larger blocks eventually create cache pollution More data is evicted from the cache Larger block sizes increase the miss penalty (and thus AMAT) Larger blocks take more cycles to refill There exists an optimal block size 16 Page 8

Larger Block Sizes (2) 25% Miss Rate 20% 15% 10% 5% 0% 1K 4K 16K 64K 256K 16 32 64 128 256 Block Size (bytes) 17 Larger Block Sizes (3) Increasing block size increases AMAT! Larger blocks require multiple bus cycles to be transferred Example: Block size 16 Miss penalty 42 1k 7.3 4k 4.6 16k 2.6 64k 1.8 256k 1.4 32 44 6.8 4.2 2.2 1.6 1.3 64 48 7.6 4.4 2.2 1.5 1.2 128 56 10.3 5.3 2.5 1.6 1.2 256 72 16.8 7.8 3.3 1.8 1.3 18 Page 9

Higher Associativity Higher degrees of associativity reduce conflict misses 8-way set-associative caches are almost as good as fully associative caches 2:1 Cache Rule: Miss Rate DM cache of size N Miss Rate 2-way cache of size N/2 Drawback: Increased associativity can increase the access time More logic for compares Set-associative caches not used as primary caches (where cycle-time is most important) but as lower-level caches (where access time is less of an issue) 19 Higher Associativity (2) AMAT for different cache configurations: Red values = AMAT does not decrease Cache Size Associativity (KB) 1-way 2-way 4-way 8-way 1 2.33 2.15 2.07 2.01 2 1.98 1.86 1.76 1.68 4 1.72 1.67 1.61 1.53 8 1.46 1.48 1.47 1.43 16 1.29 1.32 1.32 1.32 32 1.20 1.24 1.25 1.27 64 1.14 1.20 1.21 1.23 128 1.10 1.17 1.18 1.20 20 Page 10

Target: conflict misses Smart indexing (1) Conventional indexing mechanism uses m LS bits of address (2 m lines) Choice driven by performance (fast translation) Cache indexing is a hashing problem Map 2 n to 2 m lines by minimizing conflicts Better indexing: use a hash function Problem: good hash function are costly! Find a reasonable hash function 21 Options: Smart indexing (2) Use an alternative subset of address bits Example (n=4, m=2) 0000 0011 0111 Conflict Same complexity as standard indexing, modest reductions Low-cost hashing Use XOR between selected bits 0000 0011 0111 No conflict Bit k of index is b k = a i a j a p k=1,, m p <= n Cost of XORs can be amortized into address generation pipeline stage 22 Page 11

Victim Cache [Jouppi 1990] Small cache that contains the most recently discarded (replaced) cache blocks Typically 1-5 blocks On cache miss, victim cache is checked If block is present, victim cache block is placed back into the primary cache Equivalent to increased associativity for a few lines Very effective for direct-mapped caches A four-entry victim cache can remove 20% to 95% of conflict misses in a 4-KByte directmapped cache Used in Alpha, HP machines 23 Hardware Prefetching of Instructions & Data On a cache miss, fetch both the missing block and subsequent blocks Prefetched blocks are not placed directly into the cache, but into a special prefetch buffer Avoids cache pollution Very effective for instruction streams, but works for data as well Equivalent to a bigger blocksize for one or a few of the cache lines. Used in the Alpha 21064/21164 21064 fetches two cache blocks on a miss (2nd block is a prefetch) 24 Page 12

Compiler Optimizations Instructions: Make the non-branch path the common case Isolate all exception-handling code together Data: Array Merging Loop Interchange: change nesting of loops to access data in order stored in memory Loop Fusion: Combine 2 independent loops that have same looping and some variables overlap Blocking: Improve temporal locality by accessing blocks of data repeatedly vs. going down whole columns or rows 25 Array Merging /* Before: 2 sequential arrays */ int val[size]; int key[size]; /* After: 1 array of stuctures */ struct merge { int val; int key; }; struct merge merged_array[size]; Reduces conflicts between val & key; improve spatial locality 26 Page 13

Loop Interchange /* Before */ for (k = 0; k < 100; k = k+1) for (j = 0; j < 100; j = j+1) for (i = 0; i < 5000; i = i+1) x[i][j] = 2 * x[i][j]; /* After */ for (k = 0; k < 100; k = k+1) for (i = 0; i < 5000; i = i+1) for (j = 0; j < 100; j = j+1) x[i][j] = 2 * x[i][j]; Sequential accesses instead of striding through memory every 100 words 27 Loop Fusion /* Before */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) a[i][j] = 1/b[i][j] * c[i][j]; for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) d[i][j] = a[i][j] + c[i][j]; /* After */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) { a[i][j] = 1/b[i][j] * c[i][j]; d[i][j] = a[i][j] + c[i][j];} Combine independent loops that access same data 2 misses per access to a & c vs. one miss per access 28 Page 14

Blocking Example /* Before */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1){ r = 0; for (k = 0; k < N; k = k+1){ r = r + y[i][k]*z[k][j];}; x[i][j] = r; }; Two Inner Loops: Read all NxN elements of z[] Read N elements of 1 row of y[] repeatedly Write N elements of 1 row of x[] Capacity Misses are a function of N & Cache Size: 3 NxNx4 => no capacity misses; otherwise... Idea: compute on BxB submatrix that fits 29 Blocking Example (2) /* After */ for (jj = 0; jj < N; jj = jj+b) for (kk = 0; kk < N; kk = kk+b) for (i = 0; i < N; i = i+1) for (j = jj; j < min(jj+b-1,n); j = j+1) {r = 0; for (k = kk; k < min(kk+b-1,n); k = k+1) { r = r + y[i][k]*z[k][j];}; x[i][j] = x[i][j] + r; }; B called Blocking Factor Capacity Misses from 2N 3 + N 2 to 2N 3 /B +N 2 30 Page 15

Reducing Conflict Misses by Blocking 0.1 0.05 Direct Mapped Cache Fully Associative Cache 0 0 50 100 150 Blocking Factor Conflict misses in caches not FA vs. Blocking size Lam et al [1991] a blocking factor of 24 had 1/5 the misses vs. 48 despite both fit in cache 31 Summary of Compiler Optimizations vpenta (nasa7) gmty (nasa7) tomcatv btrix (nasa7) mxm (nasa7) spice cholesky (nasa7) compress 1 1.5 2 2.5 3 Performance Improvement merged arrays loop interchange loop fusion blocking 32 Page 16

Reducing miss penalty 33 Reducing miss penalty How to reduce the cost of a miss Obvious solution: Make DRAM faster Four techniques: 1. Giving priority to reads over writes 2. Sub-block placement 3. Early restart 4. 2 nd -level caches 34 Page 17

Read Priority over Write on Miss Write-buffers allow reads to proceed while writes wait for idle bus cycles Possible problems: Example: Direct-mapped cache, 512 & 1024 mapped on same block SW 512(R0), R3 ; assume cache index is 0 LW R1,1024(R0) ; evicts data from previous store LW R2,512(R0) ; misses again This is a RAW hazard if the write is buffered in the write buffer Solution: Let the write buffer empty on a read-miss (i.e., wait) High penalty (for read miss) Alternative: check write buffer contents before read; if no conflicts, let the memory access continue 35 Read Priority over Write on Miss (2) Write-back caches: Read miss replacing dirty block Normal: Write dirty block to memory, and then do the read Alternative: Copy the dirty block to a write buffer, then do the read, and then do the write CPU stalls less since restarts as soon as read is done 36 Page 18

Subblock Placement Don t have to load full block on a miss Divide a cache line into sub-blocks Use one valid bit per subblock to denote if subblock is valid Originally invented to reduce tag storage Only refill part of a line on a miss 100 1 1 1 1 Only write-back the dirty part of a line sub-blocks 300 1 1 0 0 200 0 1 0 1 204 0 0 0 0 Sub-blocks 37 Early Restart and Critical Word First Don t wait for full block to be loaded before restarting CPU Early restart: t miss = t access + t transfer As soon as the requested word of the block arrives, send it to the CPU and let the CPU continue execution Critical Word First (wrapped fetch) Request the missed word first from memory and send it to the CPU as soon as it arrives (requires bus & memory arrangement) Let the CPU continue execution while filling the rest of the words in the block. Generally useful only in large blocks Spatial locality a problem; tend to want next sequential word, so not clear if benefit by early restart block 38 Page 19

Non-blocking Caches Non-blocking (or lockup-free) cache allows to handle hits while a miss is pending Requires out-of-order execution CPU Classified according to number of allowed outstanding misses: One outstanding miss ( hit under miss ) reduces the effective miss penalty by working during miss vs. ignoring CPU requests Multiple outstanding misses ( hit under multiple miss or miss under miss ) Generalization Significantly increases the complexity of the cache controller as there can be multiple outstanding memory accesses Requires multiple memory banks (otherwise cannot be supported) Pentium Pro allows 4 outstanding memory misses 39 Non-blocking cache (2) Non-blocking cache potential Definitions: Primary miss: first miss to a main memory block Secondary misses: subsequent misses to the block being fetched Structural-stall misses: subsequent misses to the block being fetched that stall because of resource contention 40 Page 20

Non-blocking cache (2) Additional HW required: Miss Status Holding Registers (MSHRs) Compared on each miss Stalls reads to pending miss Buffers writes to pending miss Holds information on all outstanding misses Per block data: status & pointer to frame Per word data: destination register, overwritten, in-buffer bits entry 41 Value of Hit Under Miss for SPEC Hit Under i Misses 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0->1 1->2 2->64 Base Hit under n Misses 0 eqntott espresso xlisp compress mdljsp2 ear fpppp tomcatv swm256 doduc su2cor wave5 mdljdp2 hydro2d alvinn nasa7 spice2g6 ora Integer Floating Point FP programs on average: AMAT= 0.68 -> 0.52 -> 0.34 -> 0.26 Int programs on average: AMAT= 0.24 -> 0.20 -> 0.19 -> 0.19 8 KB Data Cache, Direct Mapped, 32B block, 16 cycle miss 42 Page 21

L2 Equations Second Level Cache AMAT = Hit Time L1 + Miss Rate L1 x Miss Penalty L1 Miss Penalty L1 = Hit Time L2 + Miss Rate L2 x Miss Penalty L2 AMAT = Hit Time L1 + Miss Rate L1 x (Hit Time L2 + Miss Rate L2 x Miss Penalty L2 ) Definitions: Local miss rate: Misses in this cache divided by the total number of memory accesses to this cache (Miss rate L2 ) Global miss rate: misses in this cache divided by the total number of memory accesses generated by the CPU (Miss Rate L1 x Miss Rate L2 ) Global Miss Rate is what matters (because of cost of miss) 43 Second-level cache The local miss rate of L2 caches typically quite bad L1 has caught most locality! Primary target: low miss rate Large size Large block size High associativity Latency not a big issue Usually provide multi-level inclusion: Everything at level i is also in level i+1 Not always necessary 44 Page 22

Comparing Local and Global Miss Rates 32 KByte L1 cache X-axis = L2 cache size Global miss rate close to single level cache rate provided that L2»L1 Local miss rate not relevant Since hits are few, target miss reduction 45 Making RAM faster In general, we assume that fastest memory technology is used for DRAM Other options to speed up misses: Make the memory wider Ex: Read out all 2 (or more) words in parallel Overhead: Higher cost, wider bus, error-correction harder Interleave Main Memory Requires multibank memories 46 Page 23

Reducing hit time 47 Use simpler caches: Reducing hit time Use direct-mapped caches No multiplexer in the path Data can be speculatively used while tag check is in progress Write hits take longer because tag must be checked before writing (read and write are in sequence). To fix, pipeline the writes: WRITE1: readtag writecache WRITE2: readtag writecache time 48 Page 24

Reducing hit time Pipelining writes 1. Check tag for write hit 2. Actually write data Need a 2 nd port for reads, otherwise stall for read after a write 49 Cache Optimization Summary 50 Page 25

Other cache issues 51 Outline Relation with virtual memory Example of real memory hierarchies 52 Page 26

Virtual memory: review From OS theory: Separation of virtual and physical address spaces Virtual: as seen by the program (CPU) Physical: as seen by the memory Moving from virtual to physical requires a translation For realistic memory management schemes, done by hardware (MMU) Paging Segmentation Done for each memory access 53 Virtual memory (VM) Most systems use paging (sometimes combined with segmentation) Virtual addresses (VA) = pages Physical addresses (PA) = frames Translation: page table Typically, stored in main memory Entry contains Physical frame number Status bits (valid,dirty,protection ) Typically a special cache called Translation Lookaside Buffer (TLB) is used to speed up most common translations 32 to 1024 entries (slots) Can be any organization, but typically fully associative 54 Page 27

VM and translation (no TLB) page table register virtual address 31 12 11 0 virtual page number page offset valid access physical page number if valid=0 then page is not in memory and page fault exception 29 physical page number 12 11 page offset 0 physical address 55 Integrating VM and cache Conceptually, caches bring physical memory space closer: Translation of VA to PA must be done before accessing caches Translation requires a memory access! Use of TLB reduces to (still) 1 cycle Called physical cache CPU VA TLB PA $ PA MEM Conventional Organization 56 Page 28

Integrating VM and cache (2) Alternative solution: Address cache with VA Called virtual caches Translation required for misses only Problems: Aliasing: 2 virtual addresses that point to the same physical page (e.g., shared pages). Two cache blocks for one physical location Cache flushes due to process switch: Get false hits Cost for flushing + compulsory misses from empty cache I/O? (uses physical addresses) VA Tags CPU VA $ VA TLB PA MEM 57 Integrating VM and cache (3) Solution to aliases HW guarantees that every cache block has unique physical address SW guarantee Lower n bits must have same address (called page coloring) Solution to cache flushes Add process identifier tag that identifies process as well as address within process Can t get a hit if wrong process Solution to I/O Inverse map addresses 58 Page 29

59 Integrating VM and cache (4) TLB and cache access can be done in parallel! The LSB of the virtual address are not modified by the translation process Can be used to start the cache access. The page offset part of the VA used to index into the cache at the start of the cycle TLB access proceeds as normal, using the Virtual Page portion of the virtual address At the end of the cycle, the virtual page is translated into a physical frame number (assuming a TLB hit) Partially-virtually addressed caches Virtual index, physical tag PA Tags CPU VA $ TB PA L2 $ MEM 60 Page 30

Integrating VM and cache (5) Details of parallel accesses: 61 Example of real memory hierarchies 62 Page 31

Alpha 21164 Hierarchy Regs. L1 Data 1 cycle latency 8KB, direct Write-through Dual Ported 32B lines L1 Instruction 8KB, direct 32B lines L2 Unified 8 cycle latency 96KB 3-way assoc. Write-back Write allocate 32B/64B lines L3 Unified 1M-64M direct Write-back Write allocate 32B or 64B lines Main Memory Up to 1TB Processor Chip 63 Pentium memory hierarchy 64 Page 32