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

1

7

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?

Mortal answered 28/1, 2015 at 18:10 Comment(0)
S
9

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.

Swadeshi answered 28/1, 2015 at 20:10 Comment(1)
Great question, great answer. I wondered the same. When profiling my code with perf c2c I came to a different conclusion. See here: #78963265Whore

© 2022 - 2024 — McMap. All rights reserved.