4 ms·
CPU cache misconceptions, and the MESI cache coherence protocol
- Dayshine 8y agoPoor title, it's a short introduction to MESI.
- gpderetta 8y agoThe title is correct, the cache-flushing myth is very widespread and the article tries to dispell it.
- RootKitBeerCat 8y agoPoor reading comprehension on my part; I thought “Myth: The Fallen Lords” game programmers were going to share their beliefs about CPU caches.
- opencl 8y agoA lot of these 'misconceptions' are absolutely true though, for certain architectures. Every architecture has a specific set of guarantees about memory ordering and the coherence protocol used is an implementation detail relevant only to performance. The article is about x86 but i.e. ARM has much weaker guarantees about memory ordering. Relying on the behavior of a specific architecture here is not a good idea. This Linux document about memory barriers[1] repeatedly calls out problems specific to the Alpha architecture because of its extremely weak memory ordering guarantees. Though also in principle if you're not writing in assembly and your compiler is not buggy it is the programming language memory model that matters rather than the hardware model. The CPU's memory ordering guarantees don't matter if your compiler reorders memory accesses anyway to "optimize" your code. Modern C/C++ compilers WILL do this if you don't use explicit synchronization because the C/C++ model has very weak ordering guarantees that are basically similar to Alpha. [1] https://www.kernel.org/doc/Documentation/memory-barriers.txt https://www.kernel.org/doc/Documentation/memory-barriers.txt
- tntn 8y agoCache coherency is not the same as memory consistency models. This article is talking about cache coherence, and you are talking about memory consistency. As an example, both ARM and x86 have coherent caches, but neither guarantees sequential consistency. x86 guarantees (something similar to) TSO, and ARM is way more relaxed than that.
- opencl 8y agoThe article is confusing because it is talking about cache coherency but keeps calling it consistency. "The most common protocol that’s used to enforce consistency amongst caches, is known as the MESI protocol." When MESI is a coherence protocol.
- koverstreet 8y agoyeah, it seems like a really weird article. And the main misconception he lists is one of those "true but completely irrelevant" things - it doesn't matter if different processes can read different values from the same memory location at the same time, what matters is that for a variety of reasons you can't define what "the same time" is in a useful way, and defining the order events happen in becomes really important.
- gpderetta 8y agoThe last mainstream architecture (edit: [1]) that wasn't fully cache coherent was Alpha and hasn't been relevant for at least 15 years. And even Alpha was almost always cache coherent except for some weird corner cases requiring a barrier even in the load-dependent case. What the article has been trying, and apparently failing, to explain is that cache coherency has nothing to do with memory ordering. [1] Mainstream CPUs that is, GPUs are still not fully coherent AFAIK.
- modells 8y agoOld ARM had software-maintained TAG RAM (CAM? state of cache lines), ICache and DCache.
- 8y ago
- modells 8y agoNot the whole story in the real world for x86_64 architecture, there are other states like Owned and Forward. IIRC, modern ARM uses AXI4 and ACE for CC. https://en.wikipedia.org/wiki/MOESI_protocol https://en.wikipedia.org/wiki/MOESI_protocol https://en.wikipedia.org/wiki/MESIF_protocol https://en.wikipedia.org/wiki/MESIF_protocol
- jplayer01 8y agoUh, he mentions that some details such as additional states might differ depending on the CPU/architecture. He isn’t trying to write a comprehensive reference for everything you’ll see in the wild.