set associative cache
Summary
Bit allocation
- set index - which set the block would get mapped to
Cache structure
Concept
Set associative cache
- each block is mapped to a corresponding set in cache
- the set can store multiple blocks, n-way -> n blocks per set
- several colliding blocks can be stored alongside
cache_idx = block_num % num_cache_sets
Block replacement policy
- least recently used
- for temporal locality
- keep track of which blocks were accessed
- preserve the more recently accessed blocks
- first in first out
- random replacement
- least frequently used
Application
Memory accesses
- 8 byte blocks -> 3 bit offset
- 4GB memory -> 2³² bytes -> 32-bit memory addresses
- 32B cache -> 2⁵ bytes -> 4 blocks -> 2 sets -> 1 bit set index
- 2-way associative cache