Prefetching
Prefetching is a technique used in computing to improve performance by retrieving data or instructions before they are needed. By predicting what a program will request in the future, the system can load information in advance to reduced wait times .[1]
Prefetching is used in various areas of computing, including CPU architectures and operating systems. It can be implemented in both hardware and software, and it relies on detecting access patterns that suggest what data is likely to be needed soon.
Overview
[edit]Prefetching works by predicting which memory addresses or resources will be accessing and load them into faster access storage, like caches.[1]
Prefetching may be used:
- Hardware-level, such as CPU memory controllers
- Software-level, strategies in compilers, operating systems, logic in web browsers or file systems
Hardware
[edit]Processors (CPU's) often include prefetching that attempts to reduce cache misses by loading data into cache before it is requested by the running program. This is for programs that access memory in predictable patterns, such as loops that iterate over arrays.[1]
Hardware prefetching is can be done without software involvement and can be found in most modern CPU's. For example, Intel CPU's feature a variety of prefetch that work across multiple cache levels.[1]
- Stride prefetching detects constant-stride memory access patterns (fixed distance between consecutive memory accesses)[2]
- Stream prefetching identifies long sequences of contiguous memory accesses (sequential access to a block of memory)[2]
- Correlation prefetching learns patterns between cache misses and triggers prefetches based on those patterns[2]
Software
[edit]Prefetch instructions can be written into the code by the programmer or by the compiler. Prefetch instructions specify the memory addresses to be prefetched and the desired prefetch distance.[2]
In software, there are instructions that can be written with:
prefetch
on x86 architecture__builtin_prefetch
in the GCC compiler_mm_prefetch
in the Intel Intrinsics Guide
Operating systems
[edit]Operating systems use prefetching to reduce file and memory access latency.
- Anticipatory Paging, attempts to prefetch memory pages based on pages in RAM and not in RAM
Web Browsers
[edit]Web browsers apply prefetching techniques to improve perceived performance. Common examples include:
- DNS prefetching: resolves domain names of links likely to be clicked[3]
- Link prefetching: loads linked web pages or assets before the user clicks them[4]
- Resource preloading: fetches critical resources (like fonts or scripts) in parallel with the current page load[5]
Limitations
[edit]Prefetching can significantly improve performance, but it can not always be beneficial if implemented wrong. If predictions are inaccurate, prefetching may waste bandwidth, processing time, or cause cache pollution. In systems with limited resources or highly unpredictable workloads, prefetching can degrade performance rather than improve it.[1]
Implementing both software and hardware prefetching can also lead to degraded performance because of interactions that might occur between each other from how it was implemented.[6]
See Also
[edit]References
[edit]- ^ a b c d e "Intel® 64 and IA-32 Architectures Optimization Reference Manual Volume 1". Intel. 2023-09-05. Retrieved 2025-04-24.
- ^ a b c d Hur, Ibrahim; Lin, Calvin (February 2009). "Feedback mechanisms for improving probabilistic memory prefetching". 2009 IEEE 15th International Symposium on High Performance Computer Architecture. IEEE: 443–454. doi:10.1109/hpca.2009.4798282.
- ^ "Using dns-prefetch - Web performance | MDN". developer.mozilla.org. 2025-04-10. Retrieved 2025-04-24.
- ^ "rel=prefetch - HTML: HyperText Markup Language | MDN". developer.mozilla.org. 2025-04-10. Retrieved 2025-04-24.
- ^ "rel=preload - HTML: HyperText Markup Language | MDN". developer.mozilla.org. 2025-04-10. Retrieved 2025-04-24.
- ^ Lee, Jaekyu; Kim, Hyesoon; Vuduc, Richard (2012-03-01). "When Prefetching Works, When It Doesn't, and Why". ACM Trans. Archit. Code Optim. 9 (1): 2:1–2:29. doi:10.1145/2133382.2133384. ISSN 1544-3566.