This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Clean and Invalidate Cache Memory

Hi experts,

Wat is the key difference between clean and invalidate the cache memory ?

How it is related to eviction of data into the external memory ?

What happens if any one of the operations alone carried out ?

  • Invalidate simply marks a cache line as "invalid", meaning you won't hit upon.

    Clean causes the contents of the cache line to be written back to memory (or the next level of cache), but only if the cache line is "dirty".  That is, the cache line holds the latest copy of that memory.

    Clean & Invalidate, as the name suggests, does both.

    Dirty lines normally get back to memory through evictions.  When the line is selected to be evicted, there is a check to see if it's dirty.  If yes, it gets written back to memory.  Cleaning is way to force this to happen at a particular time.  For example, because something else is going to read the buffer.

    In theory, if you invalidated a dirty line you could loose data.  As an invalid line won't get written back to memory automatically through eviction.  In practice many cores will treat Invalidate as Clean&Invalidate - but you shouldn't rely on that.  If the line is potentially dirty, and you care about the data, you should use Clean&Invalidate rather than Invalidate.