Cache misses are traditionally classified into three types—compulsory, capacity, and conflict misses—and a conflict miss (sometimes called a collision miss) happens when multiple active blocks compete for the same cache location (set), even though the cache still has free space elsewhere. Here are the typical scenarios in which conflict misses show up:
Direct-mapped caches
• Every address maps to exactly one cache line (set).
• If you alternate accesses between two (or more) addresses that happen to share the same line index, each access evicts the previous one.
• Example:
code
// Assume a direct-mapped cache with 8 lines, line size = 64B
int A[512], B[512];
for (i = 0; i < 512; i += 8) {
A[i] = …; // maps to line (i/64) mod 8
B[i] = …; // if B’s base offset differs from A’s by a multiple of 512, this maps to the same lines
}
Here A[i] and B[i] thrash the same cache line back and forth.
Set-associative caches (insufficient associativity)
• Each address maps to exactly one set, but each set holds N “ways.”
• If you access more than N distinct blocks that map to the same set before any of them get reused, one block has to be evicted → conflict miss.
• Example (2-way cache):
– Working set touches 3 different addresses, all with the same set index.
– After loading the first two, the third causes an eviction. If you then circle back to the first, it’s been evicted—conflict miss.
Strided or “power-of-two” access patterns
• When your stride (distance between successive accesses) is a multiple of the cache’s total size (or an integral multiple of the number of sets), you repeatedly hit the same set.
• Common in poorly-tuned matrix or array code that walks memory with a stride that aliases the cache.
• Example: iterating over a large array with stride = (cache_size), so every access maps to line 0.
Multiple data structures aliasing the same sets
• Two or more arrays/structures in your program happen to align so that their starting addresses differ by a multiple of (number_of_sets × line_size).
• Even with full associativity you avoid conflict misses—but once associativity is limited, these aliasing structures will collide.
Loop nests and tiling gone wrong
• In multi-dimensional loops, if the inner‐loop stride across rows or columns steps through memory in a way that repeatedly maps into a small subset of sets, you’ll thrash those sets.
• Blocking/tiling techniques can either alleviate or exacerbate this, depending on your tile size relative to the cache’s shape.
—
How to reduce conflict misses?
Increase associativity (go from direct-mapped to 2-way, 4-way, etc.)
Use cache-aware data layouts or padding to break modulo collisions (“cache coloring”)
Reorder loops or apply blocking so you reuse data in a way that spreads accesses across different sets
Hardware solutions like victim buffers or skewed associativity designs
In short, any time more distinct cache blocks map to the same set than the cache can hold simultaneously—and you access them close enough in time that none stay resident—you’ll incur conflict misses.