Professional Documents
Culture Documents
Cache Memory: Chapter # 5
Cache Memory: Chapter # 5
Cache Memory: Chapter # 5
Cache Memory
The Bottom Line
Registers
L1 Cache
L2 Cache
L3 Cache
Main memory
Disk cache
Disk
Optical
Tape
So you want fast?
During the course of the execution of a program, memory references tend to cluster
e.g. Loops
Spatial locality (array) vs Temporal locality(loop)
Cache
The processor cache is a high speed memory that keeps a copy of the frequently used data
• When the CPU wants a data value from memory, it first looks in the cache
• If the data is in the cache, it uses that data
• If the data is not in the cache, it copies a line of data from RAM to the cache and gives
the CPU what it wants
Elements of Cache Design
Addressing
Size
Mapping Function
Replacement Algorithm
Write Policy
Block Size
Number of Caches
Cache Addressing
Cost
More cache is expensive
Speed
More cache is faster (up to a point)
Mapping Function
Because there are fewer cache lines than main memory blocks, an algorithm is needed for mapping main
memory blocks into cache lines
Three techniques can be used
Direct
The simplest technique
Maps each block of main memory into only one possible cache line
• Each location in RAM has one specific place in cache where the data will be held
Associative
In associative cache mapping, the data from any location in RAM can be stored in any location in
cache
Set Associative
Cache of 64kByte
Cache block of 4 bytes
i.e. cache is 16k (214) lines of 4 bytes
16MBytes main memory
24 bit address
(224=16M)
Direct Mapping
24 bit address
2 bit word identifier (4 byte block)
22 bit block identifier
8 bit tag (=22-14)
14 bit slot or line
Simple
Inexpensive
Fixed location for given block
If a program accesses 2 blocks that map to the same line repeatedly, cache misses are very high
(Fully) Associative Mapping