0

假设物理内存中有 3 帧。第 1 帧有引用字符串“a”,第 2 帧有引用字符串“b”,第 3 帧有引用字符串“c”。它们的使用位为 1。下一个序列牺牲品是第 2 帧。

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

为什么第二次机会算法在引用字符串“b”出现后没有将受害者更改为第 3 帧?b 是最新的参考,但为什么我们要替换它?

编辑

也许我在第二次机会算法上犯了一些错误。

例如,如果引用序列是 'ebcabcb 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 帧。我对么?

4

0 回答 0