Download presentation
Presentation is loading. Please wait.
Published byJacob Arthur Mogensen Modified over 5 years ago
1
Computer Architecture Lecture 3b: Memory Hierarchy and Caches
Prof. Onur Mutlu ETH Zürich Fall 2018 26 September 2018
2
Review Cache Lectures (from Spring 2018)
Memory Organization and Technology (Lecture 23b) Memory Hierarchy and Caches (Lecture 24) More Caches (Lecture 25a) Virtual Memory (Lecture 25b)
3
Optional Readings for Today
Memory Hierarchy and Caches Cache chapters from P&H: Memory/cache chapters from Hamacher+: An early cache paper by Maurice Wilkes Wilkes, “Slave Memories and Dynamic Storage Allocation,” IEEE Trans. On Electronic Computers, 1965. We already covered these in Digital Circuits so we will go through them quickly and get to advanced topics
4
Memory (Programmer’s View)
5
Abstraction: Virtual vs. Physical Memory
Programmer sees virtual memory Can assume the memory is “infinite” Reality: Physical memory size is much smaller than what the programmer assumes The system (system software + hardware, cooperatively) maps virtual memory addresses to physical memory The system automatically manages the physical memory space transparently to the programmer + Programmer does not need to know the physical size of memory nor manage it A small physical memory can appear as a huge one to the programmer Life is easier for the programmer -- More complex system software and architecture A classic example of the programmer/(micro)architect tradeoff
6
(Physical) Memory System
You need a larger level of storage to manage a small amount of physical memory automatically Physical memory has a backing store: disk We will first start with the physical memory system For now, ignore the virtualphysical indirection We will get back to it when the needs of virtual memory start complicating the design of physical memory…
7
Idealism Pipeline (Instruction execution) Instruction Supply Data
No pipeline stalls Perfect data flow (reg/memory dependencies) Zero-cycle interconnect (operand communication) Enough functional units Zero latency compute - Zero latency access - Infinite capacity - Zero cost - Perfect control flow Zero latency access Infinite capacity - Infinite bandwidth Zero cost
8
The Memory Hierarchy
9
Memory in a Modern System
CORE 0 L2 CACHE 0 L2 CACHE 1 CORE 1 SHARED L3 CACHE DRAM INTERFACE DRAM MEMORY CONTROLLER DRAM BANKS CORE 2 L2 CACHE 2 L2 CACHE 3 CORE 3
10
Ideal Memory Zero access time (latency) Infinite capacity Zero cost
Infinite bandwidth (to support multiple accesses in parallel)
11
The Problem Ideal memory’s requirements oppose each other
Bigger is slower Bigger Takes longer to determine the location Faster is more expensive Memory technology: SRAM vs. DRAM vs. Disk vs. Tape Higher bandwidth is more expensive Need more banks, more ports, higher frequency, or faster technology
12
Memory Technology: DRAM
Dynamic random access memory Capacitor charge state indicates stored value Whether the capacitor is charged or discharged indicates storage of 1 or 0 1 capacitor 1 access transistor Capacitor leaks through the RC path DRAM cell loses charge over time DRAM cell needs to be refreshed Read Liu et al., “RAIDR: Retention-aware Intelligent DRAM Refresh,” ISCA 2012. row enable _bitline
13
Memory Technology: SRAM
Static random access memory Two cross coupled inverters store a single bit Feedback path enables the stored value to persist in the “cell” 4 transistors for storage 2 transistors for access row select bitline _bitline
14
An Aside: Phase Change Memory
Phase change material (chalcogenide glass) exists in two states: Amorphous: Low optical reflexivity and high electrical resistivity Crystalline: High optical reflexivity and low electrical resistivity PCM is resistive memory: High resistance (0), Low resistance (1) Lee, Ipek, Mutlu, Burger, “Architecting Phase Change Memory as a Scalable DRAM Alternative,” ISCA 2009.
15
Reading: PCM As Main Memory
Benjamin C. Lee, Engin Ipek, Onur Mutlu, and Doug Burger, "Architecting Phase Change Memory as a Scalable DRAM Alternative" Proceedings of the 36th International Symposium on Computer Architecture (ISCA), pages 2-13, Austin, TX, June Slides (pdf)
16
Reading: More on PCM As Main Memory
Benjamin C. Lee, Ping Zhou, Jun Yang, Youtao Zhang, Bo Zhao, Engin Ipek, Onur Mutlu, and Doug Burger, "Phase Change Technology and the Future of Main Memory" IEEE Micro, Special Issue: Micro's Top Picks from 2009 Computer Architecture Conferences (MICRO TOP PICKS), Vol. 30, No. 1, pages 60-70, January/February 2010.
17
Memory Bank: A Fundamental Concept
Interleaving (banking) Problem: a single monolithic memory array takes long to access and does not enable multiple accesses in parallel Goal: Reduce the latency of memory array access and enable multiple accesses in parallel Idea: Divide the array into multiple banks that can be accessed independently (in the same cycle or in consecutive cycles) Each bank is smaller than the entire memory storage Accesses to different banks can be overlapped An issue: How do you map data to different banks? (i.e., how do you interleave data across banks?)
18
Memory Bank Organization and Operation
Read access sequence: 1. Decode row address & drive word-lines 2. Selected bits drive bit-lines • Entire row read 3. Amplify row data 4. Decode column address & select subset of row • Send to output 5. Precharge bit-lines • For next access
19
SRAM (Static Random Access Memory)
Read Sequence 1. address decode 2. drive row select 3. selected bit-cells drive bitlines (entire row is read together) 4. differential sensing and column select (data is ready) 5. precharge all bitlines (for next read or write) Access latency dominated by steps 2 and 3 Cycling time dominated by steps 2, 3 and 5 step 2 proportional to 2m step 3 and 5 proportional to 2n row select bitline _bitline bit-cell array 2n row x 2m-col (nm to minimize overall latency) n+m 2n n m 2m diff pairs sense amp and mux 1
20
DRAM (Dynamic Random Access Memory)
row enable Bits stored as charges on node capacitance (non-restorative) bit cell loses charge when read bit cell loses charge over time Read Sequence 1~3 same as SRAM 4. a “flip-flopping” sense amp amplifies and regenerates the bitline, data bit is mux’ed out 5. precharge all bitlines Destructive reads Charge loss over time Refresh: A DRAM controller must periodically read each row within the allowed refresh time (10s of ms) such that charge is restored _bitline bit-cell array 2n row x 2m-col (nm to minimize overall latency) RAS 2n n m 2m sense amp and mux 1 A DRAM die comprises of multiple such arrays CAS
21
DRAM vs. SRAM DRAM SRAM Slower access (capacitor)
Higher density (1T 1C cell) Lower cost Requires refresh (power, performance, circuitry) Manufacturing requires putting capacitor and logic together SRAM Faster access (no capacitor) Lower density (6T cell) Higher cost No need for refresh Manufacturing compatible with logic process (no capacitor)
22
The Problem Bigger is slower
SRAM, 512 Bytes, sub-nanosec SRAM, KByte~MByte, ~nanosec DRAM, Gigabyte, ~50 nanosec Hard Disk, Terabyte, ~10 millisec Faster is more expensive (dollars and chip area) SRAM, < 10$ per Megabyte DRAM, < 1$ per Megabyte Hard Disk < 1$ per Gigabyte These sample values (circa ~2011) scale with time Other technologies have their place as well Flash memory, PC-RAM, MRAM, RRAM (not mature yet)
23
Why Memory Hierarchy? We want both fast and large
But we cannot achieve both with a single level of memory Idea: Have multiple levels of storage (progressively bigger and slower as the levels are farther from the processor) and ensure most of the data the processor needs is kept in the fast(er) level(s)
24
Memory Hierarchy Fundamental tradeoff Idea: Memory hierarchy
Fast memory: small Large memory: slow Idea: Memory hierarchy Latency, cost, size, bandwidth Hard Disk Main Memory (DRAM) CPU Cache RF
25
Locality One’s recent past is a very good predictor of his/her near future. Temporal Locality: If you just did something, it is very likely that you will do the same thing again soon since you are here today, there is a good chance you will be here again and again regularly Spatial Locality: If you did something, it is very likely you will do something similar/related (in space) every time I find you in this room, you are probably sitting close to the same people
26
Memory Locality A “typical” program has a lot of locality in memory references typical programs are composed of “loops” Temporal: A program tends to reference the same memory location many times and all within a small window of time Spatial: A program tends to reference a cluster of memory locations at a time most notable examples: 1. instruction memory references 2. array/data structure references
27
Caching Basics: Exploit Temporal Locality
Idea: Store recently accessed data in automatically managed fast memory (called cache) Anticipation: the data will be accessed again soon Temporal locality principle Recently accessed data will be again accessed in the near future This is what Maurice Wilkes had in mind: Wilkes, “Slave Memories and Dynamic Storage Allocation,” IEEE Trans. On Electronic Computers, 1965. “The use is discussed of a fast core memory of, say words as a slave to a slower core memory of, say, one million words in such a way that in practical cases the effective access time is nearer that of the fast memory than that of the slow memory.”
28
Caching Basics: Exploit Spatial Locality
Idea: Store addresses adjacent to the recently accessed one in automatically managed fast memory Logically divide memory into equal size blocks Fetch to cache the accessed block in its entirety Anticipation: nearby data will be accessed soon Spatial locality principle Nearby data in memory will be accessed in the near future E.g., sequential instruction access, array traversal This is what IBM 360/85 implemented 16 Kbyte cache with 64 byte blocks Liptay, “Structural aspects of the System/360 Model 85 II: the cache,” IBM Systems Journal, 1968.
29
A Note on Manual vs. Automatic Management
Manual: Programmer manages data movement across levels -- too painful for programmers on substantial programs “core” vs “drum” memory in the 50’s still done in some embedded processors (on-chip scratch pad SRAM in lieu of a cache) Automatic: Hardware manages data movement across levels, transparently to the programmer ++ programmer’s life is easier simple heuristic: keep most recently used items in cache the average programmer doesn’t need to know about it You don’t need to know how big the cache is and how it works to write a “correct” program! (What if you want a “fast” program?)
30
Automatic Management in Memory Hierarchy
Wilkes, “Slave Memories and Dynamic Storage Allocation,” IEEE Trans. On Electronic Computers, 1965. “By a slave memory I mean one which automatically accumulates to itself words that come from a slower main memory, and keeps them available for subsequent use without it being necessary for the penalty of main memory access to be incurred again.”
31
Historical Aside: Other Cache Papers
Fotheringham, “Dynamic Storage Allocation in the Atlas Computer, Including an Automatic Use of a Backing Store,” CACM 1961. Bloom, Cohen, Porter, “Considerations in the Design of a Computer with High Logic-to-Memory Speed Ratio,” AIEE Gigacycle Computing Systems Winter Meeting, Jan
32
Cache in 1962 (Bloom, Cohen, Porter)
33
A Modern Memory Hierarchy
Register File 32 words, sub-nsec L1 cache ~32 KB, ~nsec L2 cache 512 KB ~ 1MB, many nsec L3 cache, ..... Main memory (DRAM), GB, ~100 nsec Swap Disk 100 GB, ~10 msec manual/compiler register spilling Memory Abstraction Automatic HW cache management automatic demand paging
34
Review: Hierarchical Latency Analysis
For a given memory hierarchy level i it has a technology-intrinsic access time of ti, The perceived access time Ti is longer than ti Except for the outer-most hierarchy, when looking for a given address there is a chance (hit-rate hi) you “hit” and access time is ti a chance (miss-rate mi) you “miss” and access time ti +Ti+1 hi + mi = 1 Thus Ti = hi·ti + mi·(ti + Ti+1) Ti = ti + mi ·Ti+1 hi and mi are defined to be the hit-rate and miss-rate of just the references that missed at Li-1
35
Review: Hierarchy Design Considerations
Recursive latency equation Ti = ti + mi ·Ti+1 The goal: achieve desired T1 within allowed cost Ti ti is desirable Keep mi low increasing capacity Ci lowers mi, but beware of increasing ti lower mi by smarter management (replacement::anticipate what you don’t need, prefetching::anticipate what you will need) Keep Ti+1 low faster lower hierarchies, but beware of increasing cost introduce intermediate hierarchies as a compromise
36
Review: Intel Pentium 4 Example
90nm P4, 3.6 GHz L1 D-cache C1 = 16K t1 = 4 cyc int / 9 cycle fp L2 D-cache C2 =1024 KB t2 = 18 cyc int / 18 cyc fp Main memory t3 = ~ 50ns or 180 cyc Notice best case latency is not 1 worst case access latencies are into 500+ cycles if m1=0.1, m2=0.1 T1=7.6, T2=36 if m1=0.01, m2=0.01 T1=4.2, T2=19.8 if m1=0.05, m2=0.01 T1=5.00, T2=19.8 if m1=0.01, m2=0.50 T1=5.08, T2=108
37
Cache Basics and Operation
38
Cache Generically, any structure that “memoizes” frequently used results to avoid repeating the long-latency operations required to reproduce the results from scratch, e.g. a web cache Most commonly in the on-die context: an automatically-managed memory hierarchy based on SRAM memoize in SRAM the most frequently accessed DRAM memory locations to avoid repeatedly paying for the DRAM access latency
39
Caching Basics Block (line): Unit of storage in the cache
Memory is logically divided into cache blocks that map to locations in the cache On a reference: HIT: If in cache, use cached data instead of accessing memory MISS: If not in cache, bring block into cache Maybe have to kick something else out to do it Some important cache design decisions Placement: where and how to place/find a block in cache? Replacement: what data to remove to make room in cache? Granularity of management: large or small blocks? Subblocks? Write policy: what do we do about writes? Instructions/data: do we treat them separately?
40
Cache Abstraction and Metrics
Cache hit rate = (# hits) / (# hits + # misses) = (# hits) / (# accesses) Average memory access time (AMAT) = ( hit-rate * hit-latency ) + ( miss-rate * miss-latency ) Aside: Can reducing AMAT reduce performance? Address Tag Store (is the address in the cache? + bookkeeping) Data Store (stores memory blocks) Hit/miss? Data
41
A Basic Hardware Cache Design
We will start with a basic hardware cache design Then, we will examine a multitude of ideas to make it better
42
Blocks and Addressing the Cache
Memory is logically divided into fixed-size blocks Each block maps to a location in the cache, determined by the index bits in the address used to index into the tag and data stores Cache access: 1) index into the tag and data stores with index bits in address 2) check valid bit in tag store 3) compare tag bits in address with the stored tag in tag store If a block is in the cache (cache hit), the stored tag should be valid and match the tag of the block tag index byte in block 2b 3 bits 3 bits 8-bit address
43
Direct-Mapped Cache: Placement and Access
Block: 00000 Assume byte-addressable memory: bytes, 8-byte blocks 32 blocks Assume cache: 64 bytes, 8 blocks Direct-mapped: A block can go to only one location Addresses with same index contend for the same location Cause conflict misses Block: 00001 Block: 00010 Block: 00011 Block: 00100 Block: 00101 Block: 00110 Block: 00111 Block: 01000 Block: 01001 Block: 01010 tag index byte in block Block: 01011 Block: 01100 2b 3 bits 3 bits Tag store Data store Block: 01101 Block: 01110 Address Block: 01111 Block: 10000 Block: 10001 Block: 10010 Block: 10011 Block: 10100 Block: 10101 V tag Block: 10110 Block: 10111 byte in block Block: 11000 =? MUX Block: 11001 Block: 11010 Block: 11011 Hit? Data Block: 11100 Block: 11101 Block: 11110 Block: 11111 Main memory
44
Direct-Mapped Caches Direct-mapped cache: Two blocks in memory that map to the same index in the cache cannot be present in the cache at the same time One index one entry Can lead to 0% hit rate if more than one block accessed in an interleaved manner map to the same index Assume addresses A and B have the same index bits but different tag bits A, B, A, B, A, B, A, B, … conflict in the cache index All accesses are conflict misses
45
Set Associativity Addresses 0 and 8 always conflict in direct mapped cache Instead of having one column of 8, have 2 columns of 4 blocks Tag store Data store SET V tag V tag =? =? MUX Logic byte in block MUX Hit? Address tag index byte in block Key idea: Associative memory within the set + Accommodates conflicts better (fewer conflict misses) -- More complex, slower access, larger tag store 3b 2 bits 3 bits
46
Higher Associativity 4-way + Likelihood of conflict misses even lower
-- More tag comparators and wider data mux; larger tags Tag store =? =? =? =? Logic Hit? Data store MUX byte in block MUX
47
Full Associativity Fully associative cache
A block can be placed in any cache location Tag store =? =? =? =? =? =? =? =? Logic Hit? Data store MUX byte in block MUX
48
Associativity (and Tradeoffs)
Degree of associativity: How many blocks can map to the same index (or set)? Higher associativity ++ Higher hit rate -- Slower cache access time (hit latency and data access latency) -- More expensive hardware (more comparators) Diminishing returns from higher associativity hit rate associativity
49
Issues in Set-Associative Caches
Think of each block in a set having a “priority” Indicating how important it is to keep the block in the cache Key issue: How do you determine/adjust block priorities? There are three key decisions in a set: Insertion, promotion, eviction (replacement) Insertion: What happens to priorities on a cache fill? Where to insert the incoming block, whether or not to insert the block Promotion: What happens to priorities on a cache hit? Whether and how to change block priority Eviction/replacement: What happens to priorities on a cache miss? Which block to evict and how to adjust priorities
50
Eviction/Replacement Policy
Which block in the set to replace on a cache miss? Any invalid block first If all are valid, consult the replacement policy Random FIFO Least recently used (how to implement?) Not most recently used Least frequently used? Least costly to re-fetch? Why would memory accesses have different cost? Hybrid replacement policies Optimal replacement policy?
51
Implementing LRU Idea: Evict the least recently accessed block
Problem: Need to keep track of access ordering of blocks Question: 2-way set associative cache: What do you need to implement LRU perfectly? Question: 4-way set associative cache: How many different orderings possible for the 4 blocks in the set? How many bits needed to encode the LRU order of a block? What is the logic needed to determine the LRU victim?
52
Approximations of LRU Most modern processors do not implement “true LRU” (also called “perfect LRU”) in highly-associative caches Why? True LRU is complex LRU is an approximation to predict locality anyway (i.e., not the best possible cache management policy) Examples: Not MRU (not most recently used) Hierarchical LRU: divide the N-way set into M “groups”, track the MRU group and the MRU way in each group Victim-NextVictim Replacement: Only keep track of the victim and the next victim
53
Cache Replacement Policy: LRU or Random
LRU vs. Random: Which one is better? Example: 4-way cache, cyclic references to A, B, C, D, E 0% hit rate with LRU policy Set thrashing: When the “program working set” in a set is larger than set associativity Random replacement policy is better when thrashing occurs In practice: Depends on workload Average hit rate of LRU and Random are similar Best of both Worlds: Hybrid of LRU and Random How to choose between the two? Set sampling See Qureshi et al., “A Case for MLP-Aware Cache Replacement,“ ISCA 2006.
54
What Is the Optimal Replacement Policy?
Belady’s OPT Replace the block that is going to be referenced furthest in the future by the program Belady, “A study of replacement algorithms for a virtual-storage computer,” IBM Systems Journal, 1966. How do we implement this? Simulate? Is this optimal for minimizing miss rate? Is this optimal for minimizing execution time? No. Cache miss latency/cost varies from block to block! Two reasons: Remote vs. local caches and miss overlapping Qureshi et al. “A Case for MLP-Aware Cache Replacement,“ ISCA 2006.
55
Reading Key observation: Some misses more costly than others as their latency is exposed as stall time. Reducing miss rate is not always good for performance. Cache replacement should take into account MLP of misses. Moinuddin K. Qureshi, Daniel N. Lynch, Onur Mutlu, and Yale N. Patt, "A Case for MLP-Aware Cache Replacement" Proceedings of the 33rd International Symposium on Computer Architecture (ISCA), pages , Boston, MA, June 2006. Slides (ppt)
56
Aside: Cache versus Page Replacement
Physical memory (DRAM) is a cache for disk Usually managed by system software via the virtual memory subsystem Page replacement is similar to cache replacement Page table is the “tag store” for physical memory data store What is the difference? Required speed of access to cache vs. physical memory Number of blocks in a cache vs. physical memory “Tolerable” amount of time to find a replacement candidate (disk versus memory access latency) Role of hardware versus software
57
What’s In A Tag Store Entry?
Valid bit Tag Replacement policy bits Dirty bit? Write back vs. write through caches
58
Handling Writes (I) When do we write the modified data in a cache to the next level? Write through: At the time the write happens Write back: When the block is evicted Write-back + Can combine multiple writes to the same block before eviction Potentially saves bandwidth between cache levels + saves energy -- Need a bit in the tag store indicating the block is “dirty/modified” Write-through + Simpler + All levels are up to date. Consistency: Simpler cache coherence because no need to check close-to-processor caches’ tag stores for presence -- More bandwidth intensive; no combining of writes
59
Computer Architecture Lecture 3b: Memory Hierarchy and Caches
Prof. Onur Mutlu ETH Zürich Fall 2018 26 September 2018
60
We did not cover the following slides in lecture
We did not cover the following slides in lecture. These are for your preparation for the next lecture.
61
Handling Writes (II) What if the processor writes to an entire block over a small amount of time? Is there any need to bring the block into the cache from memory in the first place? Ditto for a portion of the block, i.e., subblock E.g., 4 bytes out of 64 bytes
62
Sectored Caches Idea: Divide a block into subblocks (or sectors)
Have separate valid and dirty bits for each sector When is this useful? (Think writes…) ++ No need to transfer the entire cache block into the cache (A write simply validates and updates a subblock) ++ More freedom in transferring subblocks into the cache (a cache block does not need to be in the cache fully) (How many subblocks do you transfer on a read?) -- More complex design -- May not exploit spatial locality fully when used for reads v subblock d v subblock d v subblock d tag
63
Instruction vs. Data Caches
Separate or Unified? Unified: + Dynamic sharing of cache space: no overprovisioning that might happen with static partitioning (i.e., split I and D caches) -- Instructions and data can thrash each other (i.e., no guaranteed space for either) -- I and D are accessed in different places in the pipeline. Where do we place the unified cache for fast access? First level caches are almost always split Mainly for the last reason above Second and higher levels are almost always unified
64
Multi-level Caching in a Pipelined Design
First-level caches (instruction and data) Decisions very much affected by cycle time Small, lower associativity Tag store and data store accessed in parallel Second-level caches Decisions need to balance hit rate and access latency Usually large and highly associative; latency not as important Tag store and data store accessed serially Serial vs. Parallel access of levels Serial: Second level cache accessed only if first-level misses Second level does not see the same accesses as the first First level acts as a filter (filters some temporal and spatial locality) Management policies are therefore different
65
Cache Performance (for Your Review)
See Lecture 25a (More Caches) from Digital Circuits Spring 2018
66
Cache Parameters vs. Miss/Hit Rate
Cache size Block size Associativity Replacement policy Insertion/Placement policy
67
Cache Size Cache size: total data (not including tag) capacity
bigger can exploit temporal locality better not ALWAYS better Too large a cache adversely affects hit and miss latency smaller is faster => bigger is slower access time may degrade critical path Too small a cache doesn’t exploit temporal locality well useful data replaced often Working set: the whole set of data the executing application references Within a time interval hit rate “working set” size cache size
68
Block Size Block size is the data that is associated with an address tag not necessarily the unit of transfer between hierarchies Sub-blocking: A block divided into multiple pieces (each w/ V/D bits) Too small blocks don’t exploit spatial locality well have larger tag overhead Too large blocks too few total # of blocks less temporal locality exploitation waste of cache space and bandwidth/energy if spatial locality is not high hit rate block size
69
Large Blocks: Critical-Word and Subblocking
Large cache blocks can take a long time to fill into the cache fill cache line critical word first restart cache access before complete fill Large cache blocks can waste bus bandwidth divide a block into subblocks associate separate valid and dirty bits for each subblock Recall: When is this useful? v subblock d v subblock d v subblock d tag
70
Associativity How many blocks can be present in the same index (i.e., set)? Larger associativity lower miss rate (reduced conflicts) higher hit latency and area cost (plus diminishing returns) Smaller associativity lower cost lower hit latency Especially important for L1 caches Is power of 2 associativity required? hit rate associativity
71
End of Cache Performance (for Your Review)
See Lecture 25a (More Caches) from Digital Circuits Spring 2018
72
Classification of Cache Misses
Compulsory miss first reference to an address (block) always results in a miss subsequent references should hit unless the cache block is displaced for the reasons below Capacity miss cache is too small to hold everything needed defined as the misses that would occur even in a fully-associative cache (with optimal replacement) of the same capacity Conflict miss defined as any miss that is neither a compulsory nor a capacity miss
73
How to Reduce Each Miss Type
Compulsory Caching cannot help Prefetching can: Anticipate which blocks will be needed soon Conflict More associativity Other ways to get more associativity without making the cache associative Victim cache Better, randomized indexing Software hints? Capacity Utilize cache space better: keep blocks that will be referenced Software management: divide working set and computation such that each “computation phase” fits in cache
74
How to Improve Cache Performance
Three fundamental goals Reducing miss rate Caveat: reducing miss rate can reduce performance if more costly-to-refetch blocks are evicted Reducing miss latency or miss cost Reducing hit latency or hit cost The above three together affect performance
75
Classification of Cache Misses
Compulsory miss first reference to an address (block) always results in a miss subsequent references should hit unless the cache block is displaced for the reasons below Capacity miss cache is too small to hold everything needed defined as the misses that would occur even in a fully-associative cache (with optimal replacement) of the same capacity Conflict miss defined as any miss that is neither a compulsory nor a capacity miss
76
How to Reduce Each Miss Type
Compulsory Caching cannot help Prefetching can Conflict More associativity Other ways to get more associativity without making the cache associative Victim cache Better, randomized indexing Software hints? Capacity Utilize cache space better: keep blocks that will be referenced Software management: divide working set such that each “phase” fits in cache
77
How to Improve Cache Performance
Three fundamental goals Reducing miss rate Caveat: reducing miss rate can reduce performance if more costly-to-refetch blocks are evicted Reducing miss latency or miss cost Reducing hit latency or hit cost The above three together affect performance
78
Improving Basic Cache Performance
Reducing miss rate More associativity Alternatives/enhancements to associativity Victim caches, hashing, pseudo-associativity, skewed associativity Better replacement/insertion policies Software approaches Reducing miss latency/cost Multi-level caches Critical word first Subblocking/sectoring Non-blocking caches (multiple cache misses in parallel) Multiple accesses per cycle
79
Cheap Ways of Reducing Conflict Misses
Instead of building highly-associative caches: Victim Caches Hashed/randomized Index Functions Pseudo Associativity Skewed Associative Caches …
80
Victim Cache: Reducing Conflict Misses
Jouppi, “Improving Direct-Mapped Cache Performance by the Addition of a Small Fully-Associative Cache and Prefetch Buffers,” ISCA 1990. Idea: Use a small fully-associative buffer (victim cache) to store recently evicted blocks + Can avoid ping ponging of cache blocks mapped to the same set (if two cache blocks continuously accessed in nearby time conflict with each other) -- Increases miss latency if accessed serially with L2; adds complexity Victim cache Direct Mapped Cache Next Level Cache
81
Hashing and Pseudo-Associativity
Hashing: Use better “randomizing” index functions + can reduce conflict misses by distributing the accessed memory blocks more evenly to sets Example of conflicting accesses: strided access pattern where stride value equals number of sets in cache -- More complex to implement: can lengthen critical path Pseudo-associativity (Poor Man’s associative cache) Serial lookup: On a miss, use a different index function and access cache again Given a direct-mapped array with K cache blocks Implement K/N sets Given address Addr, sequentially look up: {0,Addr[lg(K/N)-1: 0]}, {1,Addr[lg(K/N)-1: 0]}, … , {N-1,Addr[lg(K/N)-1: 0]} + Less complex than N-way; -- Longer cache hit/miss latency
82
Skewed Associative Caches
Idea: Reduce conflict misses by using different index functions for each cache way Seznec, “A Case for Two-Way Skewed-Associative Caches,” ISCA 1993.
83
Skewed Associative Caches (I)
Basic 2-way associative cache structure Way 1 Way 0 Same index function for each way =? =? Tag Index Byte in Block
84
Skewed Associative Caches (II)
Each bank has a different index function same index redistributed to different sets same index same set Way 0 Way 1 f0 =? tag index byte in block =?
85
Skewed Associative Caches (III)
Idea: Reduce conflict misses by using different index functions for each cache way Benefit: indices are more randomized (memory blocks are better distributed across sets) Less likely two blocks have same index (esp. with strided access) Reduced conflict misses Cost: additional latency of hash function Seznec, “A Case for Two-Way Skewed-Associative Caches,” ISCA 1993.
86
Software Approaches for Higher Hit Rate
Restructuring data access patterns Restructuring data layout Loop interchange Data structure separation/merging Blocking …
87
Restructuring Data Access Patterns (I)
Idea: Restructure data layout or data access patterns Example: If column-major x[i+1,j] follows x[i,j] in memory x[i,j+1] is far away from x[i,j] This is called loop interchange Other optimizations can also increase hit rate Loop fusion, array merging, … What if multiple arrays? Unknown array size at compile time? Poor code for i = 1, rows for j = 1, columns sum = sum + x[i,j] Better code for j = 1, columns for i = 1, rows sum = sum + x[i,j]
88
Restructuring Data Access Patterns (II)
Blocking Divide loops operating on arrays into computation chunks so that each chunk can hold its data in the cache Avoids cache conflicts between different chunks of computation Essentially: Divide the working set so that each piece fits in the cache But, there are still self-conflicts in a block 1. there can be conflicts among different arrays 2. array sizes may be unknown at compile/programming time
89
Restructuring Data Layout (I)
Pointer based traversal (e.g., of a linked list) Assume a huge linked list (1B nodes) and unique keys Why does the code on the left have poor cache hit rate? “Other fields” occupy most of the cache line even though rarely accessed! struct Node { struct Node* next; int key; char [256] name; char [256] school; } while (node) { if (nodekey == input-key) { // access other fields of node node = nodenext;
90
Restructuring Data Layout (II)
struct Node { struct Node* next; int key; struct Node-data* node-data; } struct Node-data { char [256] name; char [256] school; while (node) { if (nodekey == input-key) { // access nodenode-data node = nodenext; Idea: separate frequently-used fields of a data structure and pack them into a separate data structure Who should do this? Programmer Compiler Profiling vs. dynamic Hardware? Who can determine what is frequently used?
91
Improving Basic Cache Performance
Reducing miss rate More associativity Alternatives/enhancements to associativity Victim caches, hashing, pseudo-associativity, skewed associativity Better replacement/insertion policies Software approaches Reducing miss latency/cost Multi-level caches Critical word first Subblocking/sectoring Non-blocking caches (multiple cache misses in parallel) Multiple accesses per cycle
92
Miss Latency/Cost What is miss latency or miss cost affected by?
Where does the miss get serviced from? Local vs. remote memory What level of cache in the hierarchy? Row hit versus row miss in DRAM Queueing delays in the memory controller and the interconnect … How much does the miss stall the processor? Is it overlapped with other latencies? Is the data immediately needed?
93
Memory Level Parallelism (MLP)
parallel miss isolated miss B A C time Memory Level Parallelism (MLP) means generating and servicing multiple memory accesses in parallel [Glew’98] Several techniques to improve MLP (e.g., out-of-order execution) MLP varies. Some misses are isolated and some parallel How does this affect cache replacement? Processors are fast, Memory is slow. One way to bridge this gap is to service the memory accesses in parallel. If misses are serviced in parallel, the processor incurs only one long latency stall for all the parallel misses. The notion of generating and servicing off-chip accesses in parallel is termed as Memory Level Parallelism or MLP. Out of order processors improve MLP by continuing processing of independent instructions till the instruction window is full. If there is a miss during the processing of independent instructions, the miss is serviced concurrently with the stalling miss. There are several techniques, such as Runahead, CFP, to improve the MLP of out-of-order processors. MLP is not uniform for all cache misses. Some misses, such as pointer chasing loads, are typically serviced with low MLP while other misses, such as array accesses are serviced with high MLP. Current cache management techniques are not aware of this variation in MLP.
94
Traditional Cache Replacement Policies
Traditional cache replacement policies try to reduce miss count Implicit assumption: Reducing miss count reduces memory-related stall time Misses with varying cost/MLP breaks this assumption! Eliminating an isolated miss helps performance more than eliminating a parallel miss Eliminating a higher-latency miss could help performance more than eliminating a lower-latency miss
95
An Example S1 P4 P3 P2 P1 P1 P2 P3 P4 S2 S3
Misses to blocks P1, P2, P3, P4 can be parallel Misses to blocks S1, S2, and S3 are isolated Two replacement algorithms: Minimizes miss count (Belady’s OPT) Reduces isolated miss (MLP-Aware) For a fully associative cache containing 4 blocks There are 11 memory access instructions in the loop. The accesses to cache blocks P1, P2, P3, P4 occur in the instruction window at same time. If these accesses result in more than 1 miss, then those misses are serviced in parallel. Conversely, misses to the S blocks are spaced far apart in time to misses to the S blocks are always serviced in isolation. This loop executes many time. I will analyze the cache behavior of this loop for two replacement algorithms. The first minimizes the number of misses. The well known Belady's opt algorithm provides a theoretical lower bound on the number of misses. The other is MLP-aware replacement, which tries to reduce the number of isolated miss.
96
Fewest Misses = Best Performance
Cache S1 S2 S3 P1 P3 P2 P1 P4 P3 P2 P1 P4 S1 S2 S3 P4 P3 P2 S1 P4 P3 P2 S2 P4 P3 P2 S3 P4 P4 P3 P2 P1 P1 P2 P3 P4 S1 S2 S3 Hit/Miss H H H M H H H H M M M Misses=4 Stalls=4 Time stall Belady’s OPT replacement Although Belady’s OPT minimizes misses, it is impossible to implement it in a real processor as it requires knowledge of the future. We employ the commonly used LRU policy in our experiments Hit/Miss H M M M H M M M H H H Saved cycles Time stall Misses=6Stalls=2 MLP-Aware replacement
97
MLP-Aware Cache Replacement
How do we incorporate MLP into replacement decisions? Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2006. Reading for review
98
Other Recommended Cache Papers (I)
Qureshi et al., “Adaptive Insertion Policies for High Performance Caching,” ISCA 2007.
99
Other Recommended Cache Papers (II)
Seshadri et al., “The Evicted-Address Filter: A Unified Mechanism to Address Both Cache Pollution and Thrashing,” PACT 2012.
100
Other Recommended Cache Papers (III)
Pekhimenko et al., “Base-Delta-Immediate Compression: Practical Data Compression for On-Chip Caches,” PACT 2012.
101
Hybrid Cache Replacement (Selecting Between Multiple Replacement Policies)
102
Hybrid Cache Replacement
Problem: Not a single policy provides the highest performance For any given set For the entire cache overall Idea: Implement both policies and pick the one that is expected to perform best at runtime On a per-set basis or for the entire cache + Higher performance -- Higher cost, complexity; Need selection mechanism How do you determine the best policy? Implement multiple tag stores, each following a particular policy Find the best and have the main tag store follow the best policy
103
Terminology Tag Store is also called Tag Directory
Main Tag Store/Directory (MTD) Tag Store that is actually used to keep track of the block addresses present in the cache Auxiliary Tag Store/Directory (ATD-PolicyX) Tag Store that is used to emulate a policy X Not used for tracking the block addresses present in the cache Used for tracking what the block addresses in the cache would have been if the cache were following Policy X
104
Tournament Selection (TSEL) of Replacement Policies for a Single Set
SCTR ATD-Policy1 ATD-Policy2 + SET A SET A If MSB of SCTR is 1, MTD uses Policy1, else MTD uses Policy2 SET A MTD ATD-Policy1 ATD-Policy2 Saturating Counter (SCTR) HIT Unchanged MISS += Cost of Miss in ATD-Policy2 -= Cost of Miss in ATD-Policy1 We use the tournament selection algorithm commonly employed in branch predictors. The performance of both LIN and LRU are tracked using separate tag directories, called Auxiliary Tag Directory (ATD). ATD-LIN uses the LIN policy and ATD-LRU uses the LRU policy. Each access for the main tag directory are also send to both the ATD’s. A saturating counter is used to track, which of the two policies is performing better. If there is a hit in ATD-LIN and a miss in ATD-LRU the saturating counter is incremented by a value equal to the cost of the miss in LRU. If miss in ATD-LRU and hit in ATD-LIN then the saturating counter is decremented by a value equal to the cost of the miss in LIN. Thus the high bit of the counter is an indicator of which of the two policies, LIN or LRU, is doing better. If the high bit is 1, MTD uses LRU else it uses LIN. Implementing tournament selection on a per-set basis is expensive as it requires a counter and two extra tag directories for each set. Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2006.
105
Extending TSEL to All Sets
Implementing TSEL on a per-set basis is expensive Counter overhead can be reduced by using a global counter + SCTR Policy for All Sets In MTD Set A ATD-Policy1 Set B Set C Set D Set E Set F Set G Set H ATD-Policy2 The overhead of the counter can be reduced by using a single counter to choose a replacement policy for all the sets in the cache. The figure shows how such a mechanism for a cache that has 8 sets. Although the mechanism requires only one counter it still requires overhead of two extra tag directories. Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2006.
106
Dynamic Set Sampling (DSS)
Not all sets are required to decide the best policy Have the ATD entries only for few sets. ATD-Policy1 ATD-Policy2 Set A Set C Set D Set F Set H Set B Set B SCTR + Set E Set E To reduce the overhead of the tag directories, we introduce the dynamic set sampling technique. The key idea is that not all sets are required to decide the best policy. The mechanism can still choose the best policy with a high probability even if only few sets are sampled. The ATD entries are present only for 3 sets, B, E, and G. These sets decide the replacement policy for all sets in the MTD, hence we call these sets as leader sets. Set G Set G Policy for All Sets In MTD Sets that have ATD entries (B, E, G) are called leader sets Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2006.
107
Dynamic Set Sampling (DSS)
How many sets are required to choose best performing policy? Bounds using analytical model and simulation (in paper) DSS with 32 leader sets performs similar to having all sets Last-level cache typically contains 1000s of sets, thus ATD entries are required for only 2%-3% of the sets ATD overhead can further be reduced by using MTD to always simulate one of the policies (say Policy1) Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2006.
108
Sampling Based Adaptive Replacement (SBAR)
MTD Set A Set B ATD-Policy2 SCTR Set C Set B Set D + Set E Set E Set G Set F Set G Set H Leader sets Decide policy only for follower sets Follower sets The storage overhead of SBAR is less than 2KB (0.2% of the baseline 1MB cache) Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2006.
109
Results for SBAR Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2006.
110
SBAR adaptation to phases
LIN is better LRU is better SBAR selects the best policy for each phase of this application
111
Enabling Multiple Outstanding Misses
112
Handling Multiple Outstanding Accesses
Question: If the processor can generate multiple cache accesses, can the later accesses be handled while a previous miss is outstanding? Goal: Enable cache access when there is a pending miss Goal: Enable multiple misses in parallel Memory-level parallelism (MLP) Solution: Non-blocking or lockup-free caches Kroft, “Lockup-Free Instruction Fetch/Prefetch Cache Organization," ISCA 1981.
113
Handling Multiple Outstanding Accesses
Idea: Keep track of the status/data of misses that are being handled in Miss Status Handling Registers (MSHRs) A cache access checks MSHRs to see if a miss to the same block is already pending. If pending, a new request is not generated If pending and the needed data available, data forwarded to later load Requires buffering of outstanding miss requests
114
Miss Status Handling Register
Also called “miss buffer” Keeps track of Outstanding cache misses Pending load/store accesses that refer to the missing cache block Fields of a single MSHR entry Valid bit Cache block address (to match incoming accesses) Control/status bits (prefetch, issued to memory, which subblocks have arrived, etc) Data for each subblock For each pending load/store Valid, type, data size, byte in block, destination register or store buffer entry address
115
Miss Status Handling Register Entry
116
MSHR Operation On a cache miss:
Search MSHRs for a pending access to the same block Found: Allocate a load/store entry in the same MSHR entry Not found: Allocate a new MSHR No free entry: stall When a subblock returns from the next level in memory Check which loads/stores waiting for it Forward data to the load/store unit Deallocate load/store entry in the MSHR entry Write subblock in cache or MSHR If last subblock, deallocate MSHR (after writing the block in cache)
117
Non-Blocking Cache Implementation
When to access the MSHRs? In parallel with the cache? After cache access is complete? MSHRs need not be on the critical path of hit requests Which one below is the common case? Cache miss, MSHR hit Cache hit
118
Enabling High Bandwidth Memories
119
Multiple Instructions per Cycle
Processors can generate multiple cache/memory accesses per cycle How do we ensure the cache/memory can handle multiple accesses in the same clock cycle? Solutions: true multi-porting virtual multi-porting (time sharing a port) multiple cache copies banking (interleaving)
120
Handling Multiple Accesses per Cycle (I)
True multiporting Each memory cell has multiple read or write ports + Truly concurrent accesses (no conflicts on read accesses) -- Expensive in terms of latency, power, area What about read and write to the same location at the same time? Peripheral logic needs to handle this
121
Peripheral Logic for True Multiporting
122
Peripheral Logic for True Multiporting
123
Handling Multiple Accesses per Cycle (II)
Virtual multiporting Time-share a single port Each access needs to be (significantly) shorter than clock cycle Used in Alpha 21264 Is this scalable?
124
Handling Multiple Accesses per Cycle (III)
Multiple cache copies Stores update both caches Loads proceed in parallel Used in Alpha 21164 Scalability? Store operations cause a bottleneck Area proportional to “ports” Port 1 Load Cache Copy 1 Port 1 Data Store Cache Copy 2 Port 2 Data Port 2 Load
125
Handling Multiple Accesses per Cycle (III)
Banking (Interleaving) Address space partitioned into separate banks Bits in address determines which bank an address maps to Which bits to use for “bank address”? + No increase in data store area -- Cannot satisfy multiple accesses to the same bank in parallel -- Crossbar interconnect in input/output Bank conflicts Concurrent requests to the same bank How can these be reduced? Hardware? Software? Bank 0: Even addresses Bank 1: Odd addresses
126
General Principle: Interleaving
Interleaving (banking) Problem: a single monolithic memory array takes long to access and does not enable multiple accesses in parallel Goal: Reduce the latency of memory array access and enable multiple accesses in parallel Idea: Divide the array into multiple banks that can be accessed independently (in the same cycle or in consecutive cycles) Each bank is smaller than the entire memory storage Access latencies to different banks can be overlapped A Key Issue: How do you map data to different banks? (i.e., how do you interleave data across banks?)
127
Further Readings on Caching and MLP
Required: Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2006. One Pager: Glew, “MLP Yes! ILP No!,” ASPLOS Wild and Crazy Ideas Session, 1998. Mutlu et al., “Runahead Execution: An Effective Alternative to Large Instruction Windows,” IEEE Micro 2003. Li et al., “Utility-based Hybrid Memory Management,” CLUSTER 2017. Mutlu et al., “Parallelism-Aware Batch Scheduling,” ISCA 2008
128
Computer Architecture Lecture 3b: Memory Hierarchy and Caches
Prof. Onur Mutlu ETH Zürich Fall 2018 26 September 2018
129
We did not cover the following slides in lecture
We did not cover the following slides in lecture. These are for your preparation for the next lecture.
130
Efficient Cache Utilization
Critical for performance, especially in multi-core systems Many works in this area Three sample works Qureshi et al., “A Case for MLP-Aware Cache Replacement,” ISCA 2005. Seshadri et al., “The Evicted-Address Filter: A Unified Mechanism to Address both Cache Pollution and Thrashing,” PACT 2012. Pekhimenko et al., “Base-Delta-Immediate Compression: Practical Data Compression for On-Chip Caches,” PACT 2012.
131
MLP-Aware Cache Replacement
Moinuddin K. Qureshi, Daniel N. Lynch, Onur Mutlu, and Yale N. Patt, "A Case for MLP-Aware Cache Replacement" Proceedings of the 33rd International Symposium on Computer Architecture (ISCA), pages , Boston, MA, June Slides (ppt)
132
Memory Level Parallelism (MLP)
parallel miss isolated miss B A C time Memory Level Parallelism (MLP) means generating and servicing multiple memory accesses in parallel [Glew’98] Several techniques to improve MLP (e.g., out-of-order execution, runahead execution) MLP varies. Some misses are isolated and some parallel How does this affect cache replacement? Processors are fast, Memory is slow. One way to bridge this gap is to service the memory accesses in parallel. If misses are serviced in parallel, the processor incurs only one long latency stall for all the parallel misses. The notion of generating and servicing off-chip accesses in parallel is termed as Memory Level Parallelism or MLP. Out of order processors improve MLP by continuing processing of independent instructions till the instruction window is full. If there is a miss during the processing of independent instructions, the miss is serviced concurrently with the stalling miss. There are several techniques, such as Runahead, CFP, to improve the MLP of out-of-order processors. MLP is not uniform for all cache misses. Some misses, such as pointer chasing loads, are typically serviced with low MLP while other misses, such as array accesses are serviced with high MLP. Current cache management techniques are not aware of this variation in MLP.
133
Traditional Cache Replacement Policies
Traditional cache replacement policies try to reduce miss count Implicit assumption: Reducing miss count reduces memory-related stall time Misses with varying cost/MLP breaks this assumption! Eliminating an isolated miss helps performance more than eliminating a parallel miss Eliminating a higher-latency miss could help performance more than eliminating a lower-latency miss
134
An Example S1 P4 P3 P2 P1 P1 P2 P3 P4 S2 S3
Misses to blocks P1, P2, P3, P4 can be parallel Misses to blocks S1, S2, and S3 are isolated Two replacement algorithms: Minimizes miss count (Belady’s OPT) Reduces isolated misses (MLP-Aware) For a fully associative cache containing 4 blocks There are 11 memory access instructions in the loop. The accesses to cache blocks P1, P2, P3, P4 occur in the instruction window at same time. If these accesses result in more than 1 miss, then those misses are serviced in parallel. Conversely, misses to the S blocks are spaced far apart in time to misses to the S blocks are always serviced in isolation. This loop executes many times. I will analyze the cache behavior of this loop for two replacement algorithms. The first minimizes the number of misses. The well known Belady's opt algorithm provides a theoretical lower bound on the number of misses. The other is MLP-aware replacement, which tries to reduce the number of isolated misses.
135
Fewest Misses = Best Performance
Cache S1 S2 S3 P1 P3 P2 P1 P4 P3 P2 P1 P4 S1 S2 S3 P4 P3 P2 S1 P4 P3 P2 S2 P4 P3 P2 S3 P4 P4 P3 P2 P1 P1 P2 P3 P4 S1 S2 S3 Hit/Miss H H H M H H H H M M M Misses=4 Stalls=4 Time stall Belady’s OPT replacement Although Belady’s OPT minimizes misses, it is impossible to implement it in a real processor as it requires knowledge of the future. We employ the commonly used LRU policy in our experiments Hit/Miss H M M M H M M M H H H Saved cycles Time stall Misses=6Stalls=2 MLP-Aware replacement
136
Motivation MLP varies. Some misses more costly than others
MLP-aware replacement can improve performance by reducing costly misses Thus, misses have different MLP. The performance impact of a miss is dependent on its MLP. If this non-uniformity is made visible to the cache replacement engine, then it can reduce improve performance by reducing the number of costly misses.
137
Outline Introduction MLP-Aware Cache Replacement
Model for Computing Cost Repeatability of Cost A Cost-Sensitive Replacement Policy Practical Hybrid Replacement Tournament Selection Dynamic Set Sampling Sampling Based Adaptive Replacement Summary We have qualitatively talked about some misses being more costly on others. For making decisions based on cost we need a quantitative definition for MLP-Based cost. As a first step to enable MLP-aware cache replacement, we provide a runtime mechanism to compute MLP-Based Cost.
138
Computing MLP-Based Cost
Cost of miss is number of cycles the miss stalls the processor Easy to compute for isolated miss Divide each stall cycle equally among all parallel misses A 1 The cost of a miss can be approximated by the number of cycles the miss stalls the processor. This is easy to measure for isolated miss: every cycle the processor is stalled, the cost of the miss is incremented by 1. For parallel misses, the stalled cycle is divided equally among all parallel misses. The figure shows three misses A, B, and C. Between time t0 and t1, A incurs a cost of 1 cycle, every cycle … This algorithm can easily be implemented in hardware. B 1 C 1 t0 t1 t2 t3 t4 t5 time
139
A First-Order Model Miss Status Holding Register (MSHR) tracks all in flight misses Add a field mlp-cost to each MSHR entry Every cycle for each demand entry in MSHR mlp-cost += (1/N) N = Number of demand misses in MSHR The Miss Status Holding Register ala the MSHR tracks information about all the misses in-flight. Each MSHR entry is added a field, mlp-cost. When the miss enters MSHR, the mlp-cost associated with the miss is initialized to zero. Let N be the number of demand misses in the MSHR. Every cycle, the mlp-cost of each demand miss in MSHR is incremented by 1 over N.
140
Machine Configuration
Processor aggressive, out-of-order, 128-entry instruction window L2 Cache 1MB, 16-way, LRU replacement, 32 entry MSHR Memory 400 cycle bank access, 32 banks Bus Roundtrip delay of 11 bus cycles (44 processor cycles) These are the parameters of the baseline configuration used in our experiments. It contains an aggressive out-of-order processor with 128-entry instruction window. The baseline L2 cache is 1 mega byte 16-way and uses the LRU replacement. Memory is 400 cycles away and the bus delay is 44 cycles for roundtrip. Thus an isolated miss takes 444 cycles to get service.
141
Distribution of MLP-Based Cost
% of All L2 Misses This graph shows the distribution of MLP-based cost for the ammp benchmark. The x axis shows the cost of the miss binned at 60 cycle granularity. The y-axis shows the percentage of all L2 misses. The rightmost bar shows the fraction of misses that have a cost of more than 420 cycles. All isolated misses, and some of the parallel misses serialized because of bank conflicts are accounted for in the right bar. Thus 10% of the misses in ammp are isolated misses. About one third of the misses have a cost between 60 and 120 cycles, denoting an MLP of four. On average, the MLP-based cost of the miss is 185 cycles. (TICK) And such distribution of MLP is true for a wide range of benchmarks. Shown are the distribution of mcf and mgrid. However, to exploit this variation in cost of misses for cost-sensitive replacement, it is important that the cost of the block does not vary significantly between successive misses to the block. Cost varies. Does it repeat for a given cache block?
142
Repeatability of Cost An isolated miss can be parallel miss next time
Can current cost be used to estimate future cost ? Let d = difference in cost for successive miss to a block Small d cost repeats Large d cost varies significantly
143
Repeatability of Cost d < 60 d > 120 59 < d < 120
In general d is small repeatable cost When d is large (e.g. parser, mgrid) performance loss
144
The Framework MEMORY MSHR Quantization of Cost
Computed mlp-based cost is quantized to a 3-bit value CCL C A R E Cost-Aware Repl Engine Cost Calculation Logic L2 CACHE MLP-aware cache replacement has two components. The cost calculation logic computes the mlp-based cost of each miss using a hardware implementation of the algorithm described earlier. This cost is stored in the tag-store entry of the cache block and is used for cost-aware replacement. To reduce storage overhead the mlp-based cost is quantized into a 3-bit value using the following table and this 3-bit quantized cost is used for replacement decisions. ICACHE DCACHE PROCESSOR
145
Design of MLP-Aware Replacement policy
LRU considers only recency and no cost Victim-LRU = min { Recency (i) } Decisions based only on cost and no recency hurt performance. Cache stores useless high cost blocks A Linear (LIN) function that considers recency and cost Victim-LIN = min { Recency (i) + S*cost (i) } S = significance of cost. Recency(i) = position in LRU stack cost(i) = quantized cost
146
Results for the LIN policy
Performance loss for parser and mgrid due to large d .
147
Effect of LIN policy on Cost
Miss += 4% IPC += 4% Miss -= 11% IPC += 22% Miss += 30% IPC -= 33%
148
Outline Introduction MLP-Aware Cache Replacement
Model for Computing Cost Repeatability of Cost A Cost-Sensitive Replacement Policy Practical Hybrid Replacement Tournament Selection Dynamic Set Sampling Sampling Based Adaptive Replacement Summary
149
Tournament Selection (TSEL) of Replacement Policies for a Single Set
SCTR ATD-LIN ATD-LRU + SET A SET A If MSB of SCTR is 1, MTD uses LIN else MTD use LRU SET A MTD ATD-LIN ATD-LRU Saturating Counter (SCTR) HIT Unchanged MISS += Cost of Miss in ATD-LRU -= Cost of Miss in ATD-LIN We use the tournament selection algorithm commonly employed in branch predictors. The performance of both LIN and LRU are tracked using separate tag directories, called Auxiliary Tag Directory (ATD). ATD-LIN uses the LIN policy and ATD-LRU uses the LRU policy. Each access for the main tag directory are also send to both the ATD’s. A saturating counter is used to track, which of the two policies is performing better. If there is a hit in ATD-LIN and a miss in ATD-LRU the saturating counter is incremented by a value equal to the cost of the miss in LRU. If miss in ATD-LRU and hit in ATD-LIN then the saturating counter is decremented by a value equal to the cost of the miss in LIN. Thus the high bit of the counter is an indicator of which of the two policies, LIN or LRU, is doing better. If the high bit is 1, MTD uses LRU else it uses LIN. Implementing tournament selection on a per-set basis is expensive as it requires a counter and two extra tag directories for each set.
150
Extending TSEL to All Sets
Implementing TSEL on a per-set basis is expensive Counter overhead can be reduced by using a global counter + SCTR Policy for All Sets In MTD Set A ATD-LIN Set B Set C Set D Set E Set F Set G Set H ATD-LRU The overhead of the counter can be reduced by using a single counter to choose a replacement policy for all the sets in the cache. The figure shows how such a mechanism for a cache that has 8 sets. Although the mechanism requires only one counter it still requires overhead of two extra tag directories.
151
Dynamic Set Sampling Not all sets are required to decide the best policy Have the ATD entries only for few sets. ATD-LIN ATD-LRU Set A Set C Set D Set F Set H Set B Set B SCTR + Set E Set E To reduce the overhead of the tag directories, we introduce the dynamic set sampling technique. The key idea is that not all sets are required to decide the best policy. The mechanism can still choose the best policy with a high probability even if only few sets are sampled. The ATD entries are present only for 3 sets, B, E, and G. These sets decide the replacement policy for all sets in the MTD, hence we call these sets as leader sets. Set G Set G Policy for All Sets In MTD Sets that have ATD entries (B, E, G) are called leader sets
152
Dynamic Set Sampling How many sets are required to choose best performing policy? Bounds using analytical model and simulation (in paper) DSS with 32 leader sets performs similar to having all sets Last-level cache typically contains 1000s of sets, thus ATD entries are required for only 2%-3% of the sets ATD overhead can further be reduced by using MTD to always simulate one of the policies (say LIN)
153
Sampling Based Adaptive Replacement (SBAR)
MTD Set A Set B ATD-LRU SCTR Set C Set B Set D + Set E Set E Set G Set F Set G Set H Leader sets Decide policy only for follower sets Follower sets The storage overhead of SBAR is less than 2KB (0.2% of the baseline 1MB cache)
154
Results for SBAR
155
SBAR adaptation to phases
LIN is better LRU is better SBAR selects the best policy for each phase of ammp
156
Outline Introduction MLP-Aware Cache Replacement
Model for Computing Cost Repeatability of Cost A Cost-Sensitive Replacement Policy Practical Hybrid Replacement Tournament Selection Dynamic Set Sampling Sampling Based Adaptive Replacement Summary
157
Summary MLP varies. Some misses are more costly than others
MLP-aware cache replacement can reduce costly misses Proposed a runtime mechanism to compute MLP-Based cost and the LIN policy for MLP-aware cache replacement SBAR allows dynamic selection between LIN and LRU with low hardware overhead Dynamic set sampling used in SBAR also enables other cache related optimizations
158
The Evicted-Address Filter
Vivek Seshadri, Onur Mutlu, Michael A. Kozuch, and Todd C. Mowry, "The Evicted-Address Filter: A Unified Mechanism to Address Both Cache Pollution and Thrashing" Proceedings of the 21st ACM International Conference on Parallel Architectures and Compilation Techniques (PACT), Minneapolis, MN, September Slides (pptx)
159
Executive Summary Two problems degrade cache performance EAF-Cache
Pollution and thrashing Prior works don’t address both problems concurrently Goal: A mechanism to address both problems EAF-Cache Keep track of recently evicted block addresses in EAF Insert low reuse with low priority to mitigate pollution Clear EAF periodically to mitigate thrashing Low complexity implementation using Bloom filter EAF-Cache outperforms five prior approaches that address pollution or thrashing …
160
Cache Utilization is Important
Large latency Memory Core Core Last-Level Cache All high-performance processors employ on-chip caches. In most modern systems, multiple cores share the last-level cache. With the large latency of main memory access and increasing contention between multiple cores, effective cache utilization is critical for system performance. For effective cache utilization, the cache should be filled with blocks that are likely to be reused. Increasing contention Effective cache utilization is important
161
Reuse Behavior of Cache Blocks
Different blocks have different reuse behavior Access Sequence: A B C A B C S T U V W X Y Z A B C High-reuse block Low-reuse block However, different blocks have different reuse behaviors. For example, consider the following access sequence. Blocks A, B and C are accessed repeatedly. We refer to such blocks as High reuse blocks. On the other hand, the remaining blocks are not reused. We refer to such blocks as low-reuse blocks. Ideally, the cache should be filled with high-reuse blocks such as A, B and C. But traditional cache management policies such as LRU suffer from two problems. A B C . Ideal Cache
162
Cache Pollution Problem: Low-reuse blocks evict high-reuse blocks
F E D U T S H G F E D H G F E D C B S H G F E D C A B C C B A A B A LRU Policy MRU LRU Prior work: Predict reuse behavior of missed blocks. Insert low-reuse blocks at LRU position. The first problem, referred to as cache pollution, is one where blocks with low-reuse evict blocks with high-reuse from the cache. Consider the following example of a cache following the LRU policy. Although the cache is filled with high–reuse blocks, the LRU policy inserts even blocks with low-reuse at the MRU position, evicting more useful blocks from the cache. So the future accesses to blocks A, B and C will miss in the cache. To address this problem, prior work proposed the idea of predicting the reuse behavior of missed cache blocks and inserting low-reuse blocks at the LRU position. This mitigates the impact of pollution as shown in the example. H G F E D C B A U T S T S A S A A MRU LRU
163
Cache Thrashing Cache Problem: High-reuse blocks evict each other
LRU Policy A B C D E F G H I J K K J I H G F E D I H G F E D C H G F E D C B J I H G F E D C A B C B A A B A MRU Cache LRU Prior work: Insert at MRU position with a very low probability (Bimodal insertion policy) The second problem, referred to as thrashing, occurs when the number of high-reuse blocks is more than what the cache can handle, as shown in the example. In this case, the LRU policy leads to these high-reuse blocks evicting each other from the cache, leading to zero cache hits. Prior work proposed to achieve this using the bimodal insertion policy, which inserts blocks at the MRU position with a very low probability. As a result, majority of the blocks are inserted at the LRU position. For a thrashing working set, this results in a fraction of the working set to be retained in the cache, leading to cache hits for at least that fraction. A fraction of working set stays in cache H G F E D C B A I K J A J I A I A MRU LRU
164
Shortcomings of Prior Works
Prior works do not address both pollution and thrashing concurrently Prior Work on Cache Pollution No control on the number of blocks inserted with high priority into the cache Prior Work on Cache Thrashing No mechanism to distinguish high-reuse blocks from low-reuse blocks The motivation behind this work is that prior works do not address both pollution and thrashing concurrently. Prior works on pollution do not have control over the number of high-reuse blocks. As a result, if there are more high-reuse blocks than what the cache can handle, these approaches can suffer from thrashing. On the other hand, prior works on cache thrashing have no mechanism to distinguish high-reuse blocks from low-reuse blocks. As a result, when a working set is not thrashing, these approaches can suffer from pollution. Our goal in this work is to design a mechanism to address both cache pollution and thrashing. In this talk, I will present our mechanism, the Evicted-address filter, that achieves our goal. Our goal: Design a mechanism to address both pollution and thrashing concurrently
165
Outline Background and Motivation Evicted-Address Filter Final Design
Reuse Prediction Thrash Resistance Final Design Our mechanism has two components: a reuse prediction component and a thrash resistance component. I will describe both these components followed by the advantages and disadvantages of our proposed approach. Then, I will present our evaluation results and conclude. Advantages and Disadvantages Evaluation Conclusion
166
Reuse Prediction High reuse Miss Missed-block ? Low reuse
Keep track of the reuse behavior of every cache block in the system The reuse prediction problem asks the following question. On a cache miss, does the missed cache block have high reuse or low reuse? One possible way to answer this question is to keep track of the reuse behavior of every block in the system. But such an approach is impractical due to its high storage overhead and look-up latency. So, how do prior works address this problem? Impractical High storage overhead Look-up latency
167
Prior Work on Reuse Prediction
Use program counter or memory region information. 2. Learn group behavior 1. Group Blocks 3. Predict reuse B A T S PC 1 PC 2 B A T S PC 1 PC 2 PC 1 PC 2 C U Previous approaches proposed to predict the reuse behavior of missed blocks indirectly using program-counter or memory-region information. At a high level, the program-counter based mechanism operates in three steps. First, the mechanism groups blocks based on the program counter that caused their cache miss. Second, the mechanism learns the reuse behavior of each group based on the blocks that were previously accessed by the program counter. Third, the learned behavior of each group is used to predict the reuse behavior of future blocks accessed by the corresponding program counter. Such an approach has two shortcomings. First, blocks belonging to the same program counter may not have the same reuse behavior. Second, the mechanism has no control over the number of blocks predicted to have high reuse. As a result, this approach can potentially suffer from thrashing. Same group → same reuse behavior No control over number of high-reuse blocks
168
Our Approach: Per-block Prediction
Use recency of eviction to predict reuse A A Time Accessed soon after eviction Time of eviction Accessed long time after eviction In this work, we propose a mechanism to predict the reuse behavior of a block based on its own past behavior. The key idea behind our mechanism is to use the recency of eviction of a block to predict its reuse on its next access. More specifically, if a block is accessed soon after getting evicted, our mechanism concludes that the block was prematurely evicted and predicts it to have high reuse. On the other hand, if a block is accessed a long time after eviction, our mechanism concludes that the block is unlikely to be accessed in the near future and predicts it to have low reuse. The above idea suggests that it is sufficient to keep track of a small number of recently evicted blocks to distinguish between high-reuse blocks and low-reuse blocks. Time S S
169
Evicted-Address Filter (EAF)
Evicted-block address EAF (Addresses of recently evicted blocks) Cache MRU LRU Yes No In EAF? Based on this observation, our mechanism augments the cache with a structure called the Evicted-address filter that keeps track of addresses of recently evicted blocks. When a block is evicted from the cache, our mechanism inserts its address into the EAF. On a cache miss, if the missed block address is present in the EAF, then the block was evicted recently. Therefore, our mechanism predicts that the block has high reuse and inserts it at the MRU position. It also removes the block address from the EAF to create space for more evicted addresses. On the other hand, if the missed block address is not present in the EAF, there is one of two possibilities: either the block was accessed before and evicted a long time ago or the block is accessed for the first time. In both cases, our mechanism predicts that the block has low reuse and inserts it at the LRU position. Although the EAF is a simple mechanism to predict the reuse behavior of missed blocks, one natural question is how to implement it in hardware? High Reuse Low Reuse Miss Missed-block address
170
Naïve Implementation: Full Address Tags
Recently evicted address EAF ? Need not be 100% accurate 1. Large storage overhead A naïve implementation of the EAF would be to implement it as a tag store where each tag entry corresponds to the address or a recently evicted block. However, such an implementation suffers from two problems: 1) it has a large storage overhead and 2) it requires associative lookups which consume high energy. But notice that the EAF need not be 100% accurate as it is just a prediction structure. This raises the possibility of implementing EAF using a more compact structure which doesn’t have the two shortcomings. So, we consider implementing the EAF using a Bloom filter. 2. Associative lookups – High energy
171
Low-Cost Implementation: Bloom Filter
EAF ? Need not be 100% accurate A naïve implementation of the EAF would be to implement it as a tag store where each tag entry corresponds to the address or a recently evicted block. However, such an implementation suffers from two problems: 1) it has a large storage overhead and 2) it requires associative lookups which consume high energy. But notice that the EAF need not be 100% accurate as it is just a prediction structure. This raises the possibility of implementing EAF using a more compact structure which doesn’t have the two shortcomings. So, we consider implementing the EAF using a Bloom filter. Implement EAF using a Bloom Filter Low storage overhead + energy
172
Bloom Filter Clear Compact representation of a set Remove Insert
May remove multiple addresses Remove Clear Insert Test False positive 1. Bit vector Y X Z W 2. Set of hash functions H1 H2 1 1 1 1 Let me give you a quick overview of a Bloom filter. A Bloom filter is a compact representation of a set, in this case, a set of addresses. It consists of a bit vector and a set of hash functions. All the bits in the bit-vector are initialized to zero. To insert an address X into the set, the Bloom filter computes the values of the two hash functions and sets the corresponding elements in the filter. To insert another address Y, the Bloom filter repeats the process. To test if an address is present in the filter, the Bloom filter computes the values of the hash functions and checks if all the corresponding bits are set. If yes, the Bloom filter concludes that the address is present in the set. This is the case for the address X. However, even if one of the bits is not set, the Bloom filter concludes that the address is not present in the set. When we test for the address W, the Bloom filter will conclude that W is present in the set. But W was never inserted. The left bit was set due to the insertion of X and the right bit was set due to the insertion of Y. This situation is referred to as a false positive. The false positive rate of a Bloom filter can be made low by controlling the parameters of the Bloom filter. Since multiple addresses can map to the same bits, a Bloom filter does not support removing individual addresses from the set. However, all the addresses can be cleared from the set by simply resetting all the bits in the Bloom filter. Now, let us look at how we can implement EAF using a Bloom filter. X Y H1 H2 Inserted Elements: X Y
173
EAF using a Bloom Filter
Clear 2 when full Insert Bloom Filter Remove Evicted-block address FIFO address when full Test Missed-block address Let us quickly revisit the operations performed on the EAF. First, on a cache eviction, the evicted block address is inserted into the EAF. Second, on a cahce miss, our mechanism tests if the missed block address is present in the EAF. If yes, the address is also removed from the EAF. Finally, when the EAF is full, an address is removed in a FIFO manner to create space for more recently evicted addresses. A Bloom filter based implementation of EAF will support the insert and the test operations. However, as we saw in the previous slide, the Bloom filter does not support the remove operations. So we need to somehow eliminate these remove operations. For this purpose, we propose two changes to the EAF design. First, on a cache miss, if the missed block address is present in the EAF, we choose to retain the block address in the EAF instead of removing it. Second, when the EAF becomes full, we propose to clear the EAF completely instead of removing an address in a FIFO manner. With these changes, we can implement the EAF using a Bloom filter. Doing so can reduce the storage overhead of EAF by 4x, to around 1.47% compared to the cache size. Remove 1 If present Bloom-filter EAF: 4x reduction in storage overhead, 1.47% compared to cache size
174
Outline Background and Motivation Evicted-Address Filter Final Design
Reuse Prediction Thrash Resistance Final Design Our mechanism has two components: a reuse prediction component and a thrash resistance component. I will describe both these components followed by the advantages and disadvantages of our proposed approach. Then, I will present our evaluation results and conclude. Advantages and Disadvantages Evaluation Conclusion
175
Large Working Set: 2 Cases
1 Cache < Working set < Cache + EAF Cache EAF K J I H G F L C B D E A 2 Thrashing happens when the working set is larger than the cache size. In the context of EAF, there are two cases. In the first case, the working set is larger than the cache but smaller than the blocks tracked by the cache and EAF together. In the second case, the working set is larger than the cache and EAF together. In both cases, the traditional LRU policy will lead to thrashing. I will discuss the operation of EAF in these two cases one by one. Cache + EAF < Working Set Cache EAF S R Q P O N M L K J I H G F E D C B A
176
Large Working Set: Case 1
Cache < Working set < Cache + EAF Cache EAF A L K J I H B E D F L K J I H G A D C E K J I H G F L C B D A L K J I H G B E D F C F E G B A C Sequence: A A B B C C D E F G H I J K L A B C D In the first case, the working set is smaller than the cache and EAF put together. Let us first look at how the original FIFO based implementation of EAF works. Consider the following access sequence that accesses the blocks of the working set in a cyclic manner. First, the access to block A misses in the cache. However, since the address is present in the EAF, it is inserted with a high priority into the cache. The same thing happens with block B and Block C after than. In fact, every block in the access sequence will miss in the cache. As a result, the FIFO based implementation of EAF performs no better than traditional LRU. EAF Naive:
177
Large Working Set: Case 1
Cache < Working set < Cache + EAF Cache EAF A L K J I H G B E D F C A L K J I B C D A L K J I H G B E D C A K J I H G F L C B D E F H H G B E D F C A G F E I B A Not removed Not present in the EAF Sequence: A A B B C D D E F G H I J K L A B C D Now lets look at how the Bloom-filter based EAF performs on this access sequence. When block A is accessed, it misses in the cache but is present in the EAF. It is inserted with a high priority. But unlike EAF-FIFO, the address is not removed from the EAF. The same thing happens with Block B. Moving forward, after the access to block D which also misses in the cache, the EAF becomes full. At this point, the Bloom-filter based implementation will completely clear the EAF. As a result, even though the next four accesses to E, F, G and H miss in the cache, their addresses will not be present in the EAF. Therefore, they will be inserted at the LRU position evicting only block I from the cache. As a result, 7 of the next 8 accesses will hit in the cache. In fact, if the access sequence continues, the bloom-filter based implementation will periodically clear the EAF leading to cache hits to a fraction of the blocks. So, the Bloom-filter based implementation of EAF mitigates caceh thrashing. EAF Naive: EAF BF: Bloom-filter based EAF mitigates thrashing
178
Large Working Set: Case 2
Cache + EAF < Working Set Cache EAF S R Q P O N M L K J I H G F E D C B A Problem: All blocks are predicted to have low reuse Now lets move on to the second case of large working sets. In this case, since the working set is larger than both the cache and EAF together, none of the missed addresses will be present in the EAF. As a result, all blocks will be predicted to have low reuse and inserted with low priority. If the cache is already filled with some other blocks, none of the blocks will get into the cache. In this case, we would ideally like to allow a fraction of the working set to stay in the cache. For this purpose, we propose to use the bimodal insertion policy for low reuse blocks. As a result, a few blocks of the working set will be inserted at the MRU position improving the cache utilization. Allow a fraction of the working set to stay in the cache Use Bimodal Insertion Policy for low reuse blocks. Insert few of them at the MRU position
179
Outline Background and Motivation Evicted-Address Filter Final Design
Reuse Prediction Thrash Resistance Final Design Our mechanism has two components: a reuse prediction component and a thrash resistance component. I will describe both these components followed by the advantages and disadvantages of our proposed approach. Then, I will present our evaluation results and conclude. Advantages and Disadvantages Evaluation Conclusion
180
EAF-Cache: Final Design
1 Cache eviction Insert address into filter Increment counter Bloom Filter Cache Counter Lets take a look at the final design of our mechanism, the EAF-cache. It augments the cache with a Bloom filter and a counter that keeps track of the number of addresses inserted into the Bloom filter. On a cache eviction, the evicted address is inserted into the filter and the counter is incremented. On a cache miss, if the missed block address is present in the Bloom filter, the block is inserted at the MRU position. Otherwise it is inserted with the bimodal insertion policy. Finally, when the counter reaches a maximum, both the filter and the counter are cleared. 3 Counter reaches max Clear filter and counter 2 Cache miss Test if address is present in filter Yes, insert at MRU. No, insert with BIP
181
Outline Background and Motivation Evicted-Address Filter Final Design
Reuse Prediction Thrash Resistance Final Design Our mechanism has two components: a reuse prediction component and a thrash resistance component. I will describe both these components followed by the advantages and disadvantages of our proposed approach. Then, I will present our evaluation results and conclude. Advantages and Disadvantages Evaluation Conclusion
182
EAF: Advantages Cache Cache eviction Bloom Filter Cache miss
Counter Cache miss Apart from its ability to mitigate both pollution and thrashing, EAF has three other advantages. First, it adds only a Bloom filter and a counter. Hardware implementations of the Bloom filter are well studied. So, EAF-cache is simple to implement. Second, both the Bloom filter and the counter are outside the cache. As a result, our mechanism is easy to design and verify on top of existing cache implementations. Finally, all operations on the EAF happen on a cache miss. As a result, EAF can work well with other techniques that monitor cache hits to improve performance, for example, the cache replacement policy. 1. Simple to implement 2. Easy to design and verify 3. Works with other techniques (replacement policy)
183
EAF: Disadvantage Cache Second access First access A A In EAF? Miss A
One limitation of the EAF is that when a high-reuse block is accessed for the first time, EAF will falsely predict the block to have low reuse and insert it at the LRU position. So the block will likely get evicted causing the second access to also be a cache miss. Although this does not affect performance significantly for most applications, for LRU friendly applications, EAF incurs one additional miss for most blocks. To mitigate this problem, we propose to use a previously proposed technique called set dueling to choose the best between the EAF and the LRU policies. Please read our paper for more details. Problem: For an LRU-friendly application, EAF incurs one additional miss for most blocks Dueling-EAF: set dueling between EAF and LRU
184
Outline Background and Motivation Evicted-Address Filter Final Design
Reuse Prediction Thrash Resistance Final Design Our mechanism has two components: a reuse prediction component and a thrash resistance component. I will describe both these components followed by the advantages and disadvantages of our proposed approach. Then, I will present our evaluation results and conclude. Advantages and Disadvantages Evaluation Conclusion
185
Methodology Simulated System Benchmarks Multi-programmed workloads
In-order cores, single issue, 4 GHz 32 KB L1 cache, 256 KB L2 cache (private) Shared L3 cache (1MB to 16MB) Memory: 150 cycle row hit, 400 cycle row conflict Benchmarks SPEC 2000, SPEC 2006, TPC-C, 3 TPC-H, Apache Multi-programmed workloads Varying memory intensity and cache sensitivity Metrics 4 different metrics for performance and fairness Present weighted speedup
186
Comparison with Prior Works
Addressing Cache Pollution Run-time Bypassing (RTB) – Johnson+ ISCA’97 - Memory region based reuse prediction Single-usage Block Prediction (SU) – Piquet+ ACSAC’07 Signature-based Hit Prediction (SHIP) – Wu+ MICRO’11 - Program counter based reuse prediction We compare EAF to five previous approaches. Three of them address the cache pollution problem. Run time cache bypassing learns the reuse behavior of course grain memory regions to predict the reuse of individual cache blocks. Single usage block prediction and signature based hit prediction both use a program counter based reuse prediction mechanism, similar to the memory region approach. The miss classification table keeps track of one most recently evicted block to filter low-reuse blocks. The main drawback of these approaches is that they do not have inherent mechanism to control the number of high reuse blocks. As a result, when the working set is larger than the cache size, they will likely lead to thrashing. The two other mechanisms we compare to address cache thrashing. They both use set dueling to identify applications with thrashing working sets and use the bimodal insertion policy for such applications. TA-DIP uses the traditional LRU replacement policy as the base policy and TA-DRRIP uses a different replacement policy called RRIP. Miss Classification Table (MCT) – Collins+ MICRO’99 - One most recently evicted block - No control on number of blocks inserted with high priority ⟹ Thrashing
187
Comparison with Prior Works
Addressing Cache Thrashing TA-DIP – Qureshi+ ISCA’07, Jaleel+ PACT’08 TA-DRRIP – Jaleel+ ISCA’10 - Use set dueling to determine thrashing applications - No mechanism to filter low-reuse blocks ⟹ Pollution We compare EAF to five previous approaches. Three of them address the cache pollution problem. Run time cache bypassing learns the reuse behavior of course grain memory regions to predict the reuse of individual cache blocks. Single usage block prediction and signature based hit prediction both use a program counter based reuse prediction mechanism, similar to the memory region approach. The miss classification table keeps track of one most recently evicted block to filter low-reuse blocks. The main drawback of these approaches is that they do not have inherent mechanism to control the number of high reuse blocks. As a result, when the working set is larger than the cache size, they will likely lead to thrashing. The two other mechanisms we compare to address cache thrashing. They both use set dueling to identify applications with thrashing working sets and use the bimodal insertion policy for such applications. TA-DIP uses the traditional LRU replacement policy as the base policy and TA-DRRIP uses a different replacement policy called RRIP.
188
Results – Summary This slide presents the summary of our performance results for systems with different number of cores. As shown, our mechanisms outperform all prior approaches for all the three systems. Also, the multicore results are significantly better than the single core results. This is because, in a multicore system, pollution or thrashing caused by an application will affect useful blocks of other concurrently running applications. SAY THAT LAST TWO BARS ARE EAF AND D-EAF
189
4-Core: Performance This figure compares the performance of EAF with the SHIP (BEST PREVIOUS MECHANISM) for all 4-core workloads. Each point on the x-axis corresponds to a 4-core workload and the workloads are sorted based on the performance improvements due to EAF. I would like to draw two conclusions. First, the average improvements of EAF is not due to few workloads. Rather, EAF outperforms SHIP for most workloads. Second, EAF degrades performance for a few LRU-friendly workloads. However, Dueling-EAF mitigates this degradation while not significantly affecting the performance for other workloads.
190
Effect of Cache Size This figure shows the effect of varying the cache size on the performance of different schemes. As expected, the gap between different schemes decrease with increasing cache size. With larger cache sizes, the negative impact of pollution and thrashing also reduces. However, our EAF-based approaches still provide better performance compared to both the LRU baseline and SHIP.
191
Effect of EAF Size Finally, let’s take a look at the effect of the number of addresses kept track in the EAF on its performance. The x-axis shows the ratio of the number of addresses in the EAF and the number of blocks in the cache. When the number of addresses in the EAF is low, it falsely predicts many high reuse blocks as low reuse blocks. On the other extreme, when the number of addresses in the EAF is high, it predicts too many blocks to have high reuse, more than what the cache can handle. We find that having as many addresses in the EAF as there are blocks in the cache provides the best performance. Our paper describes the intuition behind this behavior.
192
Other Results in Paper EAF orthogonal to replacement policies
LRU, RRIP – Jaleel+ ISCA’10 Performance improvement of EAF increases with increasing memory latency EAF performs well on four different metrics Performance and fairness Alternative EAF-based designs perform comparably Segmented EAF Decoupled-clear EAF …
193
Conclusion Cache utilization is critical for system performance
Pollution and thrashing degrade cache performance Prior works don’t address both problems concurrently EAF-Cache Keep track of recently evicted block addresses in EAF Insert low reuse with low priority to mitigate pollution Clear EAF periodically and use BIP to mitigate thrashing Low complexity implementation using Bloom filter EAF-Cache outperforms five prior approaches that address pollution or thrashing …
194
Base-Delta-Immediate Cache Compression
Gennady Pekhimenko, Vivek Seshadri, Onur Mutlu, Philip B. Gibbons, Michael A. Kozuch, and Todd C. Mowry, "Base-Delta-Immediate Compression: Practical Data Compression for On-Chip Caches" Proceedings of the 21st ACM International Conference on Parallel Architectures and Compilation Techniques (PACT), Minneapolis, MN, September Slides (pptx)
195
Executive Summary Off-chip memory latency is high
Large caches can help, but at significant cost Compressing data in cache enables larger cache at low cost Problem: Decompression is on the execution critical path Goal: Design a new compression scheme that has 1. low decompression latency, 2. low cost, 3. high compression ratio Observation: Many cache lines have low dynamic range data Key Idea: Encode cachelines as a base + multiple differences Solution: Base-Delta-Immediate compression with low decompression latency and high compression ratio Outperforms three state-of-the-art compression mechanisms
196
Motivation for Cache Compression
Significant redundancy in data: 0x 0x B 0x 0x … How can we exploit this redundancy? Cache compression helps Provides effect of a larger cache without making it physically larger
197
Background on Cache Compression
Hit L2 Cache CPU L1 Cache Decompression Uncompressed Uncompressed Compressed Key requirements: Fast (low decompression latency) Simple (avoid complex hardware changes) Effective (good compression ratio)
198
Shortcomings of Prior Work
Compression Mechanisms Decompression Latency Complexity Ratio Zero
199
Shortcomings of Prior Work
Compression Mechanisms Decompression Latency Complexity Ratio Zero Frequent Value
200
Shortcomings of Prior Work
Compression Mechanisms Decompression Latency Complexity Ratio Zero Frequent Value Frequent Pattern /
201
Shortcomings of Prior Work
Compression Mechanisms Decompression Latency Complexity Ratio Zero Frequent Value Frequent Pattern / Our proposal: BΔI
202
Outline Motivation & Background Key Idea & Our Mechanism Evaluation
Conclusion
203
Key Data Patterns in Real Applications
Zero Values: initialization, sparse matrices, NULL pointers 0x 0x 0x 0x … Repeated Values: common initial values, adjacent pixels 0x000000FF 0x000000FF 0x000000FF 0x000000FF … Narrow Values: small values stored in a big data type 0x 0x B 0x 0x … Other Patterns: pointers to the same memory region 0xC04039C0 0xC04039C8 0xC04039D0 0xC04039D8 …
204
How Common Are These Patterns?
SPEC2006, databases, web workloads, 2MB L2 cache “Other Patterns” include Narrow Values 43% of the cache lines belong to key patterns
205
Key Data Patterns in Real Applications
Zero Values: initialization, sparse matrices, NULL pointers Low Dynamic Range: Differences between values are significantly smaller than the values themselves 0x 0x 0x 0x … Repeated Values: common initial values, adjacent pixels 0x000000FF 0x000000FF 0x000000FF 0x000000FF … Narrow Values: small values stored in a big data type 0x 0x B 0x 0x … Other Patterns: pointers to the same memory region 0xC04039C0 0xC04039C8 0xC04039D0 0xC04039D8 …
206
Key Idea: Base+Delta (B+Δ) Encoding
4 bytes 32-byte Uncompressed Cache Line 0xC04039C0 0xC04039C8 0xC04039D0 … 0xC04039F8 0xC04039C0 Base 12-byte Compressed Cache Line 0x00 0x08 0x10 … 0x38 1 byte 1 byte 1 byte Fast Decompression: vector addition Simple Hardware: arithmetic and comparison 20 bytes saved Effective: good compression ratio
207
Can We Do Better? Uncompressible cache line (with a single base):
Key idea: Use more bases, e.g., two instead of one Pro: More cache lines can be compressed Cons: Unclear how to find these bases efficiently Higher overhead (due to additional bases) 0x 0x09A40178 0x B 0x09A4A838 …
208
B+Δ with Multiple Arbitrary Bases
2 bases – the best option based on evaluations
209
How to Find Two Bases Efficiently?
First base - first element in the cache line Second base - implicit base of 0 Advantages over 2 arbitrary bases: Better compression ratio Simpler compression logic Base+Delta part Immediate part Base-Delta-Immediate (BΔI) Compression
210
B+Δ (with two arbitrary bases) vs. BΔI
Average compression ratio is close, but BΔI is simpler
211
BΔI Implementation Decompressor Design Compressor Design
Low latency Compressor Design Low cost and complexity BΔI Cache Organization Modest complexity
212
BΔI Decompressor Design
Compressed Cache Line B0 B0 Δ0 Δ0 Δ1 Δ1 Δ2 Δ2 Δ3 Δ3 B0 B0 B0 B0 Vector addition + + + + V1 V2 V3 V0 V0 V1 V2 V3 Uncompressed Cache Line
213
Compression Flag & Compressed Cache Line
BΔI Compressor Design 32-byte Uncompressed Cache Line 8-byte B0 1-byte Δ CU 8-byte B0 2-byte Δ CU 8-byte B0 4-byte Δ CU 4-byte B0 1-byte Δ CU 4-byte B0 2-byte Δ CU 2-byte B0 1-byte Δ CU Zero CU Rep. Values CU CFlag & CCL CFlag & CCL CFlag & CCL CFlag & CCL CFlag & CCL CFlag & CCL CFlag & CCL CFlag & CCL CFlag & CCL Compression Selection Logic (based on compr. size) Compression Flag & Compressed Cache Line Compressed Cache Line
214
BΔI Compression Unit: 8-byte B0 1-byte Δ
32-byte Uncompressed Cache Line 8 bytes V0 V0 V0 V1 V1 V2 V2 V3 V3 B0= V0 B0 B0 B0 B0 - - - - Δ0 Δ1 Δ2 Δ3 Within 1-byte range? Within 1-byte range? Within 1-byte range? Within 1-byte range? Is every element within 1-byte range? Yes No B0 B0 Δ0 Δ0 Δ1 Δ1 Δ2 Δ2 Δ3 Δ3
215
BΔI Cache Organization
Tag Storage: Data Storage: 32 bytes Conventional 2-way cache with 32-byte cache lines Set0 … … Set0 … … Set1 Tag0 Tag1 Set1 Data0 Data1 … … … … Way0 Way1 Way0 Way1 BΔI: 4-way cache with 8-byte segmented data 8 bytes Tag Storage: Set0 … … … … Set0 … … … … … … … … Set1 Tag0 Tag1 Tag2 Tag3 Set1 S0 S0 S1 S2 S3 S4 S5 S6 S7 C C - Compr. encoding bits … … … … … … … … … … … … Way0 Way1 Way2 Way3 Twice as many tags Tags map to multiple adjacent segments 2.3% overhead for 2 MB cache
216
Qualitative Comparison with Prior Work
Zero-based designs ZCA [Dusser+, ICS’09]: zero-content augmented cache ZVC [Islam+, PACT’09]: zero-value cancelling Limited applicability (only zero values) FVC [Yang+, MICRO’00]: frequent value compression High decompression latency and complexity Pattern-based compression designs FPC [Alameldeen+, ISCA’04]: frequent pattern compression High decompression latency (5 cycles) and complexity C-pack [Chen+, T-VLSI Systems’10]: practical implementation of FPC-like algorithm High decompression latency (8 cycles)
217
Outline Motivation & Background Key Idea & Our Mechanism Evaluation
Conclusion
218
Methodology Simulator Workloads System Parameters
x86 event-driven simulator based on Simics [Magnusson+, Computer’02] Workloads SPEC2006 benchmarks, TPC, Apache web server 1 – 4 core simulations for 1 billion representative instructions System Parameters L1/L2/L3 cache latencies from CACTI [Thoziyoor+, ISCA’08] 4GHz, x86 in-order core, 512kB - 16MB L2, simple memory model (300-cycle latency for row-misses)
219
Compression Ratio: BΔI vs. Prior Work
SPEC2006, databases, web workloads, 2MB L2 1.53 BΔI achieves the highest compression ratio
220
Single-Core: IPC and MPKI
3.6% 16% 5.6% 4.9% 24% 5.1% 21% 5.2% 13% 8.1% 19% 14% BΔI achieves the performance of a 2X-size cache Performance improves due to the decrease in MPKI
221
Multi-Core Workloads Application classification based on
Compressibility: effective cache size increase (Low Compr. (LC) < 1.40, High Compr. (HC) >= 1.40) Sensitivity: performance gain with more cache (Low Sens. (LS) < 1.10, High Sens. (HS) >= 1.10; 512kB -> 2MB) Three classes of applications: LCLS, HCLS, HCHS, no LCHS applications For 2-core - random mixes of each possible class pairs (20 each, 120 total workloads)
222
Multi-Core: Weighted Speedup
If at least one application is sensitive, then the performance improves BΔI performance improvement is the highest (9.5%)
223
Other Results in Paper IPC comparison against upper bounds
BΔI almost achieves performance of the 2X-size cache Sensitivity study of having more than 2X tags Up to 1.98 average compression ratio Effect on bandwidth consumption 2.31X decrease on average Detailed quantitative comparison with prior work Cost analysis of the proposed changes 2.3% L2 cache area increase
224
Conclusion A new Base-Delta-Immediate compression mechanism
Key insight: many cache lines can be efficiently represented using base + delta encoding Key properties: Low latency decompression Simple hardware implementation High compression ratio with high coverage Improves cache hit ratio and performance of both single-core and multi-core workloads Outperforms state-of-the-art cache compression techniques: FVC and FPC
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.