On 5/25/2012 10:20 AM, EricP wrote:
> Paul A. Clayton wrote:
>> On May 25, 6:16 am,
v...@t.com wrote:
>>> Normally, there are several levels of caching in every memory
>>> architecture. Thereby, L1 is backed by L2. Suppose one item is the
>>> most used one. It is therefore kept in L1 and, therefore, very rarely
>>> requested from L2. It is a first candidate for eviction out of L2! The
>>> most used item is evicted first!
>>>
>>> Is it how the stuff works?
Others have responded accurately. I'll pile on, and explain in terms I
am familiar with:
I won't talk about exclusive caches.
I'll also skip past LRU versus pseudo-LRU versus clock replacement, as
EricP described, handwaving that clock is supposed to be an
approximation to LRU.
For an inclusive cache, a naive L1/L2 system with LRU might work as you
describe. However, this performs badly. Some systems "trickle through"
information to update the L2 LRU, providing messages from L1 to L2 that
help keep the L2 more accurate.
Some systems may backwards query on an eviction from the L2. They may
have to do a backwards invalidate anyway, if evicting data that may be
in the L1. The backwards query gives the L1 the chance to say "Hey,
don't replace that line - I'm using it."
The backwards query doesn't need to be done at replacement time. It can
be done in advance.
Often you want the L2 cache to know which lines are in the L1, or in
which L1 if there are multiple L1s per L2. To do this accurately the L1
needs to inform the L2 when a line is no longer in use. This can
sometimes be done with just a few extra bits piggybacking on other
transactions. EricP already mentioned "replace the least recently
replaced from L1" policy.
Some older systems had the CPU or some inner controller know the shape,
sets and ways, of the outer cache. This way, when a line missed in the
L1, it knew which was the appropriate line in L2 to evict. This comes
very close to having the cache controller maintain LRU for both the L1
and L2. But it requires a cache controller that manages both L1 and L2.
Works less well with multiple L1s per L2. And requires that the L1
cache controller know the shape of the L2, which can be hard for
organizations.
Finally, when you have NINE (Non Inclusive Non Exclusive) caches, or
accidentally inclusive, it doesn't matter so much if you evict a line
from the L2 that is currently in the L1. Such caches allow this - they
may allow the line in the L1 to continue to be used, even though not in
the L2. If the line is eventually evicted from the L1, it can be
(re)allocated in the L2 if necessary. Often, it is not necessary.