Read-Ahead and Free-Behind

Read-ahead 與 free-behind 是針對 sequential I/O 的 cache policy:向前預取、向後丟棄。


Read-Ahead

Application 要求 page/block i 時,OS 同時預先讀後面的資料。

request i → read i, i+1, i+2, next pages

若 access 真的是 sequential,下次 read 可 cache hit;HDD 上也能把小 I/O 合併成較大連續 transfer。


Free-Behind

Process 讀到 i+1 後,OS 降低 i 的 cache priority 或直接 eviction。

read i+1 → page i unlikely to be reused → free behind

適合 streaming、backup、log scan,避免 sequential scan 洗掉其他 working set。


Tradeoff

  • Read-ahead 太小:藏不住 latency;太大:猜錯會浪費 bandwidth/cache。
  • Free-behind 太積極:若 application backward seek / reread,會增加 miss。

現代 OS 會動態偵測 sequential pattern 與 cache pressure,調整 window 與 eviction 強度。