Sub topic 5
Average Memory Access Time
Prerequisites and the basic model
Assume you know binary numbers, powers of two, byte-addressable memory, and weighted averages. You should also know that a cache stores recently used copies of blocks from main memory.
Average memory access time (AMAT) is the average time needed to complete one memory access. It combines the fast accesses that hit in the cache with the slower accesses that miss.
For a single cache, use:
\[ \text{AMAT} = \text{hit time} + \text{miss rate} \times \text{miss penalty} \]
- Hit time is the time to check the cache and return data when the block is present.
- Miss rate is the fraction of accesses that miss.
- Miss penalty is the extra time required after a miss to obtain the block from the next memory level.
The miss rate is:
\[ \text{miss rate} = 1 - \text{hit ratio} \]
If the hit ratio is 95%, the miss rate is 5%, or 0.05.
Worked single-level example
Suppose a cache has a hit time of 2 ns, a hit ratio of 90%, and a miss penalty of 80 ns.
\[ \text{AMAT} = 2 + (1 - 0.90) \times 80 \]
\[ \text{AMAT} = 2 + 8 = 10\text{ ns} \]
The penalty is multiplied by the miss rate because only missed accesses pay it.
def amat(hit_time, hit_ratio, miss_penalty):
miss_rate = 1 - hit_ratio
return hit_time + miss_rate * miss_penalty
print(amat(2, 0.90, 80)) # 10.0Multilevel caches
With two cache levels, an L1 miss first checks L2. Only an L2 miss goes to main memory.
For local miss ratios:
\[ \text{AMAT} = T1 + m1(T2 + m2T_M) \]
Here:
- \(T_1\) is the L1 hit time.
- \(m_1\) is the L1 miss ratio.
- \(T_2\) is the L2 access time.
- \(m_2\) is the L2 local miss ratio.
- \(T_M\) is main-memory access time.
The L2 local miss ratio is measured among accesses that reach L2, not among all CPU accesses.
| Quantity | Meaning |
|---|---|
| L1 hit time | Time paid by every access |
| L1 miss ratio | Fraction that continues to L2 |
| L2 local miss ratio | Fraction reaching L2 that continues to memory |
| Memory time | Time paid after an L2 miss |
def amat_two_level(t_l1, m_l1, t_l2, m_l2, t_mem):
return t_l1 + m_l1 * (t_l2 + m_l2 * t_mem)
print(amat_two_level(1, 0.10, 10, 0.20, 100)) # 4.0 nsAvoiding common errors
Do not add the L2 time to every access. An access pays L2 time only when it misses in L1. Likewise, memory time is paid only when it misses in both levels.
Do not confuse a local miss ratio with a global miss ratio. If the global L2 miss ratio is already measured over all CPU accesses, use:
\[ \text{AMAT} = T1 + m1T2 + m{\text{global},2}T_M \]
Visualizing the timing path
Exercise
An L1 cache takes 1 ns, has a miss ratio of 0.2, and is followed by an L2 cache taking 5 ns with a local miss ratio of 0.1. Main memory takes 50 ns. What is the AMAT?
Show answer
AMAT = 1 + 0.2 × (5 + 0.1 × 50) = 1 + 2 = 3 ns.