ENES

CPU cache

A tiny, very fast memory inside the processor that keeps the data it is about to need.

A CPU core with three nested boxes, L1, L2 and L3, growing bigger and slower on the way out to RAM

A CPU can do billions of operations per second, but fetching data from RAM takes far longer than one operation: the processor would spend most of its time waiting. The CPU cache fixes that. It is a small amount of extremely fast memory built into the chip itself, holding copies of the data and instructions the processor used recently or is likely to use next.

Caches come in levels. L1 cache sits right next to each core: tiny (tens of kilobytes) and almost instant. L2 cache is bigger and a bit slower. L3 cache is larger still, often several megabytes or more, and usually shared by all the cores. When the CPU needs something it checks L1, then L2, then L3, and only goes to RAM if none of them has it. Finding it is a hit; going all the way out is a miss.

Caches work because programs are predictable: they tend to reuse the same data and to read memory in order. The chip loads whole neighboring chunks at once and keeps what was used lately. That is why two programs doing the same math can run at very different speeds depending on how they lay out their data, and why chipmakers advertise cache size next to cores and clock speed.

Keep in mind

Go deeper

Related terms

More in Hardware