馃攳
L-5.25: Least Recently Used Page Replacement Algorithm | Operating System - YouTube
Channel: Gate Smashers
[0]
In LRU we replace the page which is least
recently used in the past
[5]
means we replace that page which was used
firstly in the past
means we replace that page which was used
firstly in the past
[11]
let's solve it with the example
let's solve it with the example
[12]
this is the reference stream given to us
this is the reference stream given to us
[14]
and four number of frames are there
and four number of frames are there
[17]
whenever there is a demand of first page
that is page number 7
whenever there is a demand of first page
that is page number 7
[22]
initially all the frames are empty
initially all the frames are empty
[24]
so we service the page number 7
and we call it in the main memory
so we service the page number 7
and we call it in the main memory
[29]
that is called a page fault
that is called a page fault
[32]
after that we checked for page number 0,
that is there page number?
after that we checked for page number 0,
that is there page number?
[36]
page number 0 is also not there,
serviced the page number 0
page number 0 is also not there,
serviced the page number 0
[40]
means called from the hard disk
means called from the hard disk
[42]
and this also we call as page fault
and this also we call as page fault
[44]
after that page number 1 comes
after that page number 1 comes
[47]
so page number 1 was also absent
so page number 1 was also absent
[50]
so that also we called to main memory from
hard disk, that is also called a page fault
so that also we called to main memory from
hard disk, that is also called a page fault
[55]
then page number 2
then page number 2
[57]
so that is also a page fault because
it was also initially absent
so that is also a page fault because
it was also initially absent
[62]
now next is page number 0
now next is page number 0
[65]
when page number 0 came,
is my page number 0 present or absent?
when page number 0 came,
is my page number 0 present or absent?
[69]
so page number 0 is already present,
so that is called a page hit
so page number 0 is already present,
so that is called a page hit
[74]
so we can write it a page hit
so we can write it a page hit
[79]
next is page number 3
next is page number 3
[82]
page number 3 came so,
is my page number 3 present?
page number 3 came so,
is my page number 3 present?
[85]
page number 3 is not present
page number 3 is not present
[87]
so now here LRU will start, what LRU will
do?
so now here LRU will start, what LRU will
do?
[91]
so on which frame are we standing
on page number 3 we are standing
so on which frame are we standing
on page number 3 we are standing
[95]
this is the page that i have to put in the
main memory
this is the page that i have to put in the
main memory
[98]
so to put this page i will have to replace
any of the page
so to put this page i will have to replace
any of the page
[103]
so which page will we replace?
so which page will we replace?
[105]
in LRU we check the past,
means previously used pages
in LRU we check the past,
means previously used pages
[110]
so in previously used pages
so in previously used pages
[113]
which page is there among these 4
which was used at first?
which page is there among these 4
which was used at first?
[118]
which was called at first
which was called at first
[119]
means whose demand was least
means whose demand was earliest
means whose demand was least
means whose demand was earliest
[123]
so if we see here, 3 , 7, 0, 1, 2
so if we see here, 3 , 7, 0, 1, 2
[127]
so 0 has come here, 2 here, 1 here and
7 here
so 0 has come here, 2 here, 1 here and
7 here
[132]
so if we see carefully, 7's demand was at
first among these four
so if we see carefully, 7's demand was at
first among these four
[136]
you just have to compare these four
you just have to compare these four
[139]
standing at this point we have to compare
these four
standing at this point we have to compare
these four
[143]
that in past which one came at first
that in past which one came at first
[147]
whose demand was at first
whose demand was at first
[149]
so if you see carefully 7's demand was at
first
so if you see carefully 7's demand was at
first
[152]
among these four
among these four
[153]
so after sending 7 outside,
we brought 3 inside
so after sending 7 outside,
we brought 3 inside
[158]
so we entered 3 in,
and write rest of these as it is
so we entered 3 in,
and write rest of these as it is
[162]
that is called a page fault because
3 was absent
that is called a page fault because
3 was absent
[166]
now next pagenumber is 0,
is page number 0 present?
now next page number is 0,
is page number 0 present?
[169]
yes it is present?
yes it is present?
[170]
so directly copy over here
so directly copy over here
[172]
we copied and
below that we wrote hit.
we copied and
below that we wrote hit.
[176]
then page number 4
then page number 4
[179]
so page number 4 came
so page number 4 came
[181]
so when page number 4 will come, we will
have to check, is page number 4 present?
so when page number 4 will come, we will
have to check, is page number 4 present?
[186]
no page number 4 is not present
no page number 4 is not present
[189]
so now here, from 4
so now here, from 4
[192]
towards back means in past i will check,
these 4 should be compared
towards back means in past i will check,
these 4 should be compared
[196]
among 2,1,0,3 which one was used at first
among 2,1,0,3 which one was used at first
[202]
so 4, 0 came here itself, 3 came here
so 4, 0 came here itself, 3 came here
[207]
2 came here, 1 came here, so if you see
carefully, 1 is used at first among these 4
2 came here, 1 came here, so if you see
carefully, 1 is used at first among these 4
[212]
so we will replace 1 with 4
so we will replace 1 with 4
[216]
rest of these write as it is
rest of these write as it is
[218]
and this also we will call as page fault
because this page number 4 was absent
and this also we will call as page fault
because this page number 4 was absent
[223]
now we have put after service
now we have put after service
[225]
next is page number 2,
so is page number 2 present?
next is page number 2,
so is page number 2 present?
[228]
yes it is already present
so we can call this as hit
yes it is already present
so we can call this as hit
[235]
next comes page number 3
next comes page number 3
[236]
just put a mark, so that you don't try any
page again.
just put a mark, so that you don't try any
page again.
[242]
so 3, is my 3 present over here?
yes 3 is already present.
so 3, is my 3 present over here?
yes 3 is already present.
[246]
so that is again called a hit
so that is again called a hit
[250]
so next is page number 0, is page number 0
present? .. yes it is already present
so next is page number 0, is page number 0
present? .. yes it is already present
[255]
that is called a hit
that is called a hit
[257]
so next is page number 3, is page number 0
present? .. yes it is already present
so next is page number 3, is page number 0
present? .. yes it is already present
[261]
that is called a hit
that is called a hit
[264]
next is page number 2, is page number 2
present? .. yes it is already present
next is page number 2, is page number 2
present? .. yes it is already present
[269]
this also i will write as it is, that is
again called a hit
this also i will write as it is, that is
again called a hit
[274]
after that comes page number 1
after that comes page number 1
[276]
is page number 1 present?..no
page number 1 is absent
is page number 1 present?..no
page number 1 is absent
[279]
so from here onward i have to check back in
past
so from here onward i have to check back in
past
[282]
among 4,3,0 which one came first
among 4,3,0 which one came first
[286]
2 came here, 3 came here, 2 here
4, among these four 4 came first in past
2 came here, 3 came here, 2 here
4, among these four 4 came first in past
[293]
so we will replace 4 with 1
so we will replace 4 with 1
[297]
4,3, rest all write as it is,
and what is it? ... a page fault
4,3, rest all write as it is,
and what is it? ... a page fault
[301]
because this was absent
because this was absent
[303]
next comes page number 2, is page number 2
present? yes it is already present
next comes page number 2, is page number 2
present? yes it is already present
[306]
that is called a hit
that is called a hit
[310]
next comes page number 0, is page number 0
present? yes it is already present
next comes page number 0, is page number 0
present? yes it is already present
[314]
that is again called a hit
that is again called a hit
[319]
next comes page number 1, is page number 1
present? yes it is already present
next comes page number 1, is page number 1
present? yes it is already present
[323]
that is again called a hit
so we write it as it is
that is again called a hit
so we write it as it is
[328]
2, 1, 0, 3 that is again called a hit
2, 1, 0, 3 that is again called a hit
[335]
next comes page number 7, is page number 7
present? no page number 7 is not present
next comes page number 7, is page number 7
present? no page number 7 is not present
[340]
so again i will check in the past, among
1,2,0,3 which one came first
so again i will check in the past, among
1,2,0,3 which one came first
[346]
1 came here
1 came here
[348]
0 came here, 2 came here
3, 3 came here first amon these in past
0 came here, 2 came here
3, 3 came here first among these in past
[354]
i replace 3 with 7, rest all as it is
that is called a page fault
i replace 3 with 7, rest all as it is
that is called a page fault
[359]
next comes page number 0, is page number 0
present? yes it is already present
next comes page number 0, is page number 0
present? yes it is already present
[364]
this also we will call as a page hit
this also we will call as a page hit
[367]
after that page number 1 came
after that page number 1 came
[371]
page number 1 is already present
that is again called a hit
page number 1 is already present
that is again called a hit
[376]
so this way, we can replace pages through
LRU
so this way, we can replace pages through
LRU
[381]
so there is only one simple formula for
LRU
so there is only one simple formula for
LRU
[383]
that we replace the page who demand in past
was at first
that we replace the page who demand in past
was at first
[390]
so what i mean to say
so what i mean to say
[391]
means the page which was called in past
a long time ago,
means the page which was called in past
a long time ago,
[395]
there is no need of that page over here
there is no need of that page over here
[397]
so there that page we will replace by
sending in hard disk
so there that page we will replace by
sending in hard disk
[402]
and will bring any fresh page in the main
memory
and will bring any fresh page in the main
memory
[406]
so you can simply count number of page
fault.. one two three four five six
so you can simply count number of page
fault.. one two three four five six
[410]
seven eight
seven eight
[412]
so number of page faults are...eight
so number of page faults are...eight
[415]
in maximum questions they will ask you
what is total numbe of page faults
in maximum questions they will ask you
what is total number of page faults
[420]
and
what is total numbe of page hits
and
what is total numbe of page hits
[422]
so you can also calculate page hits
so you can also calculate page hits
[425]
so one two three four five six seven eight
nine ten eleven twelve
so one two three four five six seven eight
nine ten eleven twelve
[430]
so 12 number of hits are there
so 12 number of hits are there
[434]
so that is how LRU works
so that is how LRU works
[436]
although it is given less number of page
faults.. as compared to Fifo
although it is given less number of page
faults.. as compared to Fifo
[441]
but what is the problem with it?...
performance ..speed
but what is the problem with it?...
performance ..speed
[444]
because, this always, if you have checked
carefully
because, this always, if you have checked
carefully
[447]
so this always search in past which one
was farthest in past
so this always search in past which one
was farthest in past
[453]
so over here searching algorithm
is being used
so over here searching algorithm
is being used
[456]
so due to that if i compare it with Fifo
so due to that if i compare it with Fifo
[459]
over here that, speed factor
over here that, speed factor
[462]
LRU.. it's speed is less,
so at somepoint it is taking more time
LRU.. it's speed is less,
so at some point it is taking more time
[466]
as compared to fee fo
1
00:00:00,603 --> 00:00:05,158
In LRU we replace the page which is least
recently used in the past
as compared to Fifo
[468]
but yes it is performing better
than that in terms of page performance
but yes it is performing better
than that in terms of page performace
[471]
so this is all about the LN
Thank you
so this is all about the LN
Thank you
Most Recent Videos:
You can go back to the homepage right here: Homepage





