(For a detailed description see Cache coherency protocols (examples))
In computing, MOESI ("Modified Owned Exclusive Shared Invalid") is a full cache coherency protocol that encompasses all of the possible states commonly used in other protocols. In addition to the four common MESI protocol states, there is a fifth "Owned" state representing data that is both modified and shared. This avoids the need to write modified data back to main memory before sharing it. While the data must still be written back eventually, the write-back may be deferred .
In order for this to be possible, direct cache-to-cache transfers of data must be possible, so a cache with the data in the modified state can supply that data to another reader without transferring it to memory.
As discussed in AMD64 Architecture Programmer's Manual Vol. 2 'System Programming',[1] each cache line is in one of five states:
For any given pair of caches, the permitted states of a given cache line are as follows:
M | O | E | S | I | |
---|---|---|---|---|---|
M | |||||
O | |||||
E | |||||
S | |||||
I |
(The order in which the states are normally listed serves only to make the acronym "MOESI" pronounceable.)
This protocol, a more elaborate version of the simpler MESI protocol, avoids the need to write a dirty cache line back to main memory when another processor tries to read it. Instead, the Owned state allows a processor to supply the modified data directly to the other processor. This is beneficial when the communication between two CPUs is significantly better than to main memory. An example would be multi-core CPUs with per-core L2 caches.
While MOESI can quickly share dirty cache lines from cache, it may struggle to quickly share clean lines from cache. If a cache line is clean with respect to memory and in the shared state, then there is no obvious single candidate cache to respond to a read request, so it is normal to let the read request be filled from memory. (This is solved by the MESIF protocol, which may be combined with MOESI to make MOESIF.)
If a processor wishes to write to an Owned cache line, it must notify the other processors which are sharing that cache line. The standard implementation simply tells them to invalidate their copies, moving its own copy to the Modified state when this is complete, but alternatively it may use a write-through policy, telling them to update their copies with the new contents. This is a partial write-through which does not go as far as main memory; the processor's own copy remains in the Owned state.
The latter reduces cache traffic if there are multiple active readers of e.g. a heavily contended lock; one broadcast write is less communication than separate replies to a thundering herd of read requests. Because these two variants are fully compatible, they may both be used in the same system based on heuristics like the cache's estimate of the number of active readers of this cache line.