如何击败缓存?
我本周的作业中有这个问题,我不明白如何击败缓存,或者如何用汇编程序显示它。有人能指出我正确的方向吗?
通过汇编程序示例展示如何击败两种不同的缓存(关联和直接映射)。解释为什么会发生这种情况以及如何解决它。用于破坏缓存的相同程序是否相同?
注意:这是家庭作业。不要只为我回答问题,这无助于我理解材料。
I have this question on my assignment this week, and I don't understand how the caches can be defeated, or how I can show it with an assembly program.. Can someone point me in the right direction?
Show, with assembly program examples, how the two different caches (Associative and Direct Mapping) can be defeated. Explain why this occurs and how it can be fixed. Are the same programs used to defeat the caches the same?
Note: This is homework. Don't just answer the question for me, it won't help me to understand the material.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
缓存是为了提高性能。因此,击败缓存意味着找到一种内存访问模式,该模式会降低性能(在存在缓存的情况下)而不是提高性能。
请记住,缓存的大小是有限的(例如,小于主内存),因此通常要破坏缓存就需要填充缓存,以便它在您访问数据之前丢弃您即将访问的数据。
A cache is there to increase performance. So defeating a cache means finding a pattern of memory accesses that decreases performance (in the presence of the cache) rather than increases it.
Bear in mind that the cache is limited in size (smaller than main memory, for instance) so typically defeating the cache involves filling it up so that it throws away the data you're just about to access, just before you access it.
如果您正在寻找提示,请考虑将数据字拆分到 2 个缓存行。
(如果您也在寻找答案,x264 开发人员也遇到了类似的问题 - 可用的更多信息 此处 和 此处 的链接内容丰富,我强烈建议您使用。即使你找到了答案,也要阅读它们。)
If you're looking for a hint, think about splitting a data word across 2 cache lines.
(In case you're also looking for the answer, a similar problem was encountered by the x264 developers -- more information available here and here. The links are highly informative, and I really suggest you read them even after you've found your answer.)
另一件需要记住的事情是您处理的缓存是虚拟的还是物理的索引/标记。在某些变体中,即使缓存本身没有完全填满,缓存别名也会强制进行行替换。在其他变体中,缓存/页面着色冲突可能会导致驱逐。最后,在某些工作负载下的多处理器系统中,缓存行迁移(不同 CPU 的缓存之间)可能会限制 CPU 缓存的有用性。
Another thing to keep in mind is whether the caches you deal with are virtually or physically indexed / tagged. In some variants, cache aliasing forces line replacements even if the cache as such isn't completely filled. In other variants, cache/page coloring collisions might cause evictions. Finally, in multiprocessor systems under certain workloads, cacheline migrations (between the caches of different CPUs) may limit the usefulness of CPU caches.