I need to analyze when cache eviction rates exceed 10% for the L1 cache using birthday problem heuristics.
Given information:
- L1 cache: 64 sets, 12-way associative
- Total cache size: 49,152 bytes = 768 cache lines
- Each set can hold 12 lines
For the birthday problem approach, I need to find when the probability of collision (needing to evict) exceeds 10%.
In each set, once I have more than 12 cache lines mapping to that set, eviction occurs. With random address placement, each cache line maps to one of 64 sets uniformly at random.
Using the balls-and-bins model:
- n = number of cache lines inserted
- k = 64 sets
- Each set has capacity 12
The expected number of sets that exceed capacity 12 when n balls are thrown into 64 bins follows the birthday problem.
For a more precise calculation, I'll use the approximation that eviction occurs when any set has more than 12 items.
The probability that a specific set has exactly j items when n items are distributed among k sets is:
P(X = j) = C(n,j) × (1/k)^j × ((k-1)/k)^(n-j)
But for the birthday problem heuristic, I can use a simpler approach:
The expected number of items per set is n/64.
When n/64 > 12, we expect some evictions, but this is the average case.
For the 10% threshold, I need the probability that a randomly chosen cache access causes an eviction to exceed 10%.
Using the Poisson approximation where λ = n/64:
The probability that a set has more than 12 items is approximately:
P(X > 12) ≈ 1 - Σ(j=0 to 12) e^(-λ) λ^j / j!
Setting this equal to 0.10 and solving for λ, then for n:
For λ ≈ 2.5, P(X > 12) is very small.
For λ ≈ 15, P(X > 12) approaches 1.
Using more careful approximation or lookup tables for the Poisson distribution:
When λ ≈ 14.5, P(X > 12) ≈ 0.10
Therefore: n/64 ≈ 14.5
So n ≈ 928
However, this needs adjustment because we're looking at the overall eviction probability, not just overflow probability.
A better approach: when we have n lines and 64 sets with capacity 12 each, the total capacity is 768 lines. But due to random distribution, we hit evictions earlier.
Using the more precise birthday collision formula:
The expected number of collisions when placing n items into k bins each of capacity c is approximately:
For n items into 64 sets of capacity 12:
Eviction rate ≈ max(0, (n - 64×12)/n) when n > 768
But this is oversimplified.
Better approximation using load balancing:
When n items are randomly distributed into 64 bins, the maximum load is approximately:
max_load ≈ ln(64)/ln(ln(64)) + ln(n/64) when n is large
But for practical purposes and the 10% threshold:
Using the rule that for k bins and capacity c per bin, when we place approximately k×c×(1-√(ε)) items where ε is the desired empty fraction:
For 10% eviction rate, we want to fill about 90% efficiently:
n ≈ 64 × 12 × 0.9 ≈ 691
But using birthday problem more carefully:
n ≈ 64 × (12 - √(2×12×ln(1/0.9))) ≈ 64 × (12 - √(2.5)) ≈ 64 × 10.4 ≈ 666
However, the most accurate approach using standard birthday collision analysis gives:
Approximately 690-700 cache lines
Before the eviction rate exceeds 10% on average.
The answer is approximately 690 cache lines.