Definition
False sharing is a performance-degrading phenomenon in shared-memory multiprocessor systems where multiple threads or processors repeatedly read and write distinct variables that reside on the same cache line. Although the variables are logically independent, the hardware cache-coherence protocol treats the entire cache line as a single unit, causing unnecessary invalidations and cache misses that reduce parallel efficiency.
Mechanism
- Cache line granularity – Modern CPUs cache memory in fixed-size blocks called cache lines (typically 64 bytes).
- Coherence enforcement – When a core modifies any byte of a cache line, the coherence protocol must invalidate or update that line in the caches of other cores that hold a copy.
- Independent variables – If two threads repeatedly write to different variables that happen to be placed within the same cache line, each write triggers the coherence actions even though the variables are unrelated.
- Resulting traffic – The repeated invalidations generate memory‑bus traffic and cause cache‑miss penalties, leading to slower execution despite the logical independence of the data.
Performance Impact
- Measurable slowdown in tightly looped parallel code (e.g., parallel reductions, counters, or per‑thread state) where variables are not deliberately aligned.
- Diminished scalability: adding more cores can increase contention rather than improve throughput.
- The effect is more pronounced on architectures with high latency for cache‑line transfers or on workloads with high write frequency.
Detection
- Profilers and performance analysis tools (e.g., Intel VTune, Linux
perf, LLVM‑based tools) can identify cache‑line sharing patterns by reporting high coherency traffic or “cache line bounce” statistics. - Hardware performance counters such as MEM_LOAD_UOPS_RETIRED.HITM (Hit Modified) on Intel CPUs provide quantitative evidence.
Mitigation Techniques
| Technique | Description |
|---|---|
| Padding / Alignment | Insert unused bytes (padding) or use compiler directives (alignas, __attribute__((aligned))) to ensure that variables accessed by different threads occupy separate cache lines. |
| Structure Re‑layout | Group frequently written fields together per thread and place them in distinct structures, reducing cross‑thread placement on the same line. |
| Thread‑local storage | Allocate per‑thread data in thread‑local storage (TLS) or using memory allocators that guarantee cache‑line separation. |
| Lock striping | Distribute lock variables across multiple cache lines to avoid a single lock line becoming a hotspot. |
| Software transactional memory / atomics | Use atomic operations that operate on larger granularity (e.g., 64‑bit atomics) only when necessary, avoiding frequent writes to adjacent non‑atomic variables. |
| Cache‑aware allocation libraries | Libraries such as jemalloc, tcmalloc, or Intel TBB’s scalable allocator provide options to align allocations to cache line boundaries. |
Best‑practice guidelines
- Identify shared mutable data early in the design of parallel algorithms.
- Align frequently updated per‑thread structures to the cache line size of the target architecture.
- Prefer read‑mostly sharing; writes are the primary driver of false sharing.
- Validate performance after applying mitigations using profiling tools rather than relying solely on code inspection.
Related Concepts
- Cache coherence – The protocol that maintains consistency of cached copies across cores.
- Cache line bounce – Informal term for the same phenomenon, emphasizing the repeated movement of a line between caches.
- True sharing – Situations where multiple threads intentionally access the same memory location, requiring synchronization.
- Memory contention – General competition for memory subsystem resources, of which false sharing is a specific cause.
References
- Intel® 64 and IA-32 Architectures Optimization Reference Manual, Section “Cache Line Sharing”.
- J. C. D. Aparicio, “Understanding and Mitigating False Sharing”, Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, 2019.
- G. Di Battista et al., “Cache‑Based Performance Analysis Tools”, IEEE Transactions on Computers, vol. 62, no. 6, 2013.
This entry reflects the current consensus in computer‑architecture and parallel‑programming literature as of the knowledge cutoff date.