False sharing
In computer science, false sharing is a performance-degrading usage pattern that can arise in systems with distributed, coherent caches at the size of the smallest resource block managed by the caching mechanism. When a system participant attempts to periodically access data that is not being altered by another party, but that data shares a cache block with data that is being altered, the caching protocol may force the first participant to reload the whole cache block despite a lack of logical necessity. The caching system is unaware of activity within this block and forces the first participant to bear the caching system overhead required by true shared access of a resource.
In computer science, false sharing is a performance-degrading usage pattern that can arise in systems with distributed, coherent caches at the size of the smallest resource block managed by the caching mechanism. When a system participant attempts to periodically access data that is not being altered by another party, but that data shares a cache block with data that is being altered, the caching protocol may force the first participant to reload the whole cache block despite a lack of logical necessity. The caching system is unaware of activity within this block and forces the first participant to bear the caching system overhead required by true shared access of a resource. ==Multiprocessor CPU caches== By far the most common usage of this term is in modern multiprocessor CPU caches, where memory is cached in lines of some small power of two word size (e.g., 64 aligned, contiguous bytes). If two processors operate on independent data in the same memory address region storable in a single line, the cache coherency mechanisms in the system may force the whole line across the bus or interconnect with every data write, forcing memory stalls in addition to wasting system bandwidth. In some cases, the elimination of false sharing can result in order-of-magnitude performance improvements. False sharing is an inherent artifact of automatically synchronized cache protocols and can also exist in environments such as distributed file systems or databases, but current prevalence is limited to RAM caches. ==Example== include include include include include include int main() { std::vector threads; const int hc = std::jthread::hardware_concurrency(); constexpr int testLimit = 256; // for simplicity up most that many elements for (int nThreads = 1; nThreads ( std::chrono::high_resolution_clock::now() - start ).count(); }, t); } threads.clear(); // join all threads std::cout (nsSum / (1.0e6 * nThreads)) This code shows the effect of false sharing. It creates an increasing number of threads from one thread to the number of physical threads in the system. Each thread sequentially increments one byte specific for that thread (i.e. not shared between them). The higher the level of contention between threads, the longer each increment takes, despite the fact that each thread is only incrementing its own piece of the global data. These are the results on an Intel Core i7 12th generation system with 6 performance and 8 efficiency cores yielding 20 threads: As one can see, concurrent access by those threads requires about 50 times more computing time than with mitigation where it approximately doubles. ==Mitigation== There are ways of mitigating the effects of false sharing. For instance, false sharing in CPU caches can be prevented by reordering variables or adding padding (unused bytes) between variables. However, some of these program changes may increase the size of the objects, leading to higher memory use. Compile-time data transformations can also mitigate false-sharing. However, some of these transformations may not always be allowed. For instance, the C++ programming language standard draft of C++23 mandates that data members must be laid out so that later members have higher addresses. There are tools for detecting false sharing. There are also systems that both detect and repair false sharing in executing programs. However, these systems incur some execution overhead. ==References== ==External links== Easy Understanding on False Sharing C++ today blog, False Sharing hits again! Dr Dobbs article: Eliminate False Sharing Be careful when trying to eliminate false sharing in Java
References
- Working Draft, Standard for Programming Language C++ [class] · retrieved 2021-07-10 · rev 1377079722
Cite this reference
MLA "Working Draft, Standard for Programming Language C++ [class]." 2021-07-10. https://eel.is/c++draft/class. Accessed 24 November 2026.
Chicago "Working Draft, Standard for Programming Language C++ [class]." 2021-07-10. https://eel.is/c++draft/class.
APA encyclopegia.org. (2021). Working Draft, Standard for Programming Language C++ [class]. Retrieved November 24, 2026, from https://eel.is/c++draft/class
- perf-c2c(1) · retrieved 2021-08-07 · rev 1377079722
Cite this reference
MLA "perf-c2c(1)." 2021-08-07. https://man7.org/linux/man-pages/man1/perf-c2c.1.html. Accessed 24 November 2026.
Chicago "perf-c2c(1)." 2021-08-07. https://man7.org/linux/man-pages/man1/perf-c2c.1.html.
APA encyclopegia.org. (2021). perf-c2c(1). Retrieved November 24, 2026, from https://man7.org/linux/man-pages/man1/perf-c2c.1.html
- Featherlight on-the-fly false-sharing detection · retrieved 2026-11-17 · rev 1377079722
Cite this reference
MLA "Featherlight on-the-fly false-sharing detection." Chabbi, Milind; Wen, Shasha; Liu, Xu (2018-02-10). 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier). Accessed 24 November 2026.
Chicago "Featherlight on-the-fly false-sharing detection." Chabbi, Milind; Wen, Shasha; Liu, Xu (2018-02-10). 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier).
APA Chabbi, Milind; Wen, Shasha; Liu, Xu (2018-02-10). (2026). Featherlight on-the-fly false-sharing detection. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Doi_(identifier)
- Whose cache line is it anyway? · retrieved 2026-11-17 · rev 1377079722
Cite this reference
MLA "Whose cache line is it anyway?." Nanavati, Mihir; Spear, Mark; Taylor, Nathan; Rajagopalan, Shriram; Meyer, Dutch T. 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier). Accessed 24 November 2026.
Chicago "Whose cache line is it anyway?." Nanavati, Mihir; Spear, Mark; Taylor, Nathan; Rajagopalan, Shriram; Meyer, Dutch T. 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier).
APA Nanavati, Mihir; Spear, Mark; Taylor, Nathan; Rajagopalan, Shriram; Meyer, Dutch T. (2026). Whose cache line is it anyway?. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Doi_(identifier)
- SHERIFF: precise detection and automatic mitigation of false sharing · retrieved 2026-11-17 · rev 1377079722
Cite this reference
MLA "SHERIFF: precise detection and automatic mitigation of false sharing." Liu, Tongping; Berger, Emery D. 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier). Accessed 24 November 2026.
Chicago "SHERIFF: precise detection and automatic mitigation of false sharing." Liu, Tongping; Berger, Emery D. 2026-11-17. https://en.wikipedia.org/wiki/Doi_(identifier).
APA Liu, Tongping; Berger, Emery D. (2026). SHERIFF: precise detection and automatic mitigation of false sharing. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/Doi_(identifier)
- False sharing and its effect on shared memory performance · retrieved 2026-11-17 · rev 1377079722
Cite this reference
MLA "False sharing and its effect on shared memory performance." a b Bolosky, William J. 2026-11-17. https://www.usenix.org/legacy/publications/library/proceedings/sedms4/full_papers/bolosky.txt. Accessed 24 November 2026.
Chicago "False sharing and its effect on shared memory performance." a b Bolosky, William J. 2026-11-17. https://www.usenix.org/legacy/publications/library/proceedings/sedms4/full_papers/bolosky.txt.
APA a b Bolosky, William J. (2026). False sharing and its effect on shared memory performance. Retrieved November 24, 2026, from https://www.usenix.org/legacy/publications/library/proceedings/sedms4/full_papers/bolosky.txt
- Reducing false sharing on shared memory multiprocessors through compile time data transformations · retrieved 2026-11-17 · rev 1377079722
Cite this reference
MLA "Reducing false sharing on shared memory multiprocessors through compile time data transformations." Jeremiassen, Tor E. 2026-11-17. https://doi.org/10.1145%2F209937.209955. Accessed 24 November 2026.
Chicago "Reducing false sharing on shared memory multiprocessors through compile time data transformations." Jeremiassen, Tor E. 2026-11-17. https://doi.org/10.1145%2F209937.209955.
APA Jeremiassen, Tor E. (2026). Reducing false sharing on shared memory multiprocessors through compile time data transformations. Retrieved November 24, 2026, from https://doi.org/10.1145%2F209937.209955
- Patterson, David (2012). Computer organization and design: the hardware/software interface . Waltham, MA: Morgan Kaufmann. p. 537. ISBN 978-0-12-374750-1 . OCLC 746618653 . Wikipedia revision 1377079722, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1377079722
Cite this reference
MLA "Patterson, David (2012). Computer organization and design: the hardware/software interface . Waltham, MA: Morgan Kaufmann. p. 537. ISBN 978-0-12-374750-1 . OCLC 746618653 . Wikipedia revision 1377079722, retrieved 2026-11-18." Patterson, David (2012). 2026-11-17. https://en.wikipedia.org/wiki/ISBN_(identifier). Accessed 24 November 2026.
Chicago "Patterson, David (2012). Computer organization and design: the hardware/software interface . Waltham, MA: Morgan Kaufmann. p. 537. ISBN 978-0-12-374750-1 . OCLC 746618653 . Wikipedia revision 1377079722, retrieved 2026-11-18." Patterson, David (2012). 2026-11-17. https://en.wikipedia.org/wiki/ISBN_(identifier).
APA Patterson, David (2012). (2026). Patterson, David (2012). Computer organization and design: the hardware/software interface . Waltham, MA: Morgan Kaufmann. p. 537. ISBN 978-0-12-374750-1 . OCLC 746618653 . Wikipedia revision 1377079722, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/wiki/ISBN_(identifier)
Cite this article
MLA
"False sharing." encyclopegia.org, 2026, https://encyclopegia.org/wiki/false-sharing. Accessed 24 November 2026.
Chicago
"False sharing." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/false-sharing.
APA
encyclopegia.org. (2026). False sharing. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/false-sharing
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON