Memory Hierarchy
When each row of a 2D array is 4,096 bytes (a power of two), walking down a column can cause many misses even though the cache has spare capacity. Which countermeasure is effective?
- APadding each row so its size is not a power of two
- BChanging the element type to a different type of the same size
- CRelocating the whole array so it starts on a large power-of-two address boundary
Show answer and explanation
Answer: A. Padding each row so its size is not a power of two
With rows exactly 4,096 bytes long, elements down a column are spaced by multiples of 4,096, so their index bits are identical and they all map to the same set. Walking more rows than the associativity causes conflict misses even with capacity to spare. Padding each row by about one line shifts the set for each element and spreads them out. Aligning to a power of two leaves the problem intact, and a same-sized type changes nothing.
- A. Correct. Shifting the row size spreads elements across different sets.
- B. A type of the same size leaves the addresses unchanged.
- C. Aligning to a power of two leaves the concentration in one set.