Question

Consider a set-associative cache of size 2KB (1 KB=210 bytes1\text{ KB} = 2^{10}\text{ bytes}) with cache block size of 64 bytes. Assume that the cache is byte-addressable and a 32-bit address is used for accessing the cache. If the width of the tag field is 22 bits, the associativity of the cache is ______.

Official answer and solution
Official answer
2
From
Official GATE 2021 answer key

Solution

Use the memory address format breakdown into Tag, Set Index, and Block Offset fields.

Given parameters:

  • Memory address width = 32 bits
  • Cache block size = 64 bytes =26= 2^6 bytes
  • Cache capacity = 2 KB =2048= 2048 bytes
  • Tag width = 22 bits

Calculate the field bit widths:

Block offset=log⁡2(64)=6 bits\text{Block offset} = \log_2(64) = 6 \text{ bits}
Set index bits=Address width−(Tag bits+Offset bits)=32−(22+6)=4 bits\text{Set index bits} = \text{Address width} - (\text{Tag bits} + \text{Offset bits}) = 32 - (22 + 6) = 4 \text{ bits}

The number of sets in the cache is:

Number of sets=24=16\text{Number of sets} = 2^4 = 16

The total number of cache lines (blocks) in the cache is:

Total lines=Cache sizeBlock size=2048 bytes64 bytes=32 lines\text{Total lines} = \frac{\text{Cache size}}{\text{Block size}} = \frac{2048 \text{ bytes}}{64 \text{ bytes}} = 32 \text{ lines}

The associativity kk (number of lines per set) is:

k=Total linesNumber of sets=3216=2k = \frac{\text{Total lines}}{\text{Number of sets}} = \frac{32}{16} = 2
Final answer

2

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2021 Computer Science and Information Technology - Session 2 (CS2)
Question
29 of 65, printed as CS Q.19
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.