什么是false sharing

来源:互联网 发布:淘宝消防车玩具视频 编辑:程序博客网 时间:2024/06/02 06:40

1. cache coherence(cache 一致性)

在提到false sharing概念之前,首先还是了解一下cache coherence(cache一致性)

cache coherence是指在本地cache中保存的共享数据的一致性。

在共享主存多处理器系统中,每一个处理器都有自己的本地cache。那么可能对于同一个数据在几个本地cache中都有拷贝,当其中一个拷贝被修改了,其他的拷贝(按照一致性要求)也应当被修改,cache一致性就是这么一个规矩,它要求在每一个cache中对数据的改变尽快传播给其他的cache。

有三种层次上的cache一致性要求

1. 每一个写操作立即产生效果

2. 每一个处理器(processes)看到的数值变化是以同样的顺序发生的

3. 不同的处理器(processes) 看到的数值的变化是不同的(这被认为是非一致的行为)

在第二层次和第三层次,程序都可能观察到失效的数据。

 

2. false sharing(假共享)

 When a system participant attempts to periodically access data that will never be altered by another party, but that data shares a cache block with data that is altered, the caching protocol may force the first participant to reload the whole unit despite a lack of logical necessity.

The caching system is unaware of activity within this block and forces the first participant to bear the caching system overhead required by true shared access of a resource.

By far the most common usage of this term is in modern multiprocessor CPU caches, where memory is cached in lines of some small power of two word size (e.g., 64 aligned, contiguous bytes). If two processors operate on independent data in the same memory address region storable in a single line, the cache coherency mechanisms in the system may force the whole line across the bus or interconnect with every data write, forcing memory stalls in addition to wasting system bandwidth. False sharing is an inherent artifact of automatically synchronized cache protocols and can also exist in environments such as distributed file system or databases, but current prevalence is limited to RAM caches.

也就是说,在上面提到的cache一致性要求下,由于假共享,被迫做了逻辑上不必要的reload操作。