3 ms·
msync() with MS_INVALIDATE doesn't belong on this list. It has nothing to do with atomic memory access. msync() is used when flushing a mapped file to durable s
by throwaway76543 10y ago
msync() with MS_INVALIDATE doesn't belong on this list. It has nothing to do with atomic memory access. msync() is used when flushing a mapped file to durable storage. I very often see this mistake of conflating flushing caches with atomic access of memory. What's committed to durable storage has nothing to do with what multiple processes will see when mapping a file.
All that's needed is the initial mmap to share a memory segment, then to use atomic operations like CMPXCHG -- the x86 building block the later mentioned gcc atomic macros leverage.
- prodigal_erik 10y agoI haven't tested but I would expect MS_INVALIDATE on a large buffer to be much faster than filling it a word at a time with __sync_val_compare_and_swap (each causing its own bus transaction).
- throwaway76543 10y agomsync() doesn't fill buffers at all. It has no function in the operation you've described. Even if it did, it's not atomic ...
- gpderetta 10y agoMS_INVALIDATE is likely a no-op on any modernish Unix, including Linux. It is there to accommodate old systems with non-coherent mapped files and page caches or even multiple mappings of the same file.
- gpderetta 10y agoRight. Msync is an ordering barrier. Barriers go hand in hand with atomic operations, but they are really about visibility, not atomicity.