每个人。
我已经阅读了很多关于 ClockPro 缓存替换算法的文章 - 时钟缓存替换的改进版本。起初为了简单起见,我实现了时钟。现在我想用 2 只手在 Java Clock-Pro 中实现(热和冷而不是实际算法中的 3 只手)。我找到了一些描述:
The ClockPro Algorithm
On Start():
cold_block = first block
hot_block = first block
On Memory Lookup():
curr_block = NULL
If block is in cache:
Set clock bit
Return block to CPU
Else:
While curr_block == NULL:
If cold_block.clockbit == 0:
curr_block = cold_block
Else if cold_block.test == 1 :
Turn cold hand block hot
Unset the clockbit
Run Hot Hand Algorithm
Else:
cold_block.clockbit = 0
cold_block = cold_block.next
If curr_block is dirty : write
Find accessed block in memory
Return fetched block to the CPU
Replace curr_block with fetched one
Hot Hand Algorithm() :
curr_block = NULL
While curr_block == NULL:
If hot_block is cold :
hot_block.text = 0
Else if hot_block.clockbit == 0 :
Turn the block cold
Else :
hot_block.clockbit = 0
hot_block = hot_block.next
如果有人尝试过,请回答一些问题:
考试时间是多少?它什么时候开始,我们可以使用什么类型。是否只是一点点,可以告诉我们对象是否处于测试期,或者它是一个计数器?双手可以在某个时间点指向一个街区吗?
如果有人可以,请帮助我在一个简单的示例中对算法的这种行为进行建模。谢谢。