Average memory access time (source code)

= Average memory access time
{title2=$t_h+mp$}

= AMAT
{c}
{synonym}

The <arithmetic mean> of <memory access latencies>. Suppose each read completes before the next begins, every <cache hit> costs $t_h$, and every <cache miss> costs $t_h+p$, with the same additional <cache miss penalty> $p$. If $h$ is <cache hit rate> and $m=1-h$ is <cache miss rate>, the <weighted arithmetic mean> is
$$
\operatorname{AMAT}=h\,t_h+m(t_h+p)=t_h+mp.
$$
The common lookup cost is paid on both outcomes. This additive assumption matches the simple model in <Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others/Beyond Physical Memory: Policies> (§22.1, equation 22.1, pp. 1–2), where main <computer memory> acts as a <memory cache> for <memory pages> backed by disk; here the same accounting is applied to a toy data <memory cache>.

Assign synthetic values $t_h=2\,\mathrm{ns}$ and $p=30\,\mathrm{ns}$. The twelve-read, two-slot <fully associative cache> example has five <cache hits> and seven <cache misses>, giving
$$
\operatorname{AMAT}=2+\frac{7}{12}\,30=19.5\,\mathrm{ns},\qquad T=5\cdot2+7\cdot32=234\,\mathrm{ns}.
$$
With four <cache slots>, its four <compulsory misses> instead give $\operatorname{AMAT}=12\,\mathrm{ns}$. This comparison holds the timing costs fixed as capacity changes, which is a model assumption rather than a hardware promise.

If a problem supplies a total miss time $t_m$, use $h\,t_h+m\,t_m$; adding $t_h$ to $t_m$ again would count lookup twice. Variable <cache miss penalties>, multiple consulted levels, or overlapping requests require a richer timing model. Real <CPU> work can overlap a pending read, so this <arithmetic mean> cannot by itself predict program speed or stall time. <Memory part 2: CPU caches by Ulrich Drepper>{ref}