【linux内核】预读优化

 

 

前台消费位置 = consumed_head

|---- urgent 区 ----|------ tail 区 ------|
consumed_head      low_water            high_water

再结合当前已经有多少“有效前置页”:

effective_ahead_pages = cached_ahead_pages + inflight_credit

就会变成下面这种判断。

情况 1:前方缓存很少,连 low_water 都没到

consumed_head                    low_water            high_water
|--------------------------------|--------------------|
<------ urgent_pages -----------><--- tail_pages ---->

effective_ahead_pages

对应代码是:

  • urgent_pages = low_water - effective_ahead_pages
  • tail_pages = high_water - low_water

也就是:

  • urgent 是“保底库存缺口”
  • tail 是“扩展库存缺口”

情况 2:已经超过 low_water,但还没到 high_water

consumed_head                    low_water            high_water
|--------------------------------|--------------------|
                 effective_ahead_pages
                 <------ tail_pages ------>

这时:

  • urgent_pages = 0
  • tail_pages = high_water - effective_ahead_pages

意思是保底已经够了,只差“继续往前铺”。

情况 3:已经达到 high_water

consumed_head                    low_water            high_water
|--------------------------------|--------------------|
                                         effective_ahead_pages

这时:

  • urgent_pages = 0
  • tail_pages = 0

不需要再补。

posted @ 2026-04-13 21:19  苏格拉底的落泪  阅读(5)  评论(0)    收藏  举报