Review: The Memory Hierarchy

Slides:



Advertisements
Similar presentations
Lecture 8: Memory Hierarchy Cache Performance Kai Bu
Advertisements

Computation I pg 1 Embedded Computer Architecture Memory Hierarchy: Cache Recap Course 5KK73 Henk Corporaal November 2014
CMSC 611: Advanced Computer Architecture Cache Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from.
1 Copyright © 2012, Elsevier Inc. All rights reserved. Chapter 2 (and Appendix B) Memory Hierarchy Design Computer Architecture A Quantitative Approach,
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 2 Instructors: Krste Asanovic & Vladimir Stojanovic
331 Week13.1Spring :332:331 Computer Architecture and Assembly Language Spring 2006 Week 13 Basics of Cache [Adapted from Dave Patterson’s UCB CS152.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
Computer Systems Organization: Lecture 11
1 Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
Cache Memory Adapted from lectures notes of Dr. Patterson and Dr. Kubiatowicz of UC Berkeley.
Chapter 7 Large and Fast: Exploiting Memory Hierarchy Bo Cheng.
Memory Chapter 7 Cache Memories.
331 Lec20.1Fall :332:331 Computer Architecture and Assembly Language Fall 2003 Week 13 Basics of Cache [Adapted from Dave Patterson’s UCB CS152.
ENGS 116 Lecture 121 Caches Vincent H. Berk Wednesday October 29 th, 2008 Reading for Friday: Sections C.1 – C.3 Article for Friday: Jouppi Reading for.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
331 Lec20.1Spring :332:331 Computer Architecture and Assembly Language Spring 2005 Week 13 Basics of Cache [Adapted from Dave Patterson’s UCB CS152.
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.
EEM 486 EEM 486: Computer Architecture Lecture 6 Memory Systems and Caches.
1 CSE SUNY New Paltz Chapter Seven Exploiting Memory Hierarchy.
Memory Hierarchy and Cache Design The following sources are used for preparing these slides: Lecture 14 from the course Computer architecture ECE 201 by.
CS3350B Computer Architecture Winter 2015 Lecture 3.2: Exploiting Memory Hierarchy: How? Marc Moreno Maza [Adapted from.
Computer Architecture and Design – ECEN 350 Part 9 [Some slides adapted from M. Irwin, D. Paterson. D. Garcia and others]
Caching & Virtual Memory Systems Chapter 7  Caching l To address bottleneck between CPU and Memory l Direct l Associative l Set Associate  Virtual Memory.
Lecture 10 Memory Hierarchy and Cache Design Computer Architecture COE 501.
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,
EEE-445 Review: Major Components of a Computer Processor Control Datapath Memory Devices Input Output Cache Main Memory Secondary Memory (Disk)
CSIE30300 Computer Architecture Unit 9: Improving Cache Performance Hsin-Chou Chi [Adapted from material by and
CS.305 Computer Architecture Improving Cache Performance Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 10 Memory Hierarchy.
CSIE30300 Computer Architecture Unit 08: Cache Hsin-Chou Chi [Adapted from material by and
CPE432 Chapter 5A.1Dr. W. Abu-Sufah, UJ Chapter 5A: Exploiting the Memory Hierarchy, Part 2 Adapted from Slides by Prof. Mary Jane Irwin, Penn State University.
1  1998 Morgan Kaufmann Publishers Recap: Memory Hierarchy of a Modern Computer System By taking advantage of the principle of locality: –Present the.
1 CMPE 421 Parallel Computer Architecture PART4 Caching with Associativity.
1Chapter 7 Memory Hierarchies (Part 2) Outline of Lectures on Memory Systems 1. Memory Hierarchies 2. Cache Memory 3. Virtual Memory 4. The future.
Additional Slides By Professor Mary Jane Irwin Pennsylvania State University Group 3.
Caches Where is a block placed in a cache? –Three possible answers  three different types AnywhereFully associativeOnly into one block Direct mappedInto.
The Goal: illusion of large, fast, cheap memory Fact: Large memories are slow, fast memories are small How do we create a memory that is large, cheap and.
Computer Organization & Programming
Lecture 08: Memory Hierarchy Cache Performance Kai Bu
1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are ns at cost of $100 to $250 per Mbyte. DRAM access times are ns.
Nov. 15, 2000Systems Architecture II1 Machine Organization (CS 570) Lecture 8: Memory Hierarchy Design * Jeremy R. Johnson Wed. Nov. 15, 2000 *This lecture.
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.
CS224 Spring 2011 Computer Organization CS224 Chapter 5A: Exploiting the Memory Hierarchy, Part 1 Spring 2011 With thanks to M.J. Irwin, D. Patterson,
1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are ns at cost of $100 to $250 per Mbyte. DRAM access times are ns.
1  1998 Morgan Kaufmann Publishers Chapter Seven.
1  2004 Morgan Kaufmann Publishers Locality A principle that makes having a memory hierarchy a good idea If an item is referenced, temporal locality:
Improving Memory Access 2/3 The Cache and Virtual Memory
CPE232 Improving Cache Performance1 CPE 232 Computer Organization Spring 2006 Improving Cache Performance Dr. Gheith Abandah [Adapted from the slides of.
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.
CSE431 L20&21 Improving Cache Performance.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 20&21. Improving Cache Performance Mary Jane.
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Set-Associative Caches Instructors: Randy H. Katz David A. Patterson
CS 61C: Great Ideas in Computer Architecture Caches Part 2 Instructors: Nicholas Weaver & Vladimir Stojanovic
CS 110 Computer Architecture Lecture 15: Caches Part 2 Instructor: Sören Schwertfeger School of Information Science and Technology.
CMSC 611: Advanced Computer Architecture
COSC3330 Computer Architecture
Yu-Lun Kuo Computer Sciences and Information Engineering
The Goal: illusion of large, fast, cheap memory
Cache Memory Presentation I
Lecture 08: Memory Hierarchy Cache Performance
CPE 631 Lecture 05: Cache Design
Morgan Kaufmann Publishers
Chapter Five Large and Fast: Exploiting Memory Hierarchy
Cache - Optimization.
Cache Memory Rabi Mahapatra
Memory & Cache.
Presentation transcript:

Review: The Memory Hierarchy 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 Processor 4-8 bytes (word) 1 to 4 blocks 1,024+ bytes (disk sector = page) 8-32 bytes (block) 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 Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory (Relative) size of the memory at each level

Review: Principle of Locality Temporal Locality Keep most recently accessed data items closer to the processor Spatial Locality Move blocks consisting of contiguous words to the upper levels Hit Time << Miss Penalty Hit: data appears in some block in the upper level (Blk X) Hit Rate: the fraction of accesses found in the upper level Hit Time: RAM access time + Time to determine hit/miss Miss: data needs to be retrieve from a lower level block (Blk Y) Miss Rate = 1 - (Hit Rate) Miss Penalty: Time to replace a block in the upper level with a block from the lower level + Time to deliver this block’s word to the processor Miss Types: Compulsory, Conflict, Capacity Lower Level Memory Upper Level To Processor From Processor Blk X Blk Y

Measuring Cache Performance Assuming cache hit costs are included as part of the normal CPU execution cycle, then CPU time = IC × CPI × CC = IC × (CPIideal + Memory-stall cycles) × CC CPIstall Memory-stall cycles come from cache misses (a sum of read-stalls and write-stalls) Read-stall cycles = reads/program × read miss rate × read miss penalty Write-stall cycles = (writes/program × write miss rate × write miss penalty) + write buffer stalls For write-through caches, we can simplify this to Memory-stall cycles = miss rate × miss penalty Instruction Count/CPI/Cycle Cost Reasonable write buffer depth (e.g., four or more words) and a memory capable of accepting writes at a rate that significantly exceeds the average write frequency means write buffer stalls are small Average Memory Access time = Hit Time + Miss Rate x Miss Penalty

Review: The “Memory Wall” Logic vs DRAM speed gap continues to grow Clocks per DRAM access Clocks per instruction

Impacts of Cache Performance Relative cache penalty increases as processor performance improves (faster clock rate and/or lower CPI) The memory speed is unlikely to improve as fast as processor cycle time. When calculating CPIstall, the cache miss penalty is measured in processor clock cycles needed to handle a miss The lower the CPIideal, the more pronounced the impact of stalls A processor with a CPIideal of 2, a 100 cycle miss penalty, 36% load/store instr’s, and 2% I$ and 4% D$ miss rates Memory-stall cycles = 2% × 100 + 36% × 4% × 100 = 3.44 So CPIstalls = 2 + 3.44 = 5.44 What if the CPIideal is reduced to 1? 0.5? 0.25? What if the processor clock rate is doubled (doubling the miss penalty)? For ideal CPI = 1, then CPIstall = 4.44 and the amount of execution time spent on memory stalls would have risen from 3.44/5.44 = 63% to 3.44/4.44 = 77% For miss penalty of 200, memory stall cycles = 2% 200 + 36% x 4% x 200 = 6.88 so that CPIstall = 8.88 This assumes that hit time is not a factor in determining cache performance. A larger cache would have a longer access time (if a lower miss rate), meaning either a slower clock cycle or more stages in the pipeline for memory access.

Reducing Cache Miss Rates #1 Allow more flexible block placement In a direct mapped cache a memory block maps to exactly one cache block At the other extreme, could allow a memory block to be mapped to any cache block – fully associative cache A compromise is to divide the cache into sets each of which consists of n “ways” (n-way set associative). A memory block maps to a unique set (specified by the index field) and can be placed in any way of that set (so there are n choices) (block address) modulo (# sets in the cache)

Cache Two issues: Our first example: How do we know if a data item is in the cache? If it is, how do we find it? Our first example: block size is one word of data "direct mapped" For each item of data at the lower level, there is exactly one location in the cache where it might be. e.g., lots of items at the lower level share locations in the upper level

Direct Mapped Cache Mapping: address is modulo the number of blocks in the cache

Direct Mapped Cache For MIPS: What kind of locality are we taking advantage of? A d r e s ( h o w i n g b t p ) 2 1 B y f V a l T D I x 3 H

Direct Mapped Cache Taking advantage of spatial locality: A d r e s ( w i n g b t p ) 1 6 2 B y f V T a D H 3 4 K 8 M u x l c k I 5

Hits vs. Misses Read hits Read misses Write hits: Write misses: this is what we want! Read misses stall the CPU, fetch block from memory, deliver to cache, restart Write hits: can replace data in cache and memory (write-through) write the data only into the cache (write-back the cache later) Write misses: read the entire block into the cache, then write the word

Hardware Issues Make reading multiple words easier by using banks of memory It can get a lot more complicated... C P U a c h e B u s M m o r y . O n - w d i g z t b W l p x k 1 2 3 I v

Performance Increasing the block size tends to decrease miss rate: Use split caches because there is more spatial locality in code: 1 K B 8 6 4 2 5 % 3 M i s r a t e l o c k z ( b y )

Performance Simplified model: execution time = (execution cycles + stall cycles) ´ cycle time stall cycles = # of instructions ´ miss ratio ´ miss penalty Two ways of improving performance: decreasing the miss ratio decreasing the miss penalty What happens if we increase block size?

Set Associative Caches Basic Idea: a memory block can be mapped to more than one location in the cache Cache is divided into sets Each memory block is mapped to a particular set Each set can have more than one block Number of blocks in set = associativity of cache If a set has only one block, then it is a direct-mapped cache I.e. direct mapped caches have a set associativity of 1 Each memory block can be placed in any of the blocks of the set to which it maps

Direct mapped cache: block N maps to ( N mod num of blocks in cache) Set associative cache: block N maps to set (N mod num of sets in cache) Example below shows placement of block whose address is 12 1 2 T a g D t B l o c k # 3 4 5 6 7 S e r h i m p d s v F u y

Decreasing miss ratio with associativity - w y s e o c v ( f u l ) F r S 1 O n d m p B k 7 2 3 4 5 6 Compared to direct mapped, give a series of references that: results in a lower miss ratio using a 2-way set associative cache results in a higher miss ratio using a 2-way set associative cache assuming we use the “least recently used” replacement strategy

Set Associative Cache Example Main Memory 0000xx 0001xx 0010xx 0011xx 0100xx 0101xx 0110xx 0111xx 1000xx 1001xx 1010xx 1011xx 1100xx 1101xx 1110xx 1111xx Two low order bits define the byte in the word (32-b words) One word blocks Cache Way Set V Tag Data 1 1 1 Q2: How do we find it? Use next 1 low order memory address bit to determine which cache set (i.e., modulo the number of sets in the cache) Q1: Is it there? Compare all the cache tags in the set to the high order 3 memory address bits to tell if the memory block is in the cache For lecture Valid bit indicates whether an entry contains valid information – if the bit is not set, there cannot be a match for this block

Another Reference String Mapping Consider the main memory word reference string 0 4 0 4 0 4 0 4 Start with an empty cache - all blocks initially marked as not valid 4 4 For class handout

Another Reference String Mapping Consider the main memory word reference string 0 4 0 4 0 4 0 4 Start with an empty cache - all blocks initially marked as not valid miss 4 miss hit 4 hit 000 Mem(0) 000 Mem(0) 000 Mem(0) 000 Mem(0) 010 Mem(4) 010 Mem(4) 010 Mem(4) 8 requests, 2 misses For lecture Another sample string to try 0 1 2 3 0 8 11 0 3 Solves the ping pong effect in a direct mapped cache due to conflict misses since now two memory locations that map into the same cache set can co-exist!

Four-Way Set Associative Cache 28 = 256 sets each with four ways (each with one block) Byte offset 31 30 . . . 13 12 11 . . . 2 1 0 22 Tag 8 Index Index Data Tag V 1 2 . 253 254 255 Data Tag V 1 2 . 253 254 255 Data Tag V 1 2 . 253 254 255 Data Tag V 1 2 . 253 254 255 Hit Data 32 4x1 select This is called a 4-way set associative cache because there are four cache entries for each cache index. Essentially, you have four direct mapped cache working in parallel. This is how it works: the cache index selects a set from the cache. The four tags in the set are compared in parallel with the upper bits of the memory address. If no tags match the incoming address tag, we have a cache miss. Otherwise, we have a cache hit and we will select the data from the way where the tag matches occur. This is simple enough. What is its disadvantages? +1 = 36 min. (Y:16)

Range of Set Associative Caches For a fixed size cache, each increase by a factor of two in associativity doubles the number of blocks per set (i.e., the number or ways) and halves the number of sets – decreases the size of the index by 1 bit and increases the size of the tag by 1 bit Tag Index Block offset Byte offset For class handout

Range of Set Associative Caches For a fixed size cache, each increase by a factor of two in associativity doubles the number of blocks per set (i.e., the number or ways) and halves the number of sets – decreases the size of the index by 1 bit and increases the size of the tag by 1 bit Used for tag compare Selects the set Selects the word in the block Tag Index Block offset Byte offset Increasing associativity Decreasing associativity For lecture Fully associative (only one set) Tag is all the bits except block and byte offset Direct mapped (only one way) Smaller tags

Costs of Set Associative Caches When a miss occurs, which way’s block do we pick for replacement? Least Recently Used (LRU): the block replaced is the one that has been unused for the longest time Must have hardware to keep track of when each way’s block was used relative to the other blocks in the set For 2-way set associative, takes one bit per set → set the bit when a block is referenced (and reset the other way’s bit) N-way set associative cache costs N comparators (delay and area) MUX delay (set selection) before data is available Data available after set selection (and Hit/Miss decision). In a direct mapped cache, the cache block is available before the Hit/Miss decision So its not possible to just assume a hit and continue and recover later if it was a miss First of all, a N-way set associative cache will need N comparators instead of just one comparator (use the right side of the diagram for direct mapped cache). A N-way set associative cache will also be slower than a direct mapped cache because of this extra multiplexer delay. Finally, for a N-way set associative cache, the data will be available AFTER the hit/miss signal becomes valid because the hit/mis is needed to control the data MUX. For a direct mapped cache, that is everything before the MUX on the right or left side, the cache block will be available BEFORE the hit/miss signal (AND gate output) because the data does not have to go through the comparator. This can be an important consideration because the processor can now go ahead and use the data without knowing if it is a Hit or Miss. Just assume it is a hit. Since cache hit rate is in the upper 90% range, you will be ahead of the game 90% of the time and for those 10% of the time that you are wrong, just make sure you can recover. You cannot play this speculation game with a N-way set-associative cache because as I said earlier, the data will not be available to you until the hit/miss signal is valid. +2 = 38 min. (Y:18)

Benefits of Set Associative Caches The choice of direct mapped or set associative depends on the cost of a miss versus the cost of implementation Data from Hennessy & Patterson, Computer Architecture, 2003 As cache sizes grow, the relative improvement from associativity increases only slightly; since the overall miss rate of a larger cache is lower, the opportunity for improving the miss rate decreases and the absolute improvement in miss rate from associativity shrinks significantly. Largest gains are in going from direct mapped to 2-way (20%+ reduction in miss rate)

Set Associative Caches (in summary) Advantages: Miss ratio decreases as associativity increases Disadvantages Extra memory needed for extra tag bits in cache Extra time for associative search

Block Replacement Policies What block to replace on a cache miss? We have multiple candidates (unlike direct mapped caches) Random FIFO (First In First Out) LRU (Least Recently Used) Typically, cpus use Random or Approximate LRU because easier to implement in hardware

Example Cache size = 4 one word blocks Replacement Policy = LRU Sequence of memory references 0,8,0,6,8 Set associativity = 4 (Fully Associative); Number of Sets = 1 Address Hit/Miss Set 0 M 8 H 6

Example cont’d Cache size = 4 one word blocks Replacement Policy = LRU Sequence of memory references 0,8,0,6,8 Set associativity = 2 ; Number of Sets = 2 Address Hit/Miss Set 0 Set 1 M 8 H 6

Example cont’d Cache size = 4 one word blocks Replacement Policy = LRU Sequence of memory references 0,8,0,6,8 Set associativity = 1 (Direct Mapped Cache) Address Hit/Miss 1 2 3 M 8 6

Decreasing miss penalty with multilevel caches Add a second level cache: often primary cache is on the same chip as the processor use SRAMs to add another cache above primary memory (DRAM) miss penalty goes down if data is in 2nd level cache Example: CPI of 1.0 on a 500Mhz machine with a 5% miss rate, 200ns DRAM access Adding 2nd level cache with 20ns access time decreases miss rate to 2% Using multilevel caches: try and optimize the hit time on the 1st level cache try and optimize the miss rate on the 2nd level cache

I m p r o v e n t f a c 1 9 8 2 4 6 Y C P U ( s ) l w D R A M

2 % M i s r a t e p y 4 6 8 1 3 O n - w T o C c h z ( K B ) F u E g

Reducing Cache Miss Rates #2 Use multiple levels of caches With advancing technology have more than enough room on the die for bigger L1 caches or for a second level of caches – normally a unified L2 cache (i.e., it holds both instructions and data) and in some cases even a unified L3 cache For our example, CPIideal of 2, 100 cycle miss penalty (to main memory), 36% load/stores, a 2% (4%) L1I$ (D$) miss rate, add a UL2$ that has a 25 cycle miss penalty and a 0.5% miss rate CPIstalls = 2 + .02×25 + .36×.04×25 + .005×100 + .36×.005×100 = 3.54 (as compared to 5.44 with no L2$) Also reduces cache miss penalty

Multilevel Cache Design Considerations Design considerations for L1 and L2 caches are very different Primary cache should focus on minimizing hit time in support of a shorter clock cycle Smaller with smaller block sizes Secondary cache(s) should focus on reducing miss rate to reduce the penalty of long main memory access times Larger with larger block sizes The miss penalty of the L1 cache is significantly reduced by the presence of an L2 cache – so it can be smaller (i.e., faster) but have a higher miss rate For the L2 cache, hit time is less important than miss rate The L2$ hit time determines L1$’s miss penalty L2$ local miss rate >> than the global miss rate Global miss rate – the fraction of references that miss in all levels of a multilevel cache. The global miss rate dictates how often we must access the main memory. Local miss rate – the fraction of references to one level of a cache that miss

Key Cache Design Parameters L1 typical L2 typical Total size (blocks) 250 to 2000 4000 to 250,000 Total size (KB) 16 to 64 500 to 8000 Block size (B) 32 to 64 32 to 128 Miss penalty (clocks) 10 to 25 100 to 1000 Miss rates (global for L2) 2% to 5% 0.1% to 2%

Two Machines’ Cache Parameters Intel P4 AMD Opteron L1 organization Split I$ and D$ L1 cache size 8KB for D$, 96KB for trace cache (~I$) 64KB for each of I$ and D$ L1 block size 64 bytes L1 associativity 4-way set assoc. 2-way set assoc. L1 replacement ~ LRU LRU L1 write policy write-through write-back L2 organization Unified L2 cache size 512KB 1024KB (1MB) L2 block size 128 bytes L2 associativity 8-way set assoc. 16-way set assoc. L2 replacement ~LRU L2 write policy A trace cache finds a dynamic sequence of instructions including taken branches to load into a cache block. Thus, the cache blocks contain dynamic traces of the executed instructions as determined by the CPU rather than static sequences of instructions as determined by memory layout. It folds branch prediction into the cache.

4 Questions for the Memory Hierarchy Q1: Where can a block be placed in the upper level? (Block placement) Q2: How is a block found if it is in the upper level? (Block identification) Q3: Which block should be replaced on a miss? (Block replacement) Q4: What happens on a write? (Write strategy)

Q1&Q2: Where can a block be placed/found? # of sets Blocks per set Direct mapped # of blocks in cache 1 Set associative (# of blocks in cache)/ associativity Associativity (typically 2 to 16) Fully associative Location method # of comparisons Direct mapped Index 1 Set associative Index the set; compare set’s tags Degree of associativity Fully associative Compare all blocks tags # of blocks

Q3: Which block should be replaced on a miss? Easy for direct mapped – only one choice Set associative or fully associative Random LRU (Least Recently Used) For a 2-way set associative cache, 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

Q4: What happens on a write? Write-through – The information is written to both the block in the cache and to the block in the next lower level of the memory hierarchy Write-through is always combined with a write buffer so write waits to lower level memory can be eliminated (as long as the write buffer doesn’t fill) Write-back – The information is written only to the block in the cache. The modified cache block is written to main memory only when it is replaced. Need a dirty bit to keep track of whether the block is clean or dirty Pros and cons of each? Write-through: read misses don’t result in writes (so are simpler and cheaper) Write-back: repeated writes require only one write to lower level

Improving Cache Performance 0. Reduce the time to hit in the cache smaller cache direct mapped cache smaller blocks for writes no write allocate – no “hit” on cache, just write to write buffer write allocate – to avoid two cycles (first check for hit, then write) pipeline writes via a delayed write buffer to cache 1. Reduce the miss rate bigger cache more flexible placement (increase associativity) larger blocks (16 to 64 bytes typical) victim cache – small buffer holding most recently discarded blocks

Improving Cache Performance 2. Reduce the miss penalty smaller blocks use a write buffer to hold dirty blocks being replaced so don’t have to wait for the write to complete before reading check write buffer (and/or victim cache) on read miss – may get lucky for large blocks fetch critical word first use multiple cache levels – L2 cache not tied to CPU clock rate faster backing store/improved memory bandwidth wider buses memory interleaving, page mode DRAMs

Summary: The Cache Design Space Several interacting dimensions cache size block size associativity replacement policy write-through vs write-back write allocation The optimal choice is a compromise depends on access characteristics workload use (I-cache, D-cache, TLB) depends on technology / cost Simplicity often wins Cache Size Associativity Block Size Bad No fancy replacement policy is needed for the direct mapped cache. As a matter of fact, that is what cause direct mapped trouble to begin with: only one place to go in the cache--causes conflict misses. Besides working at Sun, I also teach people how to fly whenever I have time. Statistic have shown that if a pilot crashed after an engine failure, he or she is more likely to get killed in a multi-engine light airplane than a single engine airplane. The joke among us flight instructors is that: sure, when the engine quit in a single engine stops, you have one option: sooner or later, you land. Probably sooner. But in a multi-engine airplane with one engine stops, you have a lot of options. It is the need to make a decision that kills those people. Good Factor A Factor B Less More