0

Assume there are 3 frames in physical memory. Frame 1 has reference string 'a', Frame 2 has reference string 'b', Frame 3 has reference string 'c'. And their use bits are 1. And the next sequence victim is Frame 2.

If the next reference string is 'b', in Second Chance Algorithm, we set the Frame 2's use bit to 1 again. After that, if the next reference string is 'd', Frame 2 will be replaced to 'd', and the use bits of Frame 1 and Frame 3 will be set to 0, too.

Why second chance algorithm didn't change the victim to Frame 3 after the reference string 'b' come? b is the most recent reference but why we have it replaced?

EDIT

Maybe I made some mistakes on Second Chance Algorithm.

For example, if the sequence of references is 'e b c a b c b d' and there are 3 frames in physical memory, my steps are:

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

Between Sequence 7 and Sequence 8, the frame 2 was replaced. Am I correct?

user3032481
  • 548
  • 6
  • 18
  • 2
    Why is it like that? What is your source? I am not completely sure what you are asking, but isn't just the issue that a bit has only 2 states? If two pages have their reference bit set they are considered "equally good" regardless of which one was checked later. If you are asking why it doesn't use a better mechanism: it's all (as always) about tradeoffs. There are many algorithms out there that to smarter things at higher cost. It's just about what is important in particular circumstances. – Vincent van der Weele Dec 15 '15 at 15:28
  • Have a look at this: https://en.wikipedia.org/wiki/Page_replacement_algorithm#Clock – m69's been on strike for years Dec 15 '15 at 19:39

0 Answers0