in Operating System edited by
28,635 views
76 votes
76 votes

A computer has twenty physical page frames which contain pages numbered $101$ through $120$. Now a program accesses the pages numbered $\text{1, 2, ..., 100}$ in that order, and repeats the access sequence THRICE. Which one of the following page replacement policies experiences the same number of page faults as the optimal page replacement policy for this program?

  1. Least-recently-used
  2. First-in-first-out
  3. Last-in-first-out
  4. Most-recently-used
in Operating System edited by
28.6k views

4 Comments

I have the same doubt!
0
0

@Arjun sir, here all the answers have made the assumption that for MRU the pages 101 to 120 will be swaped out. Can we make assumptions like this in exam? Because in this case Optimal will not behave exactly like MRU, and the reason is the twenty pages that were already loaded. Please note here I have taken the sequence as 1,2,3,.....99,100,1,2,3......99,100,1,2,3.....99,100.
  
Please correct me if I am wrong, according to my calculations, in Optimal we will get 40/300 page hit rate, and in MRU we will get 0/300 Page Hit Rate. 

I know MRU and Optimal work exactly same when the sequence is in a loop but in this question, the twenty frames are already loaded and that is what is making the difference. 

6
6
1
1

10 Answers

82 votes
82 votes
Best answer

It will be (D) i.e Most-recently-used.

To be clear "repeats the access sequence THRICE" means totally the sequence of page numbers are accessed $4$ times though this is not important for the answer here. 

If we go optimal page replacement algorithm it replaces the page which will be least used in near future.  

Now we have frame size $20$ and reference string is

$$1, 2, \dots, 100,1, 2, \dots, 100,1, 2, \dots, 100, 1, 2, \dots, 100$$

First $20$ accesses will cause page faults - the initial pages are no longer used and hence optimal page replacement replaces them first. Now, for page $21$, according  to reference string page 1 will be used again after $100$ and similarly $2$ will be used after $1$ so, on and so the least likely to be used page in future is page $20$. So, for $21^{\text{st}}$ reference page $20$ will be replaced and then for $22^{\text{nd}}$ page reference, page $21$ will be replaced and so on which is MOST RECENTLY USED page replacement policy.  

PS: Even for Most Recently Used page replacement at first all empty (invalid) pages frames are replaced and then only most recently used ones are replaced.

edited by

57 Comments

Can you please explain...after replacement of page 20 with page 21 ...what would be the most recently used reference....wouldn't it be 21 ...?That is why we will replace the page 22 with page page 19...?
1
1

after replacing 20 by 21 

FRAMES SHOWN BELOW
20---> replaced by 21 
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1

so now 

FRAMES SHOWN BELOW
 21 (MOST RECENTLY USED)
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1

so 21 will be replaced by 22

FRAMES SHOWN BELOW
 22 (MOST RECENTLY USED)
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
1
1
But does the number of page faults for LIFO and MRU differ here?
1
1
reshown by

@arjun sir this option is for confusion there no page replacement algorithm exist as LIFO 
A nice trick played by GATE paper setters (I had same doubt on the first hand but then i searched this one and found No book has ever implemented LIFO Algo for page replacement wink

1
1
1
1

@Arjun Sir the link shared by you has a line "The victim page is the page that has been most recently inserted into memory"

so its the LIFO is not used its used as MRU (they are synonyms ) but to be correct its most recently used As genrally known 

1
1

They are not synonyms- "most recently inserted into memory" and "most recently referenced in memory" are not the same. 

14
14
edited by

@ arjun sir thanx because of you  i got where i was going wrong
Replace till 100 from 1 to 19 no page faults ryt 

FRAMES SHOWN BELOW
100
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1

now  till 20 will arrive  no page fault ......again 100 will be used in near future because of string coming in near future(ie 20 21 ......100 ,1,2......100) correct so in Optimal merge pattern 19 will be replaced instead of 100 
i.e MOST recent was 19 but for LIFO 100 must be replaced...

FRAMES SHOWN BELOW
 100
19(most recently used )
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
FRAMES SHOWN BELOW
 100
20(MOST RECENTLY USED)
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
2
2
@Arjun Sir now we got the correct reason and Solution :)
0
0
Why there will be no page faults from 1 to 19 and can you please explain briefly the solution....couldn't get it...
0
0
Its for the second time when string is referred after 1,2,3......100 again 1,2,3,4,......19,20,21.....100
there will be no page fault for these because we are not replacing 1 to 19 pages according to optimal Page replacement algorithm
0
0
thanks..
0
0
while using MRU why didn't we assumed that pages 101 to 120 will be there and anyone of them will be replaced????
0
0
101 to 120 will be there and anyone can be replaced. I guess its worth counting the page faults here.
0
0
so i doubt sir

