文中作者言:cache 的替换策略就好比是一个二分类问题,他的目标是决定 line 是 cache-friendly 还是 cache-averse。cache-friendly 指的是一个 line 在插入时有一个高的优先级,而 cache-averse 指的是一个 line 被标记,该 line 在未来替换时会作为被替换的候选者。
文中提出了一种 Hawkeye 的策略,该策略重构了 Bélády's optimal solution 来学习 load 指令的行为。
1. OPT Replacement
Wiki百科的定义如下:
The theoretically optimal page replacement algorithm (also known as OPT, clairvoyant replacement algorithm, or Bélády's optimal page replacement policy) is an algorithm that works as follows: when a page needs to be swapped in, the operating system swaps out the page whose next use will occur farthest in the future. For example, a page that is not going to be used for the next 6 seconds will be swapped out over a page that is going to be used within the next 0.4 seconds.
This algorithm cannot be implemented in a general purpose operating system because it is impossible to compute reliably how long it will be before a page is going to be used, except when all software that will run on a system is either known beforehand and is amenable to static analysis of its memory reference patterns, or only a class of applications allowing run-time analysis. Despite this limitation, algorithms exist[citation needed] that can offer near-optimal performance — the operating system keeps track of all pages referenced by the program, and it uses those data to decide which pages to swap in and out on subsequent runs. This algorithm can offer near-optimal performance, but not on the first run of a program, and only if the program's memory reference pattern is relatively consistent each time it runs.
大致意思为: