Professional Documents
Culture Documents
4.chap6 Lookahead Vs Look Through Cache
4.chap6 Lookahead Vs Look Through Cache
4.chap6 Lookahead Vs Look Through Cache
Amit Levy
1
Figure 1: CPU Connected Directly to Memory
2
How long to run this code?
Characteristics
• CPU Instructions: 0.5ns (2GHz)
int arr[1000];
for (i = 0; i < arr.len(); i++) { ++arr[i]; }
3
How long to run this code?
4
Why not just make everything fast?
• Physical limitations
5
A Solution: Caching
What is caching?
• Examples:
• Database cache
• Memoization
7
Locality
8
When is caching effective?
1 2 3 4 5 6 7 8
9
Caching Terminology
• Hit rate and Miss rate: proportion of hits and misses, respectively
• Hit time and Miss time: time to access item in cache and not in cache, respectively
10
Effective access time
11
Characterizing a Caching System
• Allocation policy
• Eviction Policy
12
Who handles misses?
14
Look-through
• But when?
16
Write-through
• Advantages:
• Eviction is cheap
• Easy to implement
• Disadvantages:
17
Write-back
Update only in the cache. Write “back” to the backing store only when evicting item from cache
• Advantages:
• Disadvantages:
18
Write-allocate vs. Write-no-allocate
When writing to items not currently in the cache, do we bring them into the cache?
Yes == Write-Allocate
• Advantage: Exploits temporal locality: written data likely to be access again soon
No == Write-No-Allocate
• Advantage: Avoids spurious evictions if data not accessed soon
19
Eviction policies
Which items to we evict from the cache when we run out of space?
• …
• Workload
• Performance
20
Challenges in Caching
21
Remainder of this Section
22
References
23