in gate we have to make assumptions if not getting the answer

like if TLB access time not given then take 0

or in this question , assume the 20 frames are empty (when testing MRU)

??

Sir how do u know when to take assumption

- if answer is not coming or while reading the question
1
1

@lgau0522 we are counting them just not showen here keeping in mind the assumption that it is understandable 
But this is ryt that 101 to 119 there will be no page faults as 1 ,2,3,....19 are allready avilable in frame 

0
0
when i was solving this question i got 260 page fault for optimal

but when i tried for options (i.e MRU) i assumed frames will have 101 to 120

which will not give the answer

so here we have to assume those frames are empty to get 260 faults (from MRU)

am i thinking right??
1
1
yes its always the case we need to take frames as empty until and unless specified
0
0
i dont want to be annoying

but in this question they said frames are filled and asked which policy will experience same faults so i followed the question!!

but i get it now!
0
0
Yes here they have mentioned 101 to 120 are present but no occurring sequence is mentioned of them so you cannot say which is most recently used or which is not so just consider 1 fault for every 1 to 20 frame in every algo mentioned in the question (if the occurrence was clearly defined then accordingly we need to take miss and hits )
1
1
we wont get the answer if we consider 101 to 120 are present

assume they are present

now one of them will surely be the most recent used replace it (any one of it)

now if u continue the frame u replaced will be the one getting replaced not others and hence will get 300 faults
0
0
303 rt? Also, 120 pages are accessed and repeated thrice. So, it should be 480 page accesses. So, 4*101 = 404 page faults rt?
0
0
@ arjun sir their wil be 262 page falut
since 101 to 120 is present now string reffered is 1,2.....,99,100,1,2,3.........99,100,1,2,........99,100

so 101 and 120 will never appear so first time 100 page fault next time 100-19(since we are not replacing these 19 )= 81 page fault ,next time 100-19(since we are not replacing 1 to 18 and 100th page from last time )=81 page fault
so,100+81+81=262 Page fault in both MRU and Optimal pag replacement
2
2
i think there will be 300 faults

101 102 ..............................................119 120

now remove one of them say 120

now u can see that the frame containing 1 (which replaced 120) will always contain the Most recently used pages hence 300

ALL THE 300 PAGES WILL GO TO SAME FRAME
2
2

So, no option is correct? 


What would be the number of page faults for these?
and repeats the access sequence ONCE.
and repeats the access sequence 
TWICE.
and repeats the access sequence 
THRICE.
 

0
0
100,200,300
0
0

and with no repetition of the access sequence?

0
0
edited by

@Arjun sir ,@lgau0522 if we see like that in real practical situations MRU is not that useful then becuase may be these reffered page ie. 101 to120 belong to some other process which is not in running state now so why we need to maintain them unnecessarily as they are also not refer'ed in the given sequence string as well 
Consider this as a real life example 
suppose we have some pages which were refer'ed by Cpu present in Main memory (RAM) now that prog terminates so new program req new set of pages arrives so RAM dose not clear automatically it is replaced by new set of Pages that is arriving reffered by new program (eg here 1 to 100 are belonging to new prog may be )
since nothing is mentioned regarding those 101 to 120 why we are considering them for MRU and Optimal search  unnecessarily
May be those where of some other process which has been blocked / terminated 

#JUST A thought came to my mind 

0
0
i think all of the page replacement policies will give the same no. of page faults.

300

if i am wrong please provide valid reason.
2
2
@kalpish Then they could have mentioned all pages are empty initially :)

@Tamojit-Chatterjee I agree. But it should be 400 and not 300 (repeated thrice should mean happened 4 times). And lets wait if someone can provide a better interpretation of the question.

@Suraj any help?
3
3
edited by
all give same page faults which is 400 and optimal page replacement gives 100+(100-19)+(100-19)+(100-19) .=343.
1
1
Actually in MRU non referenced frames are replaced first and then only MRU ones thus making it optimal here :)
5
5

sir  

initially in 20 page frame 101 to 120 are present. 

optimal says remove frame which referenced at last means which also present in page frame at present.

so 1 is push in any  place ans replace of 120 b/c numerically it come last .

now push 2 since 1 comes last  

continue the same always remove 1st page frame.

Least-recently-used says which referenced  first 

remove 101 first then push 1

remove 102 push 2.

like this work as first in first out.

last in first out works as stack remove which is pushed one step before.

 Most-recently-used most recently insert 120 then remove it push 1. 

remove 1 push 2....

