Professional Documents
Culture Documents
Page - New Replacement Algorithm
Page - New Replacement Algorithm
Page - New Replacement Algorithm
Algorithms (VB)
Shaify Mehta (http://www.shaify.com)
Example: Algorithm:
70120304230321201701 flag1 = 0
0 0 0 0 3 3 3 2 2 flag1 = 1
1 1 1 1 0 0 0 3
flag2 = 1
Exit Sub
0 3 2 1 2 0 1 7 0 1
End If
0 0 0 0 0 0 0 7 7 7
2 2 2 1 1 1 1 1 0 0 Next n
3 3 3 3 2 2 2 2 2 1 End Sub
Initially the three frames are empty. The first three references If flag1 = 0 Then
(7, 0, 1) causes pages faults and are added into the three empty
For i = 0 To Val(Text2.Text) - 1
frames. The next reference is (2) which replaces the page (7)
If fr(i) = -1 Then
because page (7) was added in first. Since (0) is the next
reference but (0) is already in the memory, so we have no fr(i) = page(m)
page fault for this reference. This process continues as shown
flag2 = 1
above. Every time a page fault occurs, we show which pages
are in our three frames. There are total 15 page faults. Exit Sub
End If
The FIFO page replacement algorithm is easy to implement
and understand but the performance wise is bad. The page Next i
replaced may be an initialization module that was used a long
End If which a page is used heavily during the staring phase of a
process, but then is never again. Since it was used heavily, it
End Sub
has a large frequency (count) and remains in memory ever
through it are no longer needed.
End If 0 3 2 1 2 0 1 7 0 1
2 2 2 1 2 2 2 2 2 2
End Sub
0 0 0 0 0 0 0 0 0 0
3 3 3 3 3 3 1 7 7 1
Simulation:
Algorithm:
LFUc = Val(LFUc) + 1
Else
'MsgBox "2"
LFUl = LFUn
MFU (Most Frequently Used):
'MsgBox LFUn
In MFU (Most Frequently Used) algorithm the page which
For LFUk = 0 To Val(LFUbf) - 1 has with the largest count is going to be replaced.
Next LFUk 7 0 1 2 0 3 0 4 2 3
7 7 7 2 2 2 0 4 2 2
0 0 0 0 3 3 3 3 3
LFUb(LFUlc) = LFUpage(LFUi) 1 1 1 1 1 1 1 1
LFUc = 0
0 3 2 1 2 0 1 7 0 1 'MsgBox MFUn
0 0 2 2 2 0 0 7 7 7
For MFUk = 0 To Val(MFUbf) - 1
3 3 3 3 3 3 3 3 0 0
1 1 1 1 1 1 1 1 1 1 If MFUr(MFUk) > MFUl Then
MFUl = MFUr(MFUk)
Algorithm:
MFUlc = MFUk
For MFUk = 0 To Val(MFUbn) - 1 'match c
End If
If MFUpage(MFUi) = MFUb(MFUk) Then
Next MFUk
MFUr(MFUk) = Val(MFUr(MFUk)) + 1
MFUb(MFUlc) = MFUpage(MFUi)
MFUflag = 1
MFUc = 0
Exit For 'exit loop MFUk
For MFUk = 0 To MFUi
End If
If MFUpage(MFUi) = MFUpage(MFUk) Then
Next MFUk
MFUc = Val(MFUc) + 1
MFUr(MFUlc) = MFUc
If MFUflag = 0 Then
End If
If MFUbn < MFUbf Then
Next MFUk
'MsgBox "flag0"
End If
MFUb(MFUbn) = MFUpage(MFUi)
End If
MFUr(MFUbn) = Val(MFUr(MFUbn)) + 1
MFUbn = Val(MFUbn) + 1
Simulation:
'MsgBox "bn :- " & MFUbn
Else
'MsgBox "2"
MFUl = 0
References:
en.wikipedia.org/wiki/Page_replacement_algorithm