Definition
Cache coherence is a concept used in systems with multiple processors and shared memory to ensure uniformity in the data stored across different local caches. Since each processor has distinct cache memory, different copies of the same memory block may be available on different caches, creating inconsistent data.
So, if one copy stored in one processor is updated or changed, all other copies must be updated or changed to avoid inconsistency. Cache coherence ensures all processors have a consistent memory view by updating each cache with any changes made to one copy on time.
Cache Coherence Protocols in a Multiprocessor System
- MOESI (Modified, Owned, Exclusive, Shared, Invalid)
- MESI (Modified, Exclusive, Shared, Invalid)
- MOSI (Modified, Owned, Shared, Invalid)
- MSI (Modified, Shared, Invalid)
Let’s discuss the above terms:
- Modified: It means the value in the cache is inconsistent with the value in the main memory.
- Exclusive: It means the value in the cache is the same as in the main memory.
- Shared: Shared means that a cache holds the latest data copy, which is what is in all other caches.
- Owned: It means the current cache holds an entire block and has all the rights on that block.
- Invalid: Invalid means the current cache has an invalid copy and must fetch the latest copy from another cache or the main memory.
Cache Coherence Mechanisms
- Snarfing: This mechanism involves one cache controller to monitor all cache memory locations and manage the data stored there.
- Snooping: In this approach, each cache monitors address lines of all transactions associated with processors to detect, update, or invalidate their copies accordingly.
- A directory-based system: This approach is used when shared data is stored in the same directory. When data changes, the directory updates or invalidates the caches of different processors.