do it untill we finish..

i got MRU and optimal same page fault with same frame no. 

0
0
Q 2014 2_33  all give same page faults which is 400 and optimal page replacement gives 100+(100-19)+(100-19)+(100-19) .=343.  In first sequence from 1 to 19 and 100  why not considering 100 page as no page fault . ie why 19  why not 20
0
0
See the answer now..
0
0
As per the question 20 physical frames contain pages from 101 to 120 .Thus in total 120pagess.How is that possible?It means one physical frame contain 6 pages of the program. But as far i know one physical frame is equal to one page.

if that the case in that why not pages numbered 1 to 100(100 pages) are accommodated in those 20 frames which can contain up to 120 pages.it can easily accommodate there:?
0
0
why have we not considered them unnecessary in LIFO case?? I dont understand this assumption based questions. Why do they make only such questions. Cant they be bit clear with the question?? will it hurt them??,
6
6
@Arjun Sir, you said that non refrenced removed first in MRU. Is it the same case in LIFO or LIFO will have 400 faults???
0
0
optimal page replacement and MRU will give 100+(100-20)+(100-20)+(100-20) .=340 misses  where as LIFO will give  100+(100-19)+(100-19)+(100-19) .=343 misses.
5
5
can u explain why?
0
0
you must have assumed 101-120 initial frames as invalid then only 343 can come. well i think this question is a bit ambiguous. More of assumption
3
3
1 2 3 ---19 20 now 20 gets popped out 21 ,21 gets popped out 22 so at the end of ist round we have 1 2 3 4 --19 100, now 1 to 19 hit ,20 will replace 19 not the hundred (here is the difference from LIFO),so upto 99 we get miss but at 100 again hit so total 20 hit in 2nd round . and frames present are 1 2 3 4........18 99 100, so in 3rd round upto 18 no miss now 19 will replace 18 so again will get a hit at the time of accessing 99 and 100 so again 20 hits ,similarly in 4th round 1 .....17 98 99 100present so 1 to 17 hit and again in 98 ,99,100 we will get hit.. So total 60 hits ..
67
67
thanx. but again we have to assume that 100-120 are invalid frames otherwise we wont get the hits.
3
3
yes that we have assumed..
3
3
Your answer is correct and you should answer this question as a separate answer not as a reply to an answer.
1
1

@Shreya Roy ji Thank You. :)

1
1

But does the number of page faults for LIFO and MRU differ here?

 

Arjun yes sir in Case of LIFO Page Fault is  343 (20+80+81+81+81). where as in case of Optimal and MRU its 340.

0
0
Lifo case :-

still the last in was 100 since it was last inserted, others (next 1 to 19) are just touched means accessed not inserted and lifo means last in first out

so i feel for the placement of 20 in second time element naming 100 will be choosen

@arjun sir please confirm
0
0

@sushmita

@Arjun

I believe MRU is not same as Optimal here. For MRU I am getting 400 pagefaults as at same place all pages are replaced. While in Optimal we get 343 pagefaults.

Please correct me, if i am wrong.
Should I assume 101-120 as invalid

1
1
Should I assume 101-120 as invalid

yes you have to assume that.
0
0
What difference LIFO makes ?? Plz explain
0
0

@Arjun sir,

Actually in MRU non referenced frames are replaced first and then only MRU ones thus making it optimal here

Any reference to this claim? I couldn't find anywhere.

Maybe the process started by using 101 to 120 pages and after that it accessed 1 to 100 repeatedly. Maybe pages 101 to 120 were pre-paged (pre-paging used instead of pure demand paging.)

I am not concerned about "which option to select" .. Only concerned about correct concept. 

0
0

@Deepakk Poonia (Dee)

I think the statement made by @Arjun is incorrect. Non-referred frames will not be the recent ones used for sure and hence not replaced in MRU.

0
0
@arjun the link is dead
0
0
how are we talking about more than 300 misses when there are only 300 references?
0
0
because there are total 400 references in reference string read carefully u will get it.
0
0

@Arjun when the MRU algorithm is executing 
101 will be replaced by 1.

and now 1 is most recently used hence 1 should be replaced by 2.
and so on 
is this correct 

3
3
35 votes
35 votes

The optimal page replacement algorithm swaps out the page whose next use will occur farthest in the future. In the given question, the computer has 20 page frames and initially page frames are filled with pages numbered from 101 to 120. Then program accesses the pages numbered 1, 2, …, 100 in that order, and repeats the access sequence THRICE. The first 20 accesses to pages from 1 to 20 would definitely cause page fault. When 21st is accessed, there is another page fault. The page swapped out would be 20 because 20 is going to be accessed farthest in future. When 22nd is accessed, 21st is going to go out as it is going to be the farthest in future. The above optimal page replacement algorithm actually works as most recently used in this case. As a side note, the first 100 would cause 100 page faults, next 100 would cause 81 page faults (1 to 19 would never be removed), the last 100 would also cause 81 page faults.

