1. Gyanastra
  2. Computer Organisation and Architecture
  3. Set Associative and Fully Associative Cache
  4. Tag Bits in Associative Mapping
Free lesson, no account needed 4 min read 12 practice questions after it
Asked in past papers1 time
  • GATE CSE2019

Computer Organisation and Architecture · Set Associative and Fully Associative Cache

Tag Bits in Associative Mapping

Overview

In fully associative mapping any block of main memory can be placed in any cache line, so a line cannot infer which block it holds from the address.
Each line must therefore store the entire block number as its tag, which removes conflict misses but makes every access search all tags.

Key concepts

  • Fully associative mapping: any block of main memory can be placed in any line of the cache; the position of a block is completely unrestricted.
  • Tag in fully associative mapping: the tag is the entire block number, because the line cannot rely on the address to tell it which block it holds.
  • Tag size: with 16 blocks in main memory, the tag needs 4 bits, since 24=162^4 = 16 and 4 bits can encode any of the 16 block numbers.
  • Contrast with direct mapping: in direct mapping a block can go into only one particular line, so the line information is implied by the address and is not stored; only the remaining (upper) bits are kept as the tag.
    Hence tag bits are more in fully associative mapping than in direct mapping.
  • Advantage — no conflict miss: as long as there is some empty space in the cache, a block will never be replaced, so cache capacity is used completely.
  • Disadvantage — larger tags: the size of the tags increases (tolerable).
  • Disadvantage — search cost (the main problem): when a memory address is presented, there is no known place to go and search, so all the tags must be examined. In direct mapping, only one particular tag was selected (using a multiplexer), only those tag bits were read, and only one comparator was used.
Memory diagram: Tag Bits in Associative Mapping
Figure. Tag Bits in Associative Mapping

How it works

  1. Main memory has some number of blocks (for example, 16), and any of them may reside in any cache line.
  2. Each line must therefore be able to distinguish among all possible blocks (all 16).
  3. The number of tag bits equals the number of bits in the block number: log⁡2(number of blocks)\log_2(\text{number of blocks}).
  4. The tag field stores the entire block number (4 bits for 16 blocks).
  5. On an access, since the target line is unknown, all tags are examined and compared against the presented address.

Formulas

  • tag bits (fully associative)=bits in the block number=log⁡2(number of blocks in main memory)\text{tag bits (fully associative)} = \text{bits in the block number} = \log_2(\text{number of blocks in main memory})

  • number of blocks in main memory: total blocks that any cache line may hold.

  • tag bits (direct mapping)=block number bits−line number bits\text{tag bits (direct mapping)} = \text{block number bits} - \text{line number bits}

  • the line portion is implied by the address and is not stored.

Worked examples

Main memory = 16 blocks, fully associative cache:

  1. Any of the 16 blocks may reside in any line.
  2. Each line must distinguish among all 16 blocks.
  3. Bits needed = log⁡2(16)=4\log_2(16) = 4 bits.
  4. So the tag field = the entire block number (4 bits).

Comparison

FeatureDirect mapping (earlier scheme)Fully associative mapping
Block placementA block goes to exactly one lineAny block in any line
Tag contentsOnly the remaining (upper) bits; line part impliedEntire block number
Tag sizeSmallerLarger (4 bits for 16 blocks)
Search on an addressSelect one tag via multiplexer, read it, one comparatorMust examine all tags
Conflict missesPossibleNone (as long as free space exists)
Cache utilizationLimited by fixed mappingComplete use of capacity

Revision summary

  • In fully associative mapping the tag is the whole block number; for 16 blocks that is 4 bits.
  • Placement is unrestricted, so the line cannot infer the block from the address — the full block number must be stored.
  • No conflict misses occur as long as empty space exists; capacity is fully used.
  • Tags are larger than in direct mapping.
  • Every access must search all tags, because the target line is unknown.
  • Direct mapping needs only a multiplexer to select one tag and a single comparator; fully associative mapping cannot do this.
Pages 1–2 of 2