Memory Hierarchy
When inserting software prefetch instructions, which statement about how far ahead to fetch (the prefetch distance) is correct?
- AShorter is better; inserting it just before the next element is read is optimal
- BLonger is better; fetching all the data the loop will use at the very start is optimal
- CNeither too short nor too long; it is chosen from the miss latency and the time per iteration
Show answer and explanation
Answer: C. Neither too short nor too long; it is chosen from the miss latency and the time per iteration
A prefetch is useless unless the data arrives from memory before it is needed. If the distance is too short, the data arrives late; if too long, fetched data may be evicted before use or pollute the cache. A rule of thumb is to fetch ahead by the miss penalty divided by the time per loop iteration. Prefetching just before use cannot hide latency, and fetching everything up front does not fit in the cache.
- A. Just before use, the fetch cannot complete in time and latency is not hidden.
- B. Fetching everything first gets data evicted before it is used.
- C. Correct. Choose a distance that arrives in time yet is not evicted, from the miss latency and iteration time.