tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Data layout + false sharing



Sad Clouds <cryintothebluesky%googlemail.com@localhost> wrote:
> Say you have a structure that has some shared data, which is frequently 
> updated by multiple threads. What good methods are there to layout your
> data in such a way that avoids false sharing?

Group related structures and/or their members so they will be in the same
cache line and during synchronisation wont touch other ones?  How exactly,
that is specific to your application.

> Do you simply add some padding, taking into account CPU cache line size?
> There are many different CPUs with different cache sizes and different set 
> associative ways of mapping memory locations to cache lines.

Yes, basically align structure or memory address according to the cache line
size (these days it is reasonable to assume 64 bytes, but of course it is
hardware-specific) and fill/pad that structure, so the following one would
get a separate cache line.

-- 
Mindaugas


Home | Main Index | Thread Index | Old Index