Skip to content

GATE CS 2007 Q81 — Memory Hierarchy: Cache, Main Memory and Secondary Storage

Explain with AI

Consider a machine with a byte addressable main memory of 2162^{16} bytes. Assume that a direct mapped data cache consisting of 3232 lines of 6464 bytes each is used in the system. A 5050 x 5050 two-dimensional array of bytes is stored in the main memory starting from memory location 1100H1100H. Assume that the data cache is initially empty. The complete array is accessed twice. Assume that the contents of the data cache do not change in between the two accesses. 

Which of the following lines of the data cache will be replaced by new blocks in accessing the array for the second time?

Choose one option
View worked solution

Answer: A

To determine which cache lines are replaced during the second access, we first identify the memory blocks occupied by the array.

1. Cache and Array Parameters:

  • Cache line size: 6464 bytes
  • Number of cache lines: 3232
  • Array starting address: 1100extH=1imes163+1imes162=43521100 ext{H} = 1 imes 16^3 + 1 imes 16^2 = 4352
  • Array size: 50imes50=250050 imes 50 = 2500 bytes
  • Array ending address: 4352+2500−1=68514352 + 2500 - 1 = 6851

2. Memory Blocks Occupied:

  • Starting Block: ⌊4352/64⌋=68\lfloor 4352 / 64 \rfloor = 68
  • Ending Block: ⌊6851/64⌋=107\lfloor 6851 / 64 \rfloor = 107

The array spans 4040 memory blocks, from Block 6868 to Block 107107.

3. Cache Mapping (L=B(mod32)L = B \pmod{32}):

  • Blocks 6868 to 9999 map to cache lines 44 to 3131, and then 00 to 33.
  • Blocks 100100 to 107107 map to cache lines 44 to 1111.

4. First Access Pass:

  • Blocks 6868 to 9999 are loaded into cache lines 44 to 3131 and 00 to 33.
  • Blocks 100100 to 107107 are then loaded, overwriting lines 44 to 1111.
  • At the end of the first pass, lines 44 to 1111 contain Blocks 100100 to 107107, while lines 1212 to 3131 and 00 to 33 contain Blocks 7676 to 9999.

5. Second Access Pass:

  • Accessing Blocks 6868 to 7575 (mapping to lines 44 to 1111) results in misses, replacing Blocks 100100 to 107107 with Blocks 6868 to 7575.
  • Accessing Blocks 7676 to 9999 results in cache hits.
  • Accessing Blocks 100100 to 107107 results in misses, replacing Blocks 6868 to 7575 with Blocks 100100 to 107107.

Thus, only line 4 to line 11 are replaced during the second pass.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Memory Hierarchy: Cache, Main Memory and Secondary Storage questions