Seeking Consistency


Why pad by 128 bytes?

Posted on 2019-03-11

False sharing is where two fields occupy the same cache line and are accessed by separate threads and where at least one thread performs writes. The net effect is that writer threads frequently invalidate that cache line on other cores. This is where padding comes in. Everyone knows that a cache line is 64 bytes, so surely to ensure two fields are on different cache lines you need only pad by 64 bytes? Not quite. Intel has this great feature...

Continue Reading

Detecting memory corruption with dog tags

Posted on 2016-05-08

There's a fantastic technique I've used in my C days that attempted to detect memory corruption. It's a cheap and usually effective technique because it relies on common causes of corruption, namely off by one or any bound writes into memory beyond your allocated limit or even pointer arithmetic gone a-rye. It works by whenever you allocate memory you write a tag at the start and end. This can be anything but should be big enough such that it's unlikely...

Continue Reading