Conflict Misses in Direct Mapping
What you'll learn: You'll understand why direct-mapped caches experience conflict misses when multiple memory blocks compete for the same cache location.
The Core Problem
In a direct-mapped cache, each memory block maps to exactly one cache location based on its address. The problem? Multiple memory blocks often map to the same cache line. When your program alternates between accessing two blocks that map to the same location, you create a conflict miss — even if the rest of the cache is empty.
How Conflict Misses Happen
Imagine a parking garage where your parking spot is determined by your license plate number. Cars ending in "5" must use spot 5, cars ending in "7" use spot 7, and so on.
Now suppose you own two cars: one with plate ABC-5 and another with plate XYZ-5. Both must park in spot 5. Every time you swap cars, you have to move the other one out — even though spots 1, 2, 3, 4, 6, 7, 8, and 9 sit empty!
In a direct-mapped cache:
- Memory address determines the single cache line where data can go
- Blocks with the same index bits map to the same line
- Accessing alternating blocks that map to the same location causes repeated evictions
- Each eviction is a conflict miss
Real Impact
Consider accessing memory addresses 0, 8, 0, 8, 0, 8... in a small direct-mapped cache. If both addresses map to the same line, you'll miss every single time despite having a cache, because they keep kicking each other out.
Key Takeaway: Conflict misses occur in direct-mapped caches when multiple frequently-accessed memory blocks map to the same cache line, causing thrashing even when the cache has unused space elsewhere.