This article reflects the time it was first published. Products, links, and processes may have changed since then.
English edition prepared from the Turkish original. Original publication date retained.
Archive note. This article reflects the time it was written. Some details and links may be outdated.
Let's start with the basics. A computer contains data. The processor works on that data to produce output. Data is stored persistently, so it survives the power being switched off, on a disk. There are other storage methods, such as CDs and DVDs, but let's use a hard disk as our starting point.
For data to become output, it has to be processed. But the processor doesn't work on data directly on the disk or in RAM. The data needs to be in the processor's own registers.
The processor is fast. Fetching data takes time.
A mechanical hard disk is slower to access than RAM. The processor can work very quickly. Even if it were technically possible to fetch everything straight from the disk, process it, and write it back, this would be a poor arrangement. The processor would spend much of its time waiting.
RAM sits between the disk and the processor. It is fast, but not as fast as the processor. Moving data from memory to the processor and writing the result back is much quicker than working with disk, yet it can still leave the processor waiting.
Enter the caches
That is why L1, L2, and L3 caches sit between RAM and the processor's execution machinery. In broad terms, speed follows L1 > L2 > L3 > RAM. Cost per unit of storage follows the same order. That's why L1 is much smaller. It's expensive!
L1, L2, and L3 are generally integrated with the processor. They hold copies of memory data for faster access.
Imagine the processor is busy with one program. Much of the data belonging to other programs is irrelevant at that moment. Even within the active program, only part of it is being used: perhaps drawing the interface, rather than accessing the database.
The original article uses this simplified picture: some of that active data is kept in L3, a smaller selection in L2, and a still smaller selection in L1, where access is very fast.
The short version
- These caches are generally inside the processor, although the arrangement varies by architecture.
- Cache is faster and closer to the processor than RAM, but more expensive, so there is less of it.
- Cache holds copies of data from memory to reduce the time spent fetching it.
This is a translation of an introductory explanation from 2011. Modern processors differ in their cache organisation, and the nested-subset picture above is a simplification.