来自 JCIP book 第 11 章(性能和可扩展性)以及名为上下文切换的部分:
When a new thread is switched in, the data it needs is unlikely to be in the local processor cache, so a context-switch causes a flurry of cache misses, and thus threads run a little more slowly when they are first scheduled.
- 有人可以用一种易于理解的方式解释缓存未命中的概念及其可能的反面(缓存命中)吗?
- 为什么上下文切换会导致大量缓存未命中?
最佳答案
Can someone explain in an easy to understand way the concept of cache miss and its probable opposite (cache hit)?
缓存未命中通常是指在缓存中查找某些内容但未找到 - 缓存不包含正在查找的项目。缓存命中是指当您在缓存中查找某些内容并且缓存正在存储该项目并且能够满足查询时。
Why context-switching would cause a lot of cache miss?
在内存方面,每个处理器都有memory cache – 主存储器小部分的高速复制。当新线程上下文切换到处理器时,本地高速缓冲存储器为空或者不对应于线程所需的数据。这意味着该新线程进行的所有(或大多数)内存查找都会导致缓存未命中,因为它所需的数据未存储在本地内存缓存中。然后,硬件必须向主内存发出大量请求来填充本地内存缓存,这会导致线程最初运行速度变慢。
关于concurrency - 什么是缓存命中和缓存未命中?为什么上下文切换会导致缓存未命中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18559342/