Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does false sharing also occur when threads only write to the same cache block?

If we have two cores which read and write to different memory position in the same cache block, both cores are forced to reload that cache block again and again, although it is logically not necessary. This is what we call false sharing.

However, what if the cores never read from that cache block, but only write? Imagine the two cores just set some bits in the same cache block, but they don't have to read from the block, because the bit information they set is only needed in a later phase of the program.

Does false sharing only occur if the cores read and write on the same block, or does it also occur if both only write to it?

like image 669
user1494080 Avatar asked Jan 28 '15 18:01

user1494080


People also ask

What causes 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.

What type of cache misses are caused by false sharing?

Capacity misses occur when the cache size is not sufficient to hold data between references. Coherence misses are misses caused by the coherence protocol. Coherence misses can be divided into those caused by true sharing and those caused by false sharing.

What is false sharing in the context of multithreading?

False sharing in Java occurs when two threads running on two different CPUs write to two different variables which happen to be stored within the same CPU cache line.

How do you eliminate false sharing from cache?

In general, false sharing can be reduced using the following techniques: Make use of private or threadprivate data as much as possible. Use the compiler's optimization features to eliminate memory loads and stores. Pad data structures so that each thread's data resides on a different cache line.


1 Answers

Yes, it also happens then. In order to write to a subset of bytes in a cache line that line must first be read, then modified, then written back. A logical write is usually a physical read-write.

CPUs could do this differently but I'm not aware of any CPU that does this.

like image 133
usr Avatar answered Oct 12 '22 16:10

usr