Abstract
设计并实现了一种按需预取算法,采用更为宽松的顺序性判决条件,并以页面和页面缓存的状态作为可靠的决策依据.它可以发现淹没在随机读中的顺序访问并进行有效的预读,支持对单个文件实例的并发访问而产生的交织访问模式.实验结果表明:相对于原Linux预读算法,该算法在随机干扰下的顺序读性能可提高29%;交织读的性能是传统算法的4~27倍;同时,应用程序可见延迟改善可达35倍.该算法已被Linux 2.6.24内核采用.;This paper proposes and implements a demand prefetching algorithm, which uses relaxed sequentiality criteria as well as page and page cache states as reliable sources of information. It can discover and prefetch sequential streams mixed in random accesses. It can also support the interleaved access patterns created by concurrent sequential reads on one file descriptor. Experimental results show that it performs much better than legacy Linux readahead: sequential reading intermixed with random ones are faster by 29%; I/O throughput of interleaved streams could be 4~27 times better, with application visible I/O latencies improved by up to 35 times. This demand prefetching algorithm has been adopted by Linux kernel 2.6.24.
Introduction
As the performance gap between CPU/RAM and mechanical hard drives widened, disk I/O became a massive bottleneck. Operating systems use "readahead" (prefetching) to guess what data an application will need next and load it into memory before it's requested. The core motivation is that disks are significantly better utilized with larger I/O sizes, as shown in Figure 1.
However, traditional Linux readahead algorithms were fragile. They relied on "strict sequentiality"—if an application performed a few random reads or if multiple threads read from the same file descriptor (interleaving their requests), the algorithm would get confused, stop prefetching, and performance would crater. The authors sought to create a "greedy" yet intelligent algorithm that could identify sequential patterns even when they are buried under random access noise or interleaved with other streams.
Methods
The authors proposed several key architectural changes to the Linux readahead framework:
- Relaxed Sequentiality: Instead of requiring every byte to be requested in order, the algorithm looks for general forward progress. It uses a "demand-driven" approach where prefetching is triggered by specific events like cache misses or hitting a specially marked page.
- The
PG_readaheadFlag: A novel "marker" is placed on a page within the current prefetch window. When the application eventually reads this page, it acts as a signal to the kernel to asynchronously trigger the next batch of prefetching, ensuring the pipeline stays full without blocking the application. - State Recovery via Page Cache: Traditional algorithms stored prefetch state in a small data structure. If multiple threads interleaved their reads, they would constantly overwrite this state. The new algorithm treats the page cache as the "source of truth." If the internal state is lost, the kernel can scan the existing cached pages to reconstruct where the prefetch window should be.
- Decoupled Windows: The algorithm separates the "prefetch size" (how much to read) from the "ahead window" (how far in advance to trigger the read), allowing for more flexible tuning based on system load.
The implementation uses the file_ra_state structure to track these parameters efficiently, as shown in Figure 2.
Experimental Evaluation
The researchers evaluated the algorithm using controlled benchmarks on an Intel Core 2 system with a 160GB SATA drive. They focused on three primary scenarios:
- Standard Sequential: Using the
cpcommand for baseline performance. - Interleaved Streams: Simulating up to 10 threads reading from the same file descriptor.
- Disturbed Sequential Access: A sequential read stream "polluted" with random seeks to test robustness.
Key Insights and Results
The transition from a conservative to a "greedy" prefetching strategy proved highly effective for modern hardware where bandwidth is relatively abundant compared to seek latency. By using the cache as metadata, the algorithm naturally handles concurrency.
The experimental results were dramatic:
- Mixed/Noisy Reads: Performance improved by 29% when sequential reads were interrupted by random seeks.
- Interleaved Throughput: For concurrent streams, the new algorithm was 4 to 27 times faster than the legacy Linux readahead.
- Latency: Application-visible I/O latency was reduced by up to 35 times in highly interleaved scenarios.
Due to these improvements, the algorithm was merged into Linux kernel 2.6.24.
Conclusion
While highly effective for mechanical disks, the rise of Solid State Drives (SSDs) may eventually require different heuristics. Future work could involve adaptive prefetching that adjusts greediness based on real-time memory pressure.
Summary updated