Understanding the cache average memory access time calculator — concept and principle
Average memory access time (AMAT) is the expected time for the processor to get a piece of data, taking into account how often each level of the cache hierarchy hits or misses. This calculator handles a two-level cache (L1 and L2) in front of main memory. It is a standard tool in computer-architecture courses and a quick way to see whether improving hit time, miss rate or memory latency matters most.
How it is calculated
AMAT = L1 hit time + L1 miss rate × (L2 hit time + L2 local miss rate × memory latency).
- L1 hit time: time to read from L1, paid on every access.
- L1 miss rate: fraction of accesses not found in L1 (enter as a percentage).
- L2 hit time: extra time to look up L2 after an L1 miss.
- L2 local miss rate: fraction of the accesses that reach L2 and also miss there.
- Memory latency: extra time to fetch from main memory after an L2 miss.
All times are in nanoseconds; you can also use clock cycles if you are consistent.
The principle
Every access pays the L1 hit time. Only the accesses that miss pay the penalty of going further, and that penalty is itself an average: the L2 hit time plus, for the fraction that also misses in L2, the memory latency. Writing AMAT = hit time + miss rate × miss penalty and substituting the next level's AMAT for the miss penalty gives the recursive formula. The global L2 miss rate, the share of all accesses that go to memory, equals L1 miss rate × L2 local miss rate.
Worked example
- Inputs: L1 hit 1 ns, L1 miss rate 5%, L2 hit 4 ns, L2 local miss rate 20%, memory 80 ns.
- L2 miss penalty: 0.20 × 80 = 16 ns.
- L1 miss penalty: 4 + 16 = 20 ns.
- AMAT: 1 + 0.05 × 20 = 1 + 1 = 2 ns.
| L1 hit time (ns) | AMAT (ns) |
|---|---|
| 0.25 | 1.25 |
| 0.5 | 1.5 |
| 0.75 | 1.75 |
| 1 | 2 |
| 1.25 | 2.25 |
| 1.5 | 2.5 |
| 2 | 3 |
How to read the result
An AMAT close to the L1 hit time means the caches are working well. Here half of the 2 ns comes from misses, even though only 1% of accesses (5% × 20%) reach memory, because memory is 80 times slower than L1. To improve AMAT, look for the largest product: reduce the L1 miss rate with better data locality, or reduce the penalty with a larger or faster L2 or an L3.
Common mistakes
- Using the global L2 miss rate where the formula needs the local rate, or the reverse.
- Adding the full memory latency to every miss, ignoring the L2.
- Mixing nanoseconds and clock cycles in one calculation.
Frequently asked questions
What is the difference between local and global miss rate?
The local rate counts misses among accesses that reach that cache; the global rate counts them among all processor accesses.
How do I add an L3 cache?
Replace the memory latency with L3 hit time + L3 local miss rate × memory latency.
Can I calculate in cycles instead of nanoseconds?
Yes. Use cycles for every time input and the result is in cycles; divide by the clock frequency to convert.
Sources: J. L. Hennessy and D. A. Patterson, Computer Architecture: A Quantitative Approach, Morgan Kaufmann, Appendix B (Review of Memory Hierarchy) · D. A. Patterson and J. L. Hennessy, Computer Organization and Design, Morgan Kaufmann, Chapter 5