# Cache 管理

AMAT = (P[Hit] * T[M]) + (P[Miss] * T[D])

# 最优替换策略

The optimal replacement policy leads to the fewest number of misses overall.

Belady showed that a simple (but, unfortunately, difﬁcult to implement!) approach that replaces the page that will be accessed furthest in the future is the optimal policy, resulting in the fewest-possible cache misses.

Belay 是这一策略的提出者。参见引用。

HitRate = (Hits) / (Hits + Misess) = 6 / (6 + 5) = 54.5%

# 根据历史而来的替换策略：LRU / LFU

LRU, Least-Recently-Used

LFU, Least-Frequently-Used

# 近似 LRU

clock 算法（参见引用论文《A Paging Experiment with the Multics System》）

# 考虑 Dirty Page

The reason for this: if a page has been modiﬁed and is thus dirty, it must be written back to disk to evict it, which is expensive. If it has not been modiﬁed (and is thus clean), the eviction is free; the physical frame can simply be reused for other purposes without additional I/O.

Thus, some VM systems prefer to evict clean pages over dirty pages.
To support this behavior, the hardware should include a modiﬁed bit (a.k.a. dirty bit). This bit is set any time a page is written, and thus can be incorporated into the page-replacement algorithm.