What is Cache coherence?
[[Image:Cache Coherency Generic.png|thumb|right|400px| Multiple Caches of Shared Resource]] A [[cache]] can be used to improve the performance of accessing a given resource. When there are several such caches for the same resource, as shown in the picture, this can lead to problems. '''Cache coherence''' or '''Cache coherency''' refers to a number of ways to make sure all the caches of the resource have the same data, and that the data in the caches makes sense (called ''data integrity''). Cache coherence is a special case of [[memory coherence]]. There may be problems if there are many caches of a common memory resource, as data in the cache may no longer make sense, or one cache may no longer have the same data as the others. A common case where the problem occurs is the cache of [[CPU]]s in a [[multiprocessing]] system. As can be seen in the figure, if the top client has a copy of a memory block from a previous read and the bottom client changes that memory block, the top client could be left with an invalid cache of memory, without knowing. Cache coherence is there to manage such conflicts and maintain consistency between cache and memory. ==Definition== Coherence defines the behavior of reads and writes to the same memory location. The caches are coherent, if all of the following conditions are met: #When a processor P reads a location X, after writing to that location, P must get the value it wrote, if no other processor wrote another value to that location. This is also true for monoprocessor systems, it means that the memory is able to keep a value written. #Suppose there are two processors, P<sub>1</sub> and P<sub>2</sub>, and P<sub>1</sub> wrote a value X<sub>1</sub>, and afterwards, P<sub>2</sub> wrote a value X<sub>2</sub>, if P<sub>1</sub> reads the value, it must get the value written by P<sub>2</sub>, X<sub>2</sub>, and not the value it wrote, X<sub>1</sub>, if there are no other writes between the two. This means that the view of memory is coherent. If processors can read the same old value af