Cache Organization
Cache Lines
Section titled “Cache Lines”The cache is divided into fixed-size blocks called cache lines (typically 64 bytes on x86). Each line stores:
- Data — the 64-byte block from memory
- Tag — the high-order address bits identifying which memory block is stored
- Valid bit — whether the line contains valid data
- Dirty bit — whether the data has been modified (for write-back caches)
Address Decomposition
Section titled “Address Decomposition”Given a memory address, the cache hardware splits it into three parts:
- Offset ( bits): selects the byte within the cache line. For 64-byte lines, .
- Index ( bits): selects which set in the cache to check. With sets, .
- Tag ( bits): the remaining bits, used to verify if the correct block is stored.
Cache Associativity
Section titled “Cache Associativity”The associativity determines how many lines can map to the same set:
Direct-Mapped ()
Section titled “Direct-Mapped (W=1W = 1W=1)”Each memory block maps to exactly one cache line. Simple and fast, but vulnerable to conflict misses when two frequently used addresses map to the same index.
Address → Index → Check tag → Hit or missSet-Associative ()
Section titled “Set-Associative (W=2,4,8,…W = 2, 4, 8, \ldotsW=2,4,8,…)”Each set contains ways. A memory block can go in any of the lines in its set. This reduces conflict misses at the cost of comparing tags in parallel.
For a cache with bytes, -byte lines, and -way associativity:
Fully Associative ()
Section titled “Fully Associative (S=1S = 1S=1)”A block can go anywhere in the cache. No conflict misses, but requires comparing against every tag — expensive and typically only used for small caches (e.g., TLBs).
Example: 32 KB, 8-way, 64-byte lines
Section titled “Example: 32 KB, 8-way, 64-byte lines”- Offset: bits
- Index: bits
- Tag: remaining address bits (e.g., bits for 48-bit addresses)