What is Cache memory?
Fast, small memory placed close to the CPU. It holds frequently used data to bridge the speed gap with main memory. Mostly built from SRAM.
Field: CPUs and architecture
Read the beginner explainer: How Does CPU Cache Work? Hit Rate, Lines and Locality
Japanese name: キャッシュメモリ
Why it is needed
A CPU advances one operation in less than a nanosecond, but fetching data from DRAM main memory takes tens of nanoseconds or more. Waiting for DRAM every time would waste the speed of the CPU. Programs tend to reuse data they used recently and data near it (locality). A small, fast memory therefore keeps copies of recently used data so that most accesses finish there. That memory is the cache.
Why there are levels
Memory cannot be both very fast and very large, so the cache is split into levels. L1, closest to the CPU, is only tens of kilobytes, is divided into instruction and data caches, and is read in a few cycles. L2 is hundreds of kilobytes to a few megabytes and takes a dozen or so cycles. L3 is a few to tens of megabytes, takes tens of cycles, and in most CPUs is shared by several cores. A lookup tries L1, then L2, then L3, and finally main memory.
Hits, misses and average access time
If the wanted data is in the cache it is a hit; otherwise it is a miss, and fetching from the next level costs extra time, the miss penalty. The average access time can be estimated as hit time + miss rate × miss penalty. With a 1 ns hit time and a 100 ns miss penalty, a 5% miss rate gives 6 ns and a 2% miss rate gives 3 ns. A small change in miss rate changes the average speed a great deal. Data moves in lines of, for example, 64 bytes, so using nearby data in sequence makes hits more likely.
Try it: questions about Cache memory
- ATo retain data when the power is turned off
- BTo keep frequently used data close to the CPU and bridge the speed gap with main memory
- CTo correct errors in computation results
Show answer and explanation
Answer: B. To keep frequently used data close to the CPU and bridge the speed gap with main memory
While one clock cycle of a CPU running at several GHz lasts 0.2–0.3 ns, a DRAM access takes tens to 100 ns—hundreds of cycles. Frequently used data and instructions are therefore kept in fast SRAM caches to cut waiting. Caches exploit temporal locality (reusing the same data soon) and spatial locality (using nearby addresses next), with L1 reachable in a few cycles and even L3 in tens of cycles.
FAQ
Why is cache memory built from SRAM?
SRAM reads and writes faster than DRAM, needs no refresh and can be built on the same chip with the same process as the CPU. Its area per bit is large, so it is not suited to a large main memory.
Is there anything a programmer can do?
Yes. Walking arrays in order and keeping data that is used together close together make hits more likely. Traversing a two-dimensional array against its layout in memory can add many misses and slow a program considerably.
Books on CPUs and architecture Ad
As an Amazon Associate I earn from qualifying purchases.
Comparisons that include this term
- DRAM vs SRAM: Key Differences ExplainedDRAM vs SRAM in one table: cell structure, refresh, speed, density, cost, power and typical uses, plus a guid…
- CPU vs GPU: Differences in Architecture and UseCPU vs GPU compared in a table: design goal, core count, execution model, caches, memory bandwidth, branching…
- Write-Through vs Write-Back Cache: Differences ExplainedWrite-through vs write-back cache compared in a table: write policy, memory traffic, speed, consistency, comp…
- Von Neumann vs Harvard Architecture: Differences ExplainedVon Neumann vs Harvard architecture compared in a table: memory, buses, throughput, flexibility, complexity, …
- L1 vs L2 vs L3 Cache: Key Differences ExplainedL1 vs L2 vs L3 cache in typical PC and server CPUs: size, latency, per-core vs shared, split instruction/data…
- Write-Allocate vs No-Write-Allocate: Write Misses and TrafficWrite-allocate vs no-write-allocate cache policies in one table: write-miss behavior, line fill, pairing with…
Semiconductor, Electronics and Computing Calculators
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.
Back to the glossary