时钟页面替换算法-现有页面


9

在模拟时钟页面替换算法时,当内存中已存在一个引用时,时钟指针是否仍会增加?

这是一个例子:

4个插槽,使用时钟页面替换算法

参考列表:1 2 3 4 1 2 5 1 3 2 4 5

初始列表如下所示:

-> [1][1]
   [2][1]
   [3][1]
   [4][1]

下一个要插入的引用将是1,然后是2。指针在1之后,2之后是否仍指向1?换句话说,插入5后,时钟将如下所示:

-> [5][1]
   [2][0]
   [3][0]
   [4][0]

Answers:


9

我认为这个例子可以澄清您的所有疑问。

例如:
假设在起始页上主存储器为空,则参考序列为:
3 2 3 0 8 4 2 5 0 9 8 3 2每帧一个参考位(称为“已使用”位)

  PU 3 PU 2 PU 3 PU 0 PU 8 PU 4
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| | 0 | * | 3 | 1 | | 3 | 1 | | 3 | 1 | | 3 | 1 | | 3 | 1 |
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| | 0 | | | 0 | * | 2 | 1 | | 2 | 1 | | 2 | 1 | | 2 | 1 |
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| | 0 | | | 0 | | | 0 | * | | 0 | * | 0 | 1 | | 0 | 1 |
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| | 0 | | | 0 | | | 0 | | | 0 | | | 0 | * | 8 | 1 |
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| | 0 | | | 0 | | | 0 | | | 0 | | | 0 | | | 0 | *
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- ----  


  PU 2 PU 5 PU 0 PU 9 PU 8 PU 3
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| 3 | 1 | * | 3 | 1 | * | 5 | 1 | | 5 | 1 | | 5 | 1 | | 5 | 1 |
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| 2 | 1 | | 2 | 1 | | 2 | 0 | * | 2 | 0 | * | 9 | 1 | | 9 | 1 |
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| 0 | 1 | | 0 | 1 | | 0 | 0 | | 0 | 1 | | 0 | 1 | * | 0 | 1 | *
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| 8 | 1 | | 8 | 1 | | 8 | 0 | | 8 | 0 | | 8 | 0 | | 8 | 1 |
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- --- +
| 4 | 1 | | 4 | 1 | | 4 | 0 | | 4 | 0 | | 4 | 0 | | 4 | 0 |
+ --- + --- + + --- + --- + + --- + --- + + --- + --- + + --- + --- + +- ----  


  PU 2 PU   
+ --- + --- + + --- + --- + 
| 5 | 1 | * | 5 | 0 |
+ --- + --- + + --- + --- + 
| 9 | 1 | | 9 | 0 |
+ --- + --- + + --- + --- +
| 0 | 0 | | 2 | 1 |   
+ --- + --- + + --- + --- +  
| 8 | 0 | | 8 | 0 | *
+ --- + --- + + --- + --- + 
| 3 | 1 | | 3 | 1 |  
+ --- + --- + + --- + --- +  

* =指示标识下一个要扫描位置的指针 
P =该帧中存储的页面号 
U =使用的标志, 
0 =最近未使用 
1 =最近引用

这称为BSD Linux中使用的线性扫描算法或二次机会算法。 
通常,它被实现为循环队列。

您能用文字解释一下这是什么意思吗?这是一个不错的图,但是当我们不知道它的含义时,这些图就没有用了。
离散蜥蜴

7

如果引用到达内存中已存在的页面,则根本不会调用替换算法。

时钟替换算法试图实现一些LRU替换的好处,但没有在每一页命中操纵LRU位的庞大开销。

页面可以处于以下三种状态之一:

  1. 存在于内存中,该recently-used位为true。在这种情况下,访问页面时不会出现页面错误,因此不会改变任何位。
  2. 存在于内存中,但recently-used位为false。在这种情况下,页面也会在页面表中标记出来,以使如果访问该页面,则会发生页面错误。(如果在这种情况下发生页面错误,则页面错误处理程序唯一要做的就是将状态更改为recently-used。)
  3. 该页面不存在于内存中。在这种情况下,我们查看clock-hand。当clock-hand指向recently-used位已设置的页面时,true我们将recently-used位翻转到false,然后递增clock-hand以指向下一页。当我们找到一个recently-used已清除的页面时,即替换该页面。然后,我们将新页面标记为,recently-used然后将递增clock-hand下一页

从本质上讲,时钟是一种近似LRU的概率算法。如果访问该页面的速率远高于访问该页面clock-hand回到同一页面的速率,则该页面被标记的可能性很高recently-used。如果访问页面的速度比访问页面的速度低clock-hand,则页面更有可能处于not 状态recently-used。最近使用过的页面将永远不会被替换。(为什么?)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.