We are independent & ad-supported. We may earn a commission for purchases made through our links.
Advertiser Disclosure
Our website is an independent, advertising-supported platform. We provide our content free of charge to our readers, and to keep it that way, we rely on revenue generated through advertisements and affiliate partnerships. This means that when you click on certain links on our site and make a purchase, we may earn a commission. Learn more.
How We Make Money
We sustain our operations through affiliate commissions and advertising. If you click on an affiliate link and make a purchase, we may receive a commission from the merchant at no additional cost to you. We also display advertisements on our website, which help generate revenue to support our work and keep our content free for readers. Our editorial team operates independently of our advertising and affiliate partnerships to ensure that our content remains unbiased and focused on providing you with the best information and recommendations based on thorough research and honest evaluations. To remain transparent, we’ve provided a list of our current affiliate partners here.
Hardware

Our Promise to you

Founded in 2002, our company has been a trusted resource for readers seeking informative and engaging content. Our dedication to quality remains unwavering—and will never change. We follow a strict editorial policy, ensuring that our content is authored by highly qualified professionals and edited by subject matter experts. This guarantees that everything we publish is objective, accurate, and trustworthy.

Over the years, we've refined our approach to cover a wide range of topics, providing readers with reliable and practical advice to enhance their knowledge and skills. That's why millions of readers turn to us each year. Join us in celebrating the joy of learning, guided by standards you can trust.

What Is False Sharing?

By Eugene P.
Updated: May 16, 2024
Views: 8,888
Share

False sharing is a situation that can occur in a computer program when two applications that are running simultaneously attempt to access information in the same logical memory region that each program or process has stored in its own cache. The data in each application’s cache are copied from a common source, so modifying one cache causes the other to have to be reloaded from the source. The false aspect of the sharing arises when the changes made to the cache line by one program do not actually affect the data that the second program is using, in which case forcing the cache to be reloaded is a waste of system resources and can negatively affect the performance of the program. The problem of false sharing is hard to detect, because it is not a direct result of any code contained within the applications, although there are effective ways to prevent false sharing, such as moving data that are in a currently cached line to a separate line.

One of the primary reasons why false sharing can occur is found in how an operating system or hardware handles reading and writing data. When information from a hard disk or other source is being read or written by a program, it usually is loaded into a temporary cache so it can be accessed quickly. The amount of information that is cached from the source location is called a cache line and is a logical block of memory that normally can be between 2 bytes and 256 bytes in length. Under some operating systems or system architectures, programs are able to run at the same time, such as in parallel processing. This means it is possible for two separate programs to attempt to access information in the same cache line, so each program will have its own copy of the source data, potentially causing changes in one cache not to be reflected in the other cache, invalidating the data it holds.

There are a number of mechanisms employed to handle the situation when two programs attempt to access the same cache line, but the result most often is that one program is forced to reload its cache with the updated information the other program has modified. This type of incident is known as false sharing when the data within the cache line that each program is accessing are not related, so forcing one program to reload the cache is a waste of processing power and other resources. This most often is a problem for a program that will never modify the information in its cache, so there is no risk of the application overwriting changes the other process has made.

Two prevalent ways exist either to prevent or mitigate the effects of false sharing. The first is to add blank information before or after the data in memory, essentially forcing it into a separate cache line that is not being accessed by another program. The second method is to restrict the frequency of reading and writing to the cache line so it is reloaded as little as possible. More complex solutions involve cache-level management or even changes to how an operating system handles sharing.

Share
EasyTechJunkie is dedicated to providing accurate and trustworthy information. We carefully select reputable sources and employ a rigorous fact-checking process to maintain the highest standards. To learn more about our commitment to accuracy, read our editorial process.
Discussion Comments
Share
https://www.easytechjunkie.com/what-is-false-sharing.htm
Copy this link
EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.

EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.