1. Gyanastra
  2. Computer Organisation and Architecture
  3. Set Associative and Fully Associative Cache
  4. Associative Mapping
Free lesson, no account needed 6 min read 11 practice questions after it
Asked in past papers4 times
  • GATE CSE2019
  • ISRO2011
  • UGC NET20182013

Computer Organisation and Architecture · Set Associative and Fully Associative Cache

Associative Mapping

Overview

Associative mapping is a cache mapping technique that removes the restriction of direct mapping: any block of main memory can be placed in any line of the cache.
It is introduced specifically to solve the problems of direct mapping, and it changes how the address is split — the whole block number becomes the tag and there is no index field.

Key concepts

  • Associative mapping: a cache mapping technique in which any block of main memory can be placed in any line of the cache. It is a many-to-many mapping, unlike direct mapping, which is many-to-one.
  • Purpose: introduced specifically to solve the problems of direct mapping.
  • Tag: because a cache line may hold any one of the main-memory blocks, the tag must distinguish among all of them, so the entire block number is stored as the tag.
  • No index field: the cache line is not determined by the address, so associative mapping has no index field.
Memory diagram: Associative Mapping
Figure. Associative Mapping

How it works

  1. Take the physical address size and the block size.
  2. Compute the block offset bits: the number of bits needed to address a byte inside the block.
  3. Compute the block number bits: physical address bits minus block offset bits.
  4. Compute the number of main-memory blocks: 2block number bits2^{\text{block number bits}}, numbered from 0 upward.
  5. Under associative mapping, all these blocks have the freedom to be present in any line of the cache — the mapping is many-to-many, not many-to-one.
  6. In direct mapping, a given cache line could only ever hold one of a fixed small set of blocks, so only the remaining (upper) part of the block number had to be stored as the tag.
    Here a cache line may hold any one of the blocks, so the tag must distinguish among all possibilities.
  7. The tag field therefore holds the entire block number, and the index field is absent.

Formulas

  • Block offset bits=log⁡2(block size in bytes)\text{Block offset bits} = \log_2(\text{block size in bytes}) — number of bits needed to address a byte inside the block.

  • Block number bits=physical address bits−block offset bits\text{Block number bits} = \text{physical address bits} - \text{block offset bits} — bits identifying the main-memory block.

  • Number of main-memory blocks=2block number bits\text{Number of main-memory blocks} = 2^{\text{block number bits}} — total blocks in main memory, numbered from 0.

  • Tag bits (associative mapping)=block number bits\text{Tag bits (associative mapping)} = \text{block number bits} — the whole block number is the tag.

  • Index bits (associative mapping)=0\text{Index bits (associative mapping)} = 0 — no index field.

  • Associative mapping address split

  • Shows how a 6-bit physical address splits into a 4-bit tag, 2-bit block offset, and no index field under associative mapping.

Worked examples

Address split for a 6-bit physical address, 4-byte block, associative cache:

FieldBitsHow derived
Block offset2log⁡2(4 bytes)=2\log_2(4 \text{ bytes}) = 2
Tag4entire block number (16 blocks → 4 bits)
Index0no index in associative mapping
Total6given physical address size
  • Block offset = 2 bits, because block size 4 bytes = 222^2 bytes, so 2 bits address a byte inside the block.
  • Remaining bits for the block number = 6−2=46 - 2 = 4 bits.
  • Number of main-memory blocks = 24=162^4 = 16 (blocks 0 to 15).
  • All 16 blocks can be present in any line of the cache.
  • Because any of the 16 blocks can sit in any cache line, each line's tag must be able to name any of the 16 blocks → tag = 4 bits.

Comparison

AspectDirect mappingAssociative mapping
Placement ruleA block maps to exactly one line (many-to-one)Any block can go to any line (many-to-many)
Tag contentOnly the remaining (upper) part of the block numberThe entire block number
Tag size (example)Smaller (partial block number)4 bits (full block number)
Index fieldPresentAbsent

Revision summary

  • Associative mapping removes the direct-mapping restriction: any main-memory block → any cache line.
  • The mapping is many-to-many; a cache line can hold any of the 2block number bits2^{\text{block number bits}} blocks.
  • Because the line is not determined by the address, there is no index field; the whole block number becomes the tag.
  • Worked example: 6-bit address, 4-byte block → 2-bit offset, 4-bit block number, 16 blocks, 4-bit tag, 0-bit index.
  • In direct mapping only the leftover part of the block number is stored in the tag; in associative mapping the full block number must be stored.
  • Trap: the tag is not the leftover upper part of the block number here — it is the entire block number.

Previous-year exam insights

  • In a fully associative cache the number of tag bits equals the number of bits in the block number (physical address bits minus block offset bits), and the index bits are 0; the cache size and number of lines do not affect the tag width.
    Asked inGATE 2019
  • Block offset bits = log⁡2(block size in bytes)\log_{2}(\text{block size in bytes});
    block number bits = physical address bits − block offset bits;
    tag bits = block number bits for fully associative, and tag bits = block number bits − log⁡2(number of sets)\log_{2}(\text{number of sets}) for set-associative.
    Asked inGATE 2019
  • The three standard cache mapping schemes are direct mapping, associative (fully associative) mapping and set-associative mapping; segmented-page mapping is a memory-management/paging scheme, not a cache mapping.
    Asked inUGC NET 2018
  • Associative memory (content-addressable memory) searches all stored keys in parallel (simultaneously) in a single access, which is why it is used for TLB and fully associative cache tag comparison.
    Asked inUGC NET 2013ISRO 2011
  • Fully associative mapping places a block in any line and so requires a replacement policy (LRU, FIFO, random) on a miss when the cache is full; it compares the tag against every line's tag in parallel.
    Direct mapping needs no replacement policy but has conflict misses.
  • Associative mapping has the highest hit ratio (no conflict misses) but the highest cost and slowest tag search;
    direct mapping is cheapest and fastest but suffers conflict misses;
    set-associative mapping is the compromise with index bits = log⁡2(number of sets)\log_{2}(\text{number of sets}).
Pages 1–2 of 2