Skip to main content

Associative vs set associative mapping

Short answer

Associative mapping allows a block in any line, uses full tag and parallel comparison of all tags, highest hit ratio but costly. Set associative divides cache into sets; a block maps to a fixed set (by index) but any line within the set, requiring only k comparators. It reduces cost and conflict misses compared to direct mapping, with near-associative hit ratio for k≥4.

Differentiate between associative mapping and set associative mapping with example.

PointAssociative mappingSet associative mapping
PlacementA block can go in any cache lineA block goes in one fixed set, any line of the set
Address formatTag, wordTag, set, word
Tag lengthLongestShorter by the set bits
ComparatorsOne per line, all in parallelk per set (k-way)
Hit ratioBestSlightly less, close for k = 4 or 8
Cost and speedCostly and slowest searchCheaper and faster
ReplacementOver the whole cacheWithin the selected set only
Conflict missesNoneFew

Example

Main memory of 32 blocks (5-bit block number), cache with 8 lines, 2-way set associative; consider block 21 (10101).

  • Associative: block 21 may go to any of the 8 lines; the 5-bit tag 10101 is compared with all 8 tags.
  • Set associative (2-way): sets = 8/2 = 4. Set = 21 mod 4 = 1 (binary 01), tag = 21 div 4 = 5 (101). Block 21 can use either of the two lines of set 1; only 2 tags are compared. Blocks 1, 5, 9, 13, 17, 21, 25 and 29 all compete for the two lines of set 1.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Organization and Architecture chapter 6 questions →