Back to the 2015 paper

Module 4: Memory Organization

201514m

Explain in detail the three mapping procedures related to cache memory.

Worked SolutionAI Assisted

Cache mapping decides how a main memory block maps to cache line(s). Let cache have 2c2^c lines, memory have 2m2^m blocks, address = Tag + Index/Set + Word/Offset.

1. Direct Mapping

Each memory block ii maps to exactly one cache line: line=imod  (no. of lines)line = i \mod (\text{no. of lines}).
Address split: ∣Tag∣+∣Line∣+∣Word∣|Tag| + |Line| + |Word|.
e.g., 4096 lines need 12 line bits. With 64-word blocks (6 bits), address = Tag(remaining)+12+6.

  • Search: Compare only that line's tag - fast, simple.
  • Miss: Replacement is forced, no choice.
  • Drawback: Thrashing - two blocks mapping to same line continuously collide even if cache has free lines.

2. Associative (Fully Associative) Mapping

Any memory block can go to any cache line. Address = ∣Tag∣+∣Word∣|Tag| + |Word| only; no line field.

  • Search: Content-addressable memory (CAM) compares incoming Tag with all line tags in parallel.
  • Replacement: Need algorithm - LRU, FIFO, Random.
  • Advantage: No collision thrashing, best hit rate.
  • Drawback: Expensive comparators for all lines, slow for large cache.

3. Set-Associative Mapping

Compromise. Cache divided into SS sets, each set has kk lines (kk-way). Block ii maps to set=imod  Sset = i \mod S, can occupy any of kk lines within set.

  • Address: ∣Tag∣+∣Set∣+∣Word∣|Tag| + |Set| + |Word|.
    Example k=2k=2, 4096 lines → 2048 sets → 11 set bits. Address = Tag+11+6.

  • Search: Index set via Set field, associatively compare Tag among kk lines in that set only.

  • Replacement: Choose within set (LRU).

  • Special cases: k=1k=1 → Direct, k=no. of linesk = \text{no. of lines} → Fully Associative.

  • Tradeoff: Hit rate improves with larger kk but cost increases. Typical k=2,4,8k=2,4,8.

Replacement policies (LRU, LFU, FIFO) apply to associative and set-associative when set is full. Write policies: Write-through + write-allocate/no-allocate, Write-back.

Similar questions

Free AppAndroid App

Coursify Android App

Generate AI courses, take quick quizzes between classes, and master complex engineering concepts on the go.