GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Trace set mapping and LRU replacement

3 questions solved the same way, newest first. Back to Computer Organization & Architecture

How these are solved

Map each supplied memory block to a set and maintain its LRU order from an empty cache. Variants ask total misses, final absent block, or conflict-only misses for a repeated sequence.

2 marks · NAT
Report issue

Cache Memory

Question 51, GATE 2017: A 256-block, 2-way set-associative cache uses LRU and starts empty. Repeat this block-reference sequence ten times: 0,128,256,128,0,128,256,128,1,129,257,129,1,129,257,129. Count conflict misses, excluding compulsory first-access misses.
Tap to enlarge
Answer & solution

Official answer: 76.0

Our answer: 76

1. There are 256/2=128 sets. Block number modulo 128 puts {0,128,256} in set 0 and {1,129,257} in set 1; each set holds only two blocks.

2. For the first set-0 subsequence 0,128,256,128,0,128,256,128 the outcomes are compulsory,compulsory,compulsory,hit,conflict,hit,conflict,hit. LRU ends with 256 then 128 from least to most recent. Set 1 behaves identically.

3. Each later subsequence starts with those two survivors: accesses to its first,third,fifth,seventh entries miss, all now conflicts. Thus repetition 1 has four conflicts total, and each of nine later repetitions has eight. Total=4+9×8=76 conflicts, alongside six compulsory misses.

Original paper, page 23 · Answer key

2 marks · MCQ
Report issue

Four-way set-associative LRU contents

Cache Memory

Question 29, GATE 2009: An initially empty four-way cache has 16 blocks and memory 256 blocks. Reference sequence:0, 255, 1, 4, 3, 8, 133, 159, 216, 129, 63, 8, 48, 32, 73, 92, 155. With LRU within each set, which block is absent at the end? A 3; B 8; C 129; D 216.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

There are 16/4=4 sets, selected by block number modulo 4. Simulating LRU gives oldest-to-newest final sets: set 0=[8, 48, 32, 92], set 1=[1, 133, 129, 73], set 2=[], set 3=[3, 159, 63, 155]. Thus 3, 8, 129 remain but 216 has been evicted, D. In set 0, insertion 32 removes 4 and insertion 92 removes 216 after 8 was refreshed.

There are 16/4=4 sets; choose set number by block modulo 4. Only blocks mapping to the same set compete for four ways. In set 0, references are 0, 4, 8, 216, 8, 48, 32, 92. The second 8 refreshes its recency; inserting 48 removes 0, 32 removes 4, and 92 removes 216. The final set is 8, 48, 32, 92. Other sets retain 3 and 129. Hence 216, option D, is the absent listed block.

Original paper, page 6

2 marks · MCQ
Report issue

Two-way LRU cache conflicts

Cache Memory

Question 65, GATE 2004: A two-way set-associative cache contains four blocks total and uses LRU replacement. How many misses occur for block references 8,12,0,12,8? Assume an initially empty cache and conventional block-number modulo number-of-sets mapping.
Options:
(A) 2
(B) 3
(C) 4
(D) 5
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Four blocks in a two-way cache means two sets. With the standard block-number modulo 2 mapping,8,12,0 all map to the same set.

2. Starting empty:8 miss gives[8];12 miss gives[8,12];0 miss evicts least-recent 8, giving[12,0];12 hits and becomes MRU;8 misses and evicts 0. Thus four misses.

3. The unused other set cannot absorb these conflicting blocks. An initially empty cache and conventional set indexing are assumed.

4. Teaching check: Only two ways are available in the even-numbered set despite four blocks existing overall. The access to 12 after inserting 0 is a hit and changes recency. That change determines which entry is evicted on the final 8 reference, although the miss count remains four.

Original paper, page 9