Two of the design choices in a cache are the row size (number of bytes per row…
Two of the design choices in a cache are the row size (number of bytes per row or line) and whether each row is organized as a single block of data (direct mapped cache) or as more than one block (2-way or 4-way set associative). The goal of a cache is to reduce overall memory access time. Suppose that we are designing a cache and we have a choice between a direct-mapped cache where each row has a single 64-byte block of data, or a 2-way set associative cache where each row has two 32-byte blocks of data. Which one would you choose and why? Give a detailed technical justification for your answer. If the choice would make no difference in performance then explain why not.
Attempted by 14 students.
Show answer & explanation
Objective of cache design
The main objective of cache memory is to reduce the average memory access time by increasing the cache hit rate and minimizing miss penalties.Two cache design options
Option 1: Direct mapped cache with 64-byte block size.
Option 2: 2-way set associative cache with two 32-byte blocks per set.
Direct mapped cache characteristics
In direct mapping, each main memory block maps to exactly one cache line.
This structure is simple and fast because it requires only one comparison to check the tag.Problem with direct mapping
Direct mapping suffers from conflict misses.
Two frequently accessed memory blocks may map to the same cache line and continuously replace each other, reducing the hit rate.2-way set associative cache characteristics
In a 2-way set associative cache, each set can store two blocks.
A memory block can be placed in either of the two locations within the set.
Simple structure
CPU
↓
Set 0 → Block A / Block B
Set 1 → Block C / Block D
Advantage
This flexibility reduces conflict misses because multiple blocks that map to the same set can coexist.Block size consideration
Although the direct mapped cache has a larger block size (64 bytes), the 2-way associative cache still benefits from spatial locality due to the 32-byte block.Conclusion
The 2-way set associative cache is preferable because it reduces conflict misses and improves the cache hit rate, which leads to lower average memory access time and better overall system performance.