false sharing performance issue in programs where cores may write to different memory addresses but in the same cache lines
{"Image DocumentName": "False Sharing Performance issue in programs where cores may write to different memory addresses BUT in the same cache lines.", "Image ImageDescription": "Known as Ping-Ponging \u2013 Cache line is shipped between cores. Core 0. Core 1. X[0] = X[1] = Time. X[0] = 1. X[1] = 1. X[0] = 2. Intel book \u2013 Multi-core Programming \u2013 Increasing Performance Through Software Multi-threading by Shameem Akhter and Jason Roberts. False Sharing The smallest unit of memory that two processors interchange is a cache line or cache sector. Two separate caches can share a cache line when they both need to read it, but if the line is written in one cache, and read in another, it must be shipped between caches, even if the locations of interest are disjoint. Like two people writing in different parts of a log book, the writes are independent, but unless the book can be ripped apart, the writers must pass the book back and forth. In the same way, two hardware threads writing to different locations contend for a cache sector to the point where it becomes a ping-pong game. In this ping pong game, there are two threads, each running on a different core. Each thread increments a different location belonging to the same cache line. But because the locations belong to the same cache line, the cores must pass the sector back and forth across the memory bus. In order to avoid false sharing \u2013 we need to alter either the algorithm or the data structure. We can add some padding to a data structure or arrays ( just enough padding generally less than cache line size) so that threads access data from different cache lines. Or we can adjust the implementation of the algorithm (the loop stride) to access data in different cache line for each thread False Sharing is not an issue in shared cache. It is an issue in separated cache.", "Image XResolution": "37", "Image YResolution": "37", "Image ResolutionUnit": "Pixels/Centimeter", "Image Software": "SlidePlayer", "Image YCbCrPositioning": "Centered"}