direct mapped cache

Complete

Summary

Bit allocation

  • cache index - which cache block the block would get mapped to
  • tag - used to match for the specific memory address when checking the cache
o®setn-1:0blocknumber...:no®setn-1:0cacheindexn+m-1:ntag...:n+m

Cache structure

  • valid bit - indicate whether the block contains valid data
00011011validtagdata

when talking about the size of the cache, only the space for data is counted, the valid bit and tags are ignored

Concept

Direct mapped cache

  • each block is mapped to a corresponding block in cache
  • hash table that can store a subset of memory
  • has compulsory and conflict misses
cache_idx = block_num % num_cache_blocks
...00000......00001......00010......00011......00100......00101......00110......00111......01000......01001...00011011

Compulsory/cold miss

  • when the block is first accessed, it must be brought into a cache
  • a miss that will happen regardless

Conflict miss

  • when something else is currently occupying the cache block that the target was previously cached to
  • collision

if something else is occupying the cache block, but this is the first time accessing the address, its still a cold miss

Write miss

  • when the target to be written to is not in the cache
  • write allocate
    1. load block from memory into cache
    2. change the word in cache
    3. write to memory following write policy
  • write around
    • write directly to memory without loading to cache

Application

Memory accesses

  • 8 byte blocks -> 3 bit offset
  • 4GB memory -> 2³² bytes -> 32-bit memory addresses
  • 32B cache -> 2⁵ bytes -> 4 blocks -> 2 bit cache index