4 Comments

How do we get 20 hits? we get 19 hits in the second round(from 1-19), then 20 will replace 100, 21 will replace 20 and so on again till 100. How is 100 considered a hit in this sequence. I can't figure this out. Please explain
0
0

@Rishav_Bhatt replying too late .... But i think you had also considered "repeat the access sequence thrice" means sequence of page numbers are accessed 4 times.

0
0

 After the first round the sequence we will be having is 1,2,3,4.............19,100. 100 will be placed in the last frame as 20 will be replaced by 21, then 21 with 22 and so on till 100. Now when the second sequence starts till 1-19 there will be a hit now 20 will now be replaced with 19 as 19 is the will be not used for the longest time, similarly 20 by 21 till 99. Now when in the second sequence we come across 100 it will be a hit. Hence in the second sequence, we get 20 hits

2
2
17 votes
17 votes

The optimal algorithm gives 340 page faults(assuming 3 sequences from 1-100): 

We have 20 frames containing 20 pages:  101, 102, 103, 104.....120. Since these pages are never referred again in future, we will replace them all. So, we now have 1, 2, 3, .... 17, 18, 19, 20 in the frames. 20 would not be used for the longest duration, so we remove 20 and load 21. Repeating this till we reach 100.

Now, we have 1, 2, 3,... 17, 18 , 19, 100. In second repetition we get 19 hits (for 1-19). Now 100 is needed in this repetition but 19 in next.

 (1, 2, 3, 4, .... 19, 20,.... 99, 100  | 1, 2, 3,... 19, 20, 100)

So removing 19 and loading 20th page. At this instance main memory has

1, 2, 3, .... 20, ... 99, 100

20 is the best candidate to remove because it'd be needed later than the rest (like 1 , 2, 3...) in next iteration. So removing 20 and loading 21. Again to accommodate 22, 21 is best candidate to be removed. Repeating this process, we reach 100, which is already present in memory. So total hits become 20. Before the next repetition, main memory has

1, 2, 3, ...18, 99, 100

At the beginning, there would be total 18 hits. Since we need 99 and 100 in this iteration, 18 shall be removed, followed by 19, 20.... till 98. So at the end, again we have 20 hits. In the third iteration too, 17 shall be replaced, 98, 99, 100 already found in main memory, summing up the total hits to 20. So total page faults with optimal algorithm are 100+(100-20)+(100-20)+(100-20)=340


This clearly is MRU or most recently used where the latest referred page gets removed. For eg, in first iteration, since 19 was referred last, we removed it. But the frames were not empty at the beginning. Only optimal algorithm looks at the future demands and decides the best course, all the other algorithms make decisions based on previous entries. Hence neither MRU nor LIFO would eliminate all the 20 entries 101, 102, .... 120.

In fact MRU and LIFO in such circumstances would yield same results because they would keep replacing the last entry and perform worst. Thus to answer, we must assume the frames as empty, in which case MRU would better LIFO (because LIFO would remove the last entered page such as 100, thus reducing hits by 1.)

3 Comments

great answer.

FIFO=LRU=400 page faults

MRU=optimal=340 pf

LIFO=343 pf
4
4
If there are 300 pages given(1 to 100, 1 to 100, 1 to 100)..then how page faults occur more than 340 ?
1
1
There are 3 ADDITIONAL repetitions, therefore in total there will 400 pages in the sequence
1
1
17 votes
17 votes

Correct Answer is MRU. Let's see how

we can convert this problem to 3 pages and 5 page accesses which is accessed 3 times (you can access any no. of times above 2 it does not matter) because ratio of page fault will be same.

Note- Whenever there is repeated sequence like 12345 12345 then optimal convert itself into MRU & whenever there is reverse sequence like12345 54321 then optimal convert itself into LRU.

edited by

1 comment

@Nitesh Singh 2 Yes bro if we get this idea that "fault rate ratio will be similar",we can save lot of time in exam.But here given like initally 101 to 120 numbered pages are there,so doubt is which one to consider MRU page among them?If we consider like last page 120,then all the faults will occur at 120 for every page since we are not using any other page as per MRU.Then it boiled down to page replacement with no of frames=1.So it should have 300 faults right? Then how  will it be equal with optimal?

0
0
Answer:

Related questions