Sub topic 14
Multilevel Caches and Access Time
Prerequisites and the basic model
This chapter assumes that you can compute hit and miss ratios, understand cache blocks, and read powers of two. You should also know that a cache hit finds the requested data at that level, while a miss sends the request to a slower level.
Modern processors usually use multiple cache levels. L1 is the smallest and fastest cache. L2 is larger and slower. Main memory is much larger but has a higher access time.
A multilevel cache can reduce the average time of an L1 miss. Most L1 misses are often found in L2, so they do not need to wait for main memory.
Local and global miss ratios
The local miss ratio of a cache is the fraction of requests reaching that cache that miss there.
For example, if 100 requests reach L2 and 20 miss, the L2 local miss ratio is:
\[ m_{L2} = \frac{20}{100} = 0.20 \]
The global miss ratio is measured against all original CPU requests. If 1,000 CPU requests occur and 20 reach memory, the global memory miss ratio is 0.02.
For a two-level hierarchy:
\[ \text{Global memory miss ratio} = m{L1} \times m{L2} \]
This multiplication works because a request must first miss in L1 and then miss in L2 before reaching memory.
| Symbol | Meaning |
|---|---|
| \(T_{L1}\) | Time to check L1 |
| \(m_{L1}\) | L1 local miss ratio |
| \(T_{L2}\) | Additional time to check L2 |
| \(m_{L2}\) | L2 local miss ratio |
| \(T_M\) | Main-memory access time |
Calculating AMAT
The average memory access time, or AMAT, is the average time per CPU memory request. For two cache levels:
\[ \text{AMAT} = T{L1} + m{L1}(T{L2}+m{L2}T_M) \]
The first term is paid for every request. The expression inside the parentheses is paid only when L1 misses. The memory time is paid only when both L1 and L2 miss.
def amat_two_level(t_l1, m_l1, t_l2, m_l2, t_mem):
# Miss ratios are local to their respective cache levels.
return t_l1 + m_l1 * (t_l2 + m_l2 * t_mem)
result = amat_two_level(1, 0.10, 10, 0.20, 100)
print(result) # 4.0 time unitsFor these values:
\[ 1 + 0.10(10 + 0.20 \times 100) = 1 + 0.10(30) = 4 \]
The expected access time is 4 time units, not 1 plus the full L2 and memory times. Those extra times occur only on the appropriate misses.
Common GATE patterns and errors
Read the wording carefully before choosing a formula.
- If the question gives an L2 local miss ratio, use \(m{L1}m{L2}\) for the probability of reaching memory.
- If it gives an L2 global miss ratio, do not multiply it by \(m_{L1}\) again.
- Check whether \(T{L2}\) includes the time already spent checking L1. If it is a total replacement time, avoid counting \(T{L1}\) twice.
- A serial hierarchy usually checks L1 first and then L2. Parallel cache lookup uses a different timing model.
- A lower miss ratio does not automatically mean a faster cache. A larger cache can have a longer lookup time.
Exercise
An L1 cache takes 2 ns and has a 5% miss ratio. An L2 cache takes an additional 8 ns and has a local miss ratio of 25%. Main memory takes 80 ns. What is the AMAT?
Show answer
AMAT = 2 + 0.05(8 + 0.25 × 80) = 2 + 0.05(28) = 3.4 ns.