1. Gyanastra
  2. Computer Organisation and Architecture
  3. Cache Performance and Write Policies
  4. Block Replacement Algorithms in Associative Memory
Free lesson, no account needed 4 min read 9 practice questions after it
Asked in past papers3 times
  • GATE CSE201420092004

Computer Organisation and Architecture · Cache Performance and Write Policies

Block Replacement Algorithms in Associative Memory

Overview

In a fully associative cache, a main memory block can be placed in any cache line, so when the cache is full a choice must be made about which existing line to evict.
The rule that makes this choice is the block replacement algorithm, and it directly affects the number of hits and misses and therefore overall cache performance.

Key concepts

  • Associative memory (fully associative cache): a main memory block can be placed into any cache line, so placement is flexible.
  • Block replacement algorithm: the rule that selects which existing line to evict when all lines are full and a new block must be brought in.
  • Direct mapping: a main memory block maps to exactly one line. On a miss there is only one option — whatever is present in that line is replaced — so no decision is needed and no replacement algorithm is required.
  • Standard replacement algorithms: the same family used for page replacement is reused here — LRU (Least Recently Used), FIFO (First In First Out), etc.
  • Performance impact: the choice of replacement algorithm directly affects the number of hits and misses, and hence cache performance.
Memory diagram: Block Replacement Algorithms in Associative Memory
Figure. Block Replacement Algorithms in Associative Memory

How it works

  1. Because a block is free to go into any line in associative memory, placement is flexible.
  2. When all lines are full and a new block must be loaded, one of the existing lines must be selected for eviction.
  3. The block replacement algorithm performs this selection (for example LRU or FIFO).
  4. The selected line's contents are replaced by the incoming block; the algorithm used changes the resulting hit/miss counts.

Comparison

Cache organizationPlacement of a blockReplacement algorithm needed?
Direct-mappedExactly one lineNo — only one candidate line exists, so its contents are replaced on a miss
Fully associativeAny lineYes — multiple candidate lines, so a replacement algorithm is required when the cache is full
Set associativeMultiple candidate lines (within a set)Yes — a replacement algorithm is required when the cache is full

Revision summary

  • Direct-mapped cache needs no replacement algorithm: there is only one candidate line.
  • Fully associative (and set associative) caches need a replacement algorithm once the cache is full.
  • The standard algorithms are LRU and FIFO, borrowed from page replacement.
  • The replacement algorithm changes the hit/miss counts, so it is a performance decision, not just a bookkeeping one.

Previous-year exam insights

  • In a fully associative cache with LRU replacement, if the number of distinct blocks in the access sequence is at most the number of cache lines (associativity), then after the compulsory misses every access is a hit; the miss ratio equals (number of distinct blocks)/(total accesses) only when the working set fits in the cache.
    Asked inGATE 2014
  • LRU replacement: on a hit the accessed block becomes the most recently used; on a miss the least recently used block is evicted and the new block becomes most recently used.
    Simulating a sequence requires tracking the recency order of blocks within each set.
    Asked inGATE 2009
  • In an A-way set associative cache with S sets, block address b maps to set (b mod S);
    the tag is b div S. Total cache blocks = A × S.
    Asked inGATE 2009
  • For a set-associative cache, the number of sets equals (total cache blocks)/(associativity); each set is searched associatively and needs a replacement algorithm only when all A ways of that set are occupied.
    Asked inGATE 2009
  • Compulsory (cold) misses occur on the first access to each distinct block and cannot be avoided by any replacement policy; replacement policy only affects conflict and capacity misses.
    Asked inGATE 2014
  • Other standard replacement policies besides LRU and FIFO include Optimal (Belady's MIN, evict the block used farthest in the future — used as a benchmark, not implementable) and Random; LRU is a stack algorithm and never suffers Belady's anomaly, whereas FIFO can.
Pages 1–2 of 2