错误的分享会导致错误的结果吗? [英] Can false sharing lead to wrong results?

查看:69
本文介绍了错误的分享会导致错误的结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,当两个CPU内核访问单个内存块的不同部分时,就会发生错误共享.在这种情况下,每个内核中的L1缓存包含不同的值.

As I know, false sharing occurs when two cpu cores access different parts of a single memory block. In this case, the L1 caches in each core contains different values.

虚假共享有什么影响?商品CPU是否总是检测到虚假共享?会导致类似竞争的情况(在内存中保留不同的缓存版本)吗?

What is the effect of false sharing? Do commodity CPUs always detect a false sharing? Can it lead to something like a race condition (persisting different cache versions in the memory)?

推荐答案

当一个内核修改某些数据,而另一个内核读取恰好位于同一高速缓存行中的一些无关数据时,就会发生错误共享.修改迫使第二个内核重新加载整个缓存行,即使它正在使用的数据不变.

False sharing occurs when one core modifies some data, and another reads some unrelated data that happens to lie in the same cache line. The modification forces the second core to reload the whole cache line, even though the data it's using is unchanged.

除非缓存被严重破坏,否则不会导致任何不正确的行为.但这会带来很大的性能影响,因为不必要地从更高级别的缓存中获取缓存的数据.

This won't cause any incorrect behaviour unless the cache is horribly broken. But it can have a large performance impact, as cached data is unnecessarily fetched from higher level caches.

这篇关于错误的分享会导致错误的结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