標籤:cpu 緩衝 演算法
參考:algorithm LRU, how many bits needed for implement this algorithm?
問題:在cpu緩衝中使用的LRU替換演算法需要多少位呢?
解決方案:
對於n路相連的緩衝來說,LRU每個緩衝塊需要的位元為log2(n),那麼每個set需要的位元就為n*log2(n)。
(原文:Assuming you mean a 4-way set-associative cache:
A “perfect” LRU would essentially be assigning each line an exact index in the order of usage. You can also think of that as an “age”. So each of the 4 elements would require an index of 2 bits (since we need to count 4 distinct ages) stating its location in the LRU order - this means 2 bits * 4 ways, per each set of the cache.
In the general case of n ways, you’d need log2(n) bits per line, or n*log2(n) bits per set.
By the way, there are cheaper ways to reach an almost-LRU behavior, see for e.g. Pseudo LRU which would only require 3 bits for the entire set in your case (or in general: #ways - 1))
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
cpu cache中LRU演算法所需要的位元