multithreadingcachingmultiprocessingcpu-cachemesi

MESI-protocol and the LRU-strategy


I have read quite some literature about the MESI-protocol and its application for keeping caches consistent but there are two details I can't quite figure out:

When using the MESI-protocol for keeping multiple caches synchronized and applying a LRU-strategy for the cache lines, are the lines kept in the cache only by read accesses or also by write accesses?

Also, am i seeing this right: a cache hit on a shared line in cache A will not bring up that line in the LRU-order of cache B?


Solution

  • If you're talking about a writeback type of cache, you need to make a distinction between the cache read/write operations and load/store as the CPU sees them. Both a load and a store would perform a read operation (where the store may use a slightly different flavor called read-for-ownership, which essentially guarantees the core gets the line exclusively and can mark is as M-state). The reason is that most stores do not cover the entire width of a cache line, and must therefore merge the part they overwrite into the latest valid copy of the data. On such systems, therefore, both loads and stores would amount for a read and allocate the line in the cache. Any such line allocated would update the LRU.

    A cache write operation is usually associated with a writeback from an upper level cache to a lower one. The LRU mechanism is orthogonal to cache coherency itself, and merely chooses which of the lines must be written back when space is required (usually for a read line that needs to be allocated).

    As for the second question - again, LRU and MESI are orthogonal. A cache lookup that snoops another cache and hits a line in shared state would either leave it there or invalidate it (depending on the type of access). If the line is left alone (for a simple read, which would then allocate the line in shared state in cache A as well), the line in cache B may be touched (its LRU updated) or not - depending on implementation. It doesn't affect coherency.