reference:algorithm LRU, how many bits needed for implement this algorithm?
question: How many bits does it take to use the LRU replacement algorithm in the CPU cache?
Workaround:
For n-channel-connected caches, the number of bits required per cache block for LRU is log2 (n), so the number of bits required per set is N*LOG2 (n).
(Original: Assuming you mean a 4-way set-associative cache:
A "Perfect" LRU would essentially is assigning each line an exact index in the order of usage. You can also think of this as an ' age '. So each of the 4 elements would require a index of 2 bits (since we need to count 4 distinct ages) stating it location I n 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 the-by, there is cheaper ways to reach a almost-lru behavior, see for e.g. Pseudo LRU which would only require 3 bit s for the entire set in your case (or in general: #ways-1))
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The number of bits required by the LRU algorithm in the CPU cache