Cache Memory
Cache Memory
• Temporal Locality
• Spatial Locality
• Temporal Locality: if at one point in time a particular memory
location is referenced, then it is likely that the same location will be
referenced again in the near future. There is a temporal proximity
between the adjacent references to the same memory location. In this
case it is common to make efforts to store a copy of the referenced
data in special memory storage, which can be accessed faster.
Temporal locality is a very special case of the spatial locality, namely
when the prospective location is identical to the present location.
• Spatial Locality:
If a particular memory location is referenced at a particular time, then it
is likely that nearby memory locations will be referenced in the near
future. There is a spatial proximity between the memory locations,
referenced at almost the same time. In this case it is common to make
efforts to guess, how big neighbourhood around the current reference
is worthwhile to prepare for faster access.
Basic Terms
• Cache Block
• Miss/Hit
• Miss Rate/Hit Rate
• Miss Penalty
• Hit Time
• 3-Cs of caches
– Conflict
– Compulsory
– Capacity
Direct Mapped Cache
Assume 5-bit address bus and cache with 8 entries
Data Bus
=
HIT
Direct Mapped Cache
First Load
Data Bus
LD R1, (01010) ;remember 5-bit address bus, assume data is 8-
bit and
AA16 is stored at this location
First time, cause a MISS, data loaded from memory and cache HIT bit is
Direct Mapped Cache
After first load
Data Bus
LD R1, (01010) ; AA16 is stored at this location, Cache HIT bit is
set to 1
Direct Mapped Cache
Second Load
Data Bus
LD R1, (11010) ; assume 99 at address 11010
Same index but different TAG will cause a MISS, data loaded from
memory
Direct Mapped Cache
After Second Load
Data Bus
LD R1, (11010) ;remember 5-bit address bus, assume 99
First time, same index but different TAG will cause a MISS, data loaded
from memory
Cache Size Example
Direct Mapped
Valid TAG DATA
(15 bit) (32
32K X 48-bit 0
bit)
1 1111 1111 1111 1111 1111
Memory 1111
Processor Address Bus
32 K
Address Bus (A16 – A2) 0 Entries
0
0
0
(32-bit)
A31-
A17=15 =
(15-bit)
Processor Address bus = 32 bit (A)
Cache Storage = 128KB = 32 K Words (2N) with N = 15 Data Out
Number of blocks in cache (entries) = 32K
Tag Size = A- N- 2 = 32 – 15 – 2 (Byte offset) = 15
Cache Size = 128KB (data) + 32K X 15-bit (tag) + 32K X 1-bit (Hit bit) =
Cache Size Example (1)
Two-Way Set Associative
Memories 1111
0 0
16 K
0 Entries 0
Address Bus (A16 – A2) 0 Address Bus (A16 – A2) 0
0 0
0 0
0 0000 0000 0000 0000 0000
0000
0
Data Out
(16-bit) (16-bit)
Size = 2 (Sets) X
Data Out
16K X (32-bit + 16-bit + 1-
bit) 2:1 MUX
= 196KB
Cache Size Example (1)
4-Way Set Associative
Data Out
Data Out
Data Out
(17-bit) (17-bit) (17-bit) (17-bit)
4:1 MUX
Size = 4 (Sets) X
8K X (32-bit + 17-bit + 1-bit)
Data Out to
processor
= 200KB
Organization of the data cache Alpha 21264
512 Entries Cache (2 Sets)
Alpha 21264 Processor44-Bit Virtual
Data Out
(29-bit) (29-bit)
Size = 2 (Sets) X
Data Out
16K X (32-bit + 16-bit + 1-
bit) 2:1 MUX
= 196KB
Four Memory Hierarchy Questions
• Where can a block be placed
•Direct Mapped to Fully Associative
14 1- Way (direct
(ns)
mapped)
2- Way
Access Time
12 4- Way
Fully Associative
10
0
4KB 8KB 16KB 32KB 64KB 128K 256K
Cache Size B B
Reducing Cache Misses
Loop Interchange