= Cache line
= Cache block
{synonym}
A fixed-sized, aligned block of consecutive <bytes> transferred and tracked as a unit by a data <memory cache>. Here <cache line> and <cache block> name that unit of data, including its identity in backing <computer memory>; a resident slot holds a copy. Reading one element can bring neighbouring elements into the same <cache line>, exploiting <spatial locality>.
For a nonnegative <integer> <physical address> $a$ and a <cache line> size $B$ <bytes>, <Euclidean division> gives the backing <cache block> number $q$ and offset $d$:
$$
q=\left\lfloor\frac{a}{B}\right\rfloor,\qquad d=a\bmod B,\qquad a=Bq+d,\qquad 0\leq d<B.
$$
Here the brackets denote the <floor function> and $\bmod$ gives the <remainder>. <Cache line> $q$ contains <bytes> at <physical addresses> $Bq$ through $Bq+B-1$. With $B=16$, read address 52 selects <cache block> 3, spanning addresses 48–63, and offset 4. Addresses 48 and 52 therefore request the same <cache line>; addresses 15 and 16 request different <cache lines> despite being adjacent.
\Image[/cache-line-address-geometry.png]
{title=<Physical address> 52 selects <cache line> 3 and offset 4; the resident copy occupies <cache slot> 0}
For a <cache line> size $B=2^b$, the low $b$ <bits> give the offset. In a <fully associative cache>, all remaining <bits> identify the backing <cache block> as its <cache tag>; there are no address <bits> selecting a particular <cache slot>. An eight-<bit> illustration gives $52=\mathtt{00110100}_2$: four <bits> `0011` for <cache block> 3 and four <bits> `0100` for offset 4 in the <binary numeral system>. The eight-<bit> width is illustrative; the trace does not assume an actual eight-<bit> machine. <Memory part 2: CPU caches by Ulrich Drepper>{ref}
Distinguish this identity from a <cache slot>, which can hold different <cache blocks> over time. After read nine in the <memory cache> example, <cache slot> 0 contains <cache line> 3 and <cache slot> 1 contains <cache line> 0. Their <cache tags> identify 3 and 0; neither <cache line> number is its slot number. Some texts use “cache line” for the storage entry itself; this article reserves <cache slot> for that role.
Back to article page