First in First Out (FIFO) - : Case 1: Number of Frames 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

First In First Out (FIFO) – 

This is the simplest page replacement algorithm. In this algorithm, the operating system
keeps track of all pages in the memory in a queue, the oldest page is in the front of the
queue. When a page needs to be replaced page in the front of the queue is selected for
removal.

The reference String is given as 0 1 5 3 0 1 4 0 1 5 3 4. Let's analyze the behavior of FIFO


algorithm in two cases.

Case 1: Number of frames = 3

Request 0 1 5 3 0 1 4 0 1 5 3 4

Frame 3 5 5 5 1 1 1 1 1 3 3

Frame 2 1 1 1 0 0 0 0 0 5 5 5

Frame 1 0 0 0 3 3 3 4 4 4 4 4 4

Miss/Hi Mis Mis Mis Mis Mis Mis Mis Hi Hi Mis Mis Hi
t s s s s s s s t t s s t

Number of Page Faults = 9

Case 2: Number of frames = 4

Request 0 1 5 3 0 1 4 0 1 5 3 4

Frame 4 3 3 3 3 3 3 5 5 5

Frame 3 5 5 5 5 5 5 1 1 1 1

Frame 2 1 1 1 1 1 1 0 0 0 0 4

Frame 1 0 0 0 0 0 0 4 4 4 4 3 3

Miss/Hit Miss Miss Miss Miss Hit Hit Miss Miss Miss Miss Miss Miss

Number of Page Faults = 10

Therefore, in this example, the number of page faults is increasing by increasing the number
of frames hence this suffers from Belady's Anomaly.
-------------------------------------FIFO-----------------------------------------------------------------
2) Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 given Let's analyse the behaviour of
FIFO algorithm in two cases.
Case 1: Number of frames = 3
Case 2: Number of frames = 4
Answer : PF 9 /PF 10

3) A program has five virtual pages, numbered from 0 to 4. If the pages are referenced
in the order 012301401234, with three page frames, the total number of page faults
with FIFO will be equal to: ?

With 3 page frame. The pages are referenced in the order 0 1 2 3 0 1 4 0 1 2 3 4.


-------------------------------------------------------------- 0 1 2 3 0 1 4 4 4 2 3 3 0 1 2 3 0 1 0 0 4 2
2 0 1 2 3 0 1 1 0 4 4 -------------------------------------------------------------- 1 2 3 4 5 6 7 -- -- 8 9

Therefore 9 page faults will be

GATE CSE 1993

Q. Consider the virtual page reference string 1, 2, 3, 2, 4, 1, 3, 2, 4, 1 On a demand paged


virtual memory system running on a computer system that main memory size of 3 pages
frames which are initially empty. Let LRU, FIFO and OPTIMAL denote the number of page
faults under the corresponding page replacements policy.
OPTIMAL < FIFO < LRU
Sol- First In First Out (FIFO) This is the simplest page replacement algorithm. In this
algorithm, operating system keeps track of all pages in the memory in a queue; oldest page is
in the front of the queue. When a page needs to be replaced page in the front of the queue is
selected for removal. Optimal Page replacement: in this algorithm, pages are replaced which
are not used for the longest duration of time in the future. Least Recently Used (LRU) In this
algorithm page will be replaced which is least recently used. Solution: the virtual page
reference string is 1, 2, 3, 2, 4, 1, 3, 2, 4, 1 size of main memory pages frames is 3.
For FIFO: total no of page faults are 6 (depicted in red)
For optimal: total no of page faults are 5 (depicted in red)

For LRU: total no of page faults are 9 (depicted in red)

The Optimal will be 5, FIFO 6 and LRU 9. so, OPTIMAL < FIFO < LRU option (B) is
correct answer.

GATE-CS-2014 (Set-1)    
Question -Assume that there are 3 page frames which are initially empty. If the page
reference string is 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6, the number of page faults using the optimal
replacement policy is__________.
Solution- In optimal page replacement replacement policy, we replace the place which is not
used for longest duration in future.
Given three page frames.
Reference string is 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6
Total page faults = 6 + 1 = 7
_______________________________________________________________________
GATE-CS-2007
A process has been allocated 3 page frames. Assume that none of the pages of the process are
available in the memory initially. The process makes the following sequence of page
references (reference string): 1, 2, 1, 3, 7, 4, 5, 6, 3, 1 If optimal page replacement policy is
used, how many page faults occur for the above reference string?
Optimal replacement policy looks forward in time to see which frame to replace on a page
fault. 1 23    -> 1,2,3 //page faults 173      ->7 143  ->4 153 -> 5 163  -> 6 Total=7 So Answer
is A . Page fault=7

GATE-CS-2014
Q- A system uses 3 page frames for storing process pages in main memory. It uses the Least
Recently Used (LRU) page replacement policy. Assume that all the page frames are initially
empty. What is the total number of page faults that will occur while processing the page
reference string given below? 4, 7, 6, 1, 7, 6, 1, 2, 7, 2
Explanation: What is a Page fault ? An interrupt that occurs when a program requests data
that is not currently in real memory. The interrupt triggers the operating system to fetch the
data from a virtual memory and load it into RAM. Now, 4, 7, 6, 1, 7, 6, 1, 2, 7, 2 is the
reference string, you can think of it as data requests made by a program. Now the system uses
3 page frames for storing process pages in main memory. It uses the Least Recently Used
(LRU) page replacement policy.
Hence, total number of page faults are 6. Therefore, C is the answer.
--------------------------------------------------------------------------------------------------
Question: A system uses 4 page frames for storing process pages in main memory.
Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. It uses the Least Recently Used (LRU) page
replacement policy. What is the total number of page faults ?
Answer- 8 page faults
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 (Red marks are page fault)
---------------------------------------------------------------------------------------------------------------
Consider a virtual page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1
Suppose a demand paged virtual memory system running on a computer system such that the
main memory has 3 page frames. Then __________ page replacement algorithm has
minimum number of page faults.
Ans- Optimal
1. In FIFO algorithm 15 page fault will occur.

1. In LIFO algorithm 11 page fault will occur.

1. In LRU algorithm 12 page fault will occur.

1. In optimal algorithm 9 page fault will occur.

Consider a reference string: 4, 7, 6, 1, 7, 6, 1, 2, 7, 2. the number of frames in the


memory is 3. Find out the number of page faults respective to:

1. Optimal Page Replacement Algorithm


2. FIFO Page Replacement Algorithm
3. LRU Page Replacement Algorithm

You might also like