为什么LRU不会遭受贝拉迪异常?

发布于 2024-10-21 09:57:54 字数 170 浏览 6 评论 0原文

我有一个关于页面替换算法的问题。 FIFO 会受到 Belady 异常 的影响,但 LRU 不会。有谁知道为什么 LRU 不受影响?我一直在互联网上寻找原因但没有运气。

I have a question about page replacement algorithms. FIFO suffers from Belady's Anomaly but LRU doesn't. Does anyone know why LRU doesn't suffer? I've been searching for the reason on the internet but no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌若浮生 2024-10-28 09:57:54

因为LRU是一种堆叠算法,并且使用k帧将始终是LRU的k+n帧的子集。因此,任何可能在 k + n 帧中发生的页面错误也将在 k 帧中发生,这又意味着 LRU 不会遭受 Belady 异常的影响。

Because LRU is a stacking algorithm, and using k frames will always be a subset of k + n frames for LRU. Thus, any page-faults that may occur for k + n frames will also occur for k frames, which in turn means that LRU doesn't suffer Belady's anomaly.

萌吟 2024-10-28 09:57:54

因为 FIFO 假设某个页面已占用内存很长时间,更换它是最安全的,但实际上情况并非如此。相反,从统计上看,FIFO 失败的地方是,如果一个页面被频繁调用,那么它比最近被调用的另一个页面更有可能被再次调用。换句话说,频率比年龄更能决定页面加载。

Because FIFO assumes that the mere fact that a page has been occupying memory for a long time that it is the safest to replace, where in reality that simply isn't the case. Rather, where FIFO fails is that statistically, if a page has been called frequently, it's more likely to be called again than another page which has been called recently. In other words, frequency is a far better determiner of page loading than age.

朮生 2024-10-28 09:57:54

与卡斯帕的答案类似,但我发现我的教科书(稍作编辑)中的解释更清楚一些。

[LRU ]属于一类页面替换算法,称为堆栈算法,[]永远不会表现出 Belady 的异常现象。

堆栈算法是一种可以证明内存中 N 帧的页面集始终是内存中 N + 1 帧的页面集的子集的算法。 [因此,额外的帧永远不会导致额外的页面错误。]

对于 LRU 替换,内存中的页面集将是最近引用的 N 个页面。如果增加帧数,这 N 个页面仍将是最近引用的页面,因此仍会在内存中。

Silberschatz, A.、Galvin, PB 和加涅,G.(2014)。操作系统概念(第 9 版)。新加坡:威利。

Similar to Caspar's answer, however I found the explanation from my textbook (slightly edited) to be a bit more clear.

[LRU belongs] to a class of page-replacement algorithms, called stack algorithms, [which] can never exhibit Belady’s anomaly.

A stack algorithm is an algorithm for which it can be shown that the set of pages in memory for N frames is always a subset of the set of pages that would be in memory with N + 1 frames. [Therefore an additional frame will never cause an additional page fault.]

For LRU replacement, the set of pages in memory would be the N most recently referenced pages. If the number of frames is increased, these N pages will still be the most recently referenced and so will still be in memory.

Silberschatz, A., Galvin, P. B., & Gagne, G. (2014). Operating System Concepts (9th ed.). Singapore: Wiley.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文