What is Prefetching?
Loading data into the cache before it is requested because it is likely to be needed soon. Hardware prefetchers detect access patterns, and software prefetching uses explicit instructions.
Japanese name: プリフェッチ
Loading data into the cache before it is requested because it is likely to be needed soon. Hardware prefetchers detect access patterns, and software prefetching uses explicit instructions.
Japanese name: プリフェッチ
An L1 cache hit takes a few cycles, around 1 ns, while a DRAM access takes tens to about 100 ns, so a multi-GHz core can wait hundreds of cycles on a miss; this gap is called the memory wall. Compulsory misses, which occur the first time data is touched, are not reduced by more capacity or associativity because the data was never cached. Prefetching attacks this by requesting lines before the program needs them, overlapping memory latency with useful work. Larger cache lines help in a similar way by bringing in neighboring data with each miss.
A hardware prefetcher watches the stream of miss or access addresses and looks for regularity. The simplest fetches the next sequential line; stride prefetchers track the address difference between successive accesses, often per load instruction, and once a constant stride repeats they issue requests several strides ahead. Reading an int array sequentially with 64-byte lines would otherwise miss once per 16 elements, a 6.25% miss rate, and a good prefetcher hides most of those misses. Pointer chasing defeats this: in a linked list the next address is unknown until the current node arrives, so misses serialize.
Software prefetching inserts explicit prefetch instructions, either by hand or by the compiler, for patterns hardware cannot predict, such as indirect accesses through an index array. These instructions are hints that typically do not fault or change program results. The key parameter is prefetch distance: fetching too close to the use leaves latency exposed, while fetching too far ahead risks eviction before use. A common rule of thumb is to prefetch ahead by about the miss latency divided by the time per loop iteration, then tune by measurement.
Prefetching is not free. Useless prefetches consume memory bandwidth and can evict useful lines, a problem called cache pollution, which can make a program slower. Prefetchers are therefore judged on accuracy, the fraction of prefetched lines actually used; coverage, the fraction of original misses eliminated; and timeliness, whether data arrives before it is needed. Prefetching also differs from out-of-order execution, which overlaps misses only within its limited instruction window. When a data structure is hostile to prediction, reorganizing it into contiguous arrays often helps more than any prefetcher.
Answer: A. Reading an array in order at a fixed interval (stride)
A hardware prefetcher detects regularity in recent addresses, such as sequential or constant-stride patterns, predicts upcoming addresses and loads them ahead of time. Reading an array at a fixed stride is easy to predict, so the benefit is large. In a linked list the next element's address is unknown until the current one is read, so it is hard to predict from address patterns. Random-key hash lookups also lack address regularity, so prefetching helps little.
Hardware prefetchers detect patterns like sequential or constant-stride access automatically at run time. Software prefetching relies on explicit instructions placed by the programmer or compiler, which helps with irregular but computable addresses.
Each node's address is only known after the previous node has been loaded, so there is no predictable pattern and misses cannot overlap. Storing the data contiguously or adding jump pointers is usually needed.
Yes. Inaccurate or overly early prefetches waste bandwidth and evict data that was still needed, so aggressive prefetching can slow memory-bound programs.
Prefetching appears in 9 practice questions across 4 topics, including Memory Hierarchy, DRAM, CPUs and architecture.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.