知识卡片
伪共享放大多线程代价
多线程频繁修改同一变量会触发缓存一致性通信;即使修改的是不同变量,只要它们落在同一缓存行,也可能相互使缓存失效,这叫伪共享。额外核心于是未必换来更高吞吐。可减少共享、调整数据交换或采用成熟并发结构;优化要看硬件与剖析结果。缓存行由硬件缓存一致性维护,不能把本章简化描述理解为操作系统为每个线程私有分配硬件缓存。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 服务端架构 · 查看原书依据
Each cache line holds many variables, which can lead to a behavior called false sharing, where the cache is invalidated because a widely read variable or a widely written variable sits in the same cache line, although the latter is never read.5 5.
参考来源
- 位置:《Software Architecture and Decision-Making》第11章《Server Architectures》(来源项目:book-sources;源文件:extracted/Software Architecture and Decision-Making Leveraging Leadership, Technology, and Product Management to Build Great Products… (Srinath Perera)/_epub-src/ch11.xhtml)
- 结论依据:摘录说明多线程频繁修改同一变量会触发缓存一致性通信;即使修改的是不同变量,只要它们落在同一缓存行,也可能相互使缓存失效,这叫伪共享。其余条件结合本章相邻例子与取舍说明,数字示例不作当前性能承诺。
- 原始内容:Each cache line holds many variables, which can lead to a behavior called false sharing, where the cache is invalidated because a widely read variable or a widely written variable sits in the same cache line, although the latter is never read.5 5.