改进二次机会算法

时间:2015-12-15 15:07:52

标签: algorithm paging page-replacement

假设物理内存中有3帧。帧1具有参考字符串'a',帧2具有参考串'b',帧3具有参考串'c'。它们的使用位是1.而下一个序列受害者是第2帧。

如果下一个参考字符串是'b',则在Second Chance算法中,我们再次将Frame 2的使用位设置为1。之后,如果下一个引用字符串是'd',则第2帧将被替换为'd',第1帧和第3帧的使用位也将被设置为0。

为什么在参考字符串'b'到来之后,第二次机会算法没有将受害者更改为第3帧? b是最近的参考资料,但我们为什么要更换它?

修改

也许我在Second Chance算法上犯了一些错误。

例如,如果引用序列是'e b c a b c b d'并且物理内存中有3帧,我的步骤是:

Sequence Number: 0
    Frame 1(victim):
        Reference: null
        Use Bit: 0
    Frame 2:
        Reference: null
        Use Bit: 0
    Frame 3:
        Reference: null
        Use Bit: 0
Sequence Number: 1
    Reference: e
    Page Fault: true
    Frame 1:
        Reference: e
        Use Bit: 1
    Frame 2(victim):
        Reference: null
        Use Bit: 0
    Frame 3:
        Reference: null
        Use Bit: 0

Sequence Number: 2
    Reference: b
    Page Fault: true
    Frame 1:
        Reference: e
        Use Bit: 1
    Frame 2:
        Reference: b
        Use Bit: 1
    Frame 3(victim):
        Reference: null
        Use Bit: 0

Sequence Number: 3
    Reference: c
    Page Fault: true
    Frame 1(victim):
        Reference: e
        Use Bit: 1
    Frame 2:
        Reference: b
        Use Bit: 1
    Frame 3:
        Reference: c
        Use Bit: 1

Sequence Number: 4
    Reference: a
    Page Fault: true
    Frame 1:
        Reference: a
        Use Bit: 1
    Frame 2(victim):
        Reference: b
        Use Bit: 0
    Frame 3:
        Reference: c
        Use Bit: 0

Sequence Number: 5
    Reference: b
    Page Fault: false
    Frame 1:
        Reference: a
        Use Bit: 1
    Frame 2(victim):
        Reference: b
        Use Bit: 1
    Frame 3:
        Reference: c
        Use Bit: 0

Sequence Number: 6
    Reference: c
    Page Fault: false
    Frame 1:
        Reference: a
        Use Bit: 1
    Frame 2(victim):
        Reference: b
        Use Bit: 1
    Frame 3:
        Reference: c
        Use Bit: 1

Sequence Number: 7
    Reference: b
    Page Fault: false
    Frame 1:
        Reference: a
        Use Bit: 1
    Frame 2(victim):
        Reference: b
        Use Bit: 1
    Frame 3:
        Reference: c
        Use Bit: 1

Sequence Number: 8
    Reference: d
    Page Fault: true
    Frame 1:
        Reference: a
        Use Bit: 0
    Frame 2:
        Reference: d
        Use Bit: 1
    Frame 3(victim):
        Reference: c
        Use Bit: 0

Number of Page Fault: 5

在序列7和序列8之间,替换帧2。我是对的吗?

0 个答案:

没有答案