Cache Mapping
Main Memory Address :ββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββ Main Memory Block no β Byte Offset βββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββ β¬ β¬ β¬ββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββ Tag β Cache Line β Byte Offset βββββββββββββ΄ββββββββββββββββββββββββββββ΄βββββββββββββββββββββDirect Mapping
Section titled βDirect MappingβFormulas :
- Offset Bits : Represent block size (words/bytes inside a block)
- Offset Bits =
logβ(Block Size)
- Offset Bits =
- Tag Bits : Represents number of main memory blocks competing for one cache line
- Tag Bits =
logβ(Memory Size / Cache Size)orlogβ(No. of Main Memory Blocks / No. of Cache Blocks)
- Tag Bits =
- Block No. / Line : Represent No. of Blocks
- Main Memory Block Bits =
logβ(No. of Main Memory Blocks) - Cache Line Bits =
logβ(Number of Cache Blocks)
- Main Memory Block Bits =
- Address Bits : Represent addressable memory size
- Main Memory Address Bits =
logβ(Main Memory Size) - Cache Memory Address Bits =
logβ(Cache Size)
- Main Memory Address Bits =
Mental model
β’ Byte offset for Cache and Main Memory is SAME β Block size is SAME β MM Block Size = CM Block Size = Block Size
β’ Main Memory Block Bits β₯ Cache Line Bits β No. MM Blocks β₯ No. CM Blocks
β’ Main Memory Address Bits β₯ Cache Address Bits β MM Blocks Γ Block Size > CM Blocks Γ Block Size β Total Main Memory Size > Total Cache Size
β’ Tag Bits: β For ONE cache block, how many main memory blocks can map to it β 2^(Tag Bits) = No. of MM blocks per cache blockMain Memory Block Number= [ TAG | INDEX ]
INDEX β selects the cache lineTAG β identifies which memory block is in that lineOFFSET β selects data inside the blockMain Memory Address
ββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββ Tag β Cache Line β Byte Offset βββββββββββββ΄ββββββββββββββββββββββββββββ΄βββββββββββββββββββββ<---------------- Main Memory Address Bits ----------------> β log2(Main Memory Size)
-> Main Memory Address Bits - Offset Bits = logβ(Main Memory Size) - logβ(Block Size) = logβ(Main Memory Size / Block Size) = = logβ(Number of Main Memory Blocks) = Main Memory Block Bits
ββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββ Tag β Cache Line β Byte Offset βββββββββββββ΄ββββββββββββββββββββββββββββ΄βββββββββββββββββββββ<------- Main Memory Block Bits -------> <--- Offset Bits ---> β β logβ(No. of Main Memory Blocks) logβ(Block Size)Cache Memory Address
ββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββ Tag β Cache Line β Byte Offset βββββββββββββ΄ββββββββββββββββββββββββββββ΄βββββββββββββββββββββ <---------- Cache Memory Address Bits -----------> β log2(Cache Memory Size)
-> Cache Memory Address Bits - Offset Bits = logβ(Cache Size) - logβ(Block Size) = logβ(Cache Size / Block Size) = = logβ(Number of Cache Blocks) = Cache Line Bits
ββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββ Tag β Cache Line β Byte Offset βββββββββββββ΄ββββββββββββββββββββββββββββ΄βββββββββββββββββββββ <---- Cache Block Bits ---> <--- Offset Bits ---> β β logβ(No. of Cache Blocks) logβ(Block Size)