Previous | Next --- Slide 9 of 90
Back to Lecture Thumbnails
itoen

False sharing means we have multiple processors writing to the same cache line (64 bytes), even if they are writing to different pieces of data (e.g. the int counters are 4 bytes). The performance is as poor as if they had been writing to the same data, since the cache line must be retrieved across the bus using the operations we discussed last lecture.

In this particular example, a fix would be to pad the counter structs so that each counter spans an entire cache line. This way multiple processors writing to different counts are guaranteed to be writing to different cache lines, so there is no longer any false sharing.

xhe17

the difference between test1 and test2 program is that test2 has a padding mechanism (padded_t counter[MAX_THREADS] instead of int counter[MAX_THREADS]) that makes sure different processors are writing on data resided in difference cache lines to prevent false-sharing problem mentioned in p10.

Please log in to leave a comment.