edited by
4,293 views
1 votes
1 votes

Consider that a process has been allocated $3$ frames and has a sequence of page referencing as $1, 2, 1, 3, 7, 4, 5, 6, 3, 1$. What shall be the difference in page faults for the above string using the algorithms of LRU and optimal page replacement for referencing the string?

  1. $2$
  2. $0$
  3. $1$
  4. $3$
edited by

4 Answers

1 votes
1 votes

LRU Algorithm :- Replace the least recently used page if frames are not empty.

$$\overset{\text{frames}}{\begin{array}{|c|}\hline
\textbf{f1}&    \\\hline
\textbf{f2}&        \\ \hline   
\textbf{f3}&       \\     \hline
\end{array}} \qquad \overset{\text{1}}{\begin{array}{|c|}\hline
\textbf{1}_L&    \\\hline
\textbf{ }&        \\ \hline   
\textbf{ }&       \\     \hline
\end{array}}\overset{\text{2}}{\begin{array}{|c|}\hline
\textbf{1}_L&    \\\hline
\textbf{2}&        \\ \hline   
\textbf{ }&       \\     \hline
\end{array}}\overset{\text{1}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{2}_L&        \\ \hline   
\textbf{ }&       \\     \hline
\end{array}}\overset{\text{3}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{2}_L&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}\overset{\text{7}}{\begin{array}{|c|}\hline
\textbf{1}_L&    \\\hline
\textbf{7}&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}\overset{\text{4}}{\begin{array}{|c|}\hline
\textbf{4}&    \\\hline
\textbf{7}&        \\ \hline   
\textbf{3}_L&       \\     \hline
\end{array}}\overset{\text{5}}{\begin{array}{|c|}\hline
\textbf{4}&    \\\hline
\textbf{7}_L&        \\ \hline   
\textbf{5}&       \\     \hline
\end{array}}\overset{\text{6}}{\begin{array}{|c|}\hline
\textbf{4}_L&    \\\hline
\textbf{6}&        \\ \hline   
\textbf{5}&       \\     \hline
\end{array}}\overset{\text{3}}{\begin{array}{|c|}\hline
\textbf{3}&    \\\hline
\textbf{6}&        \\ \hline   
\textbf{5}_L&       \\     \hline
\end{array}}\overset{\text{1}}{\begin{array}{|c|}\hline
\textbf{3}&    \\\hline
\textbf{6}_L&        \\ \hline   
\textbf{1}&       \\     \hline
\end{array}}$$ 

$X_L$ denotes the frame to be replaced.

$\therefore$ Total page faults $= 9$


Optimal Page Replacement Algorithm :- Replace the page which will not be used for longest duration of time if the frames are not empty.

$$\overset{\text{frames}}{\begin{array}{|c|}\hline
\textbf{f1}&    \\\hline
\textbf{f2}&        \\ \hline   
\textbf{f3}&       \\     \hline
\end{array}} \qquad \overset{\text{1}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{ }&        \\ \hline   
\textbf{ }&       \\     \hline
\end{array}}\overset{\text{2}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{2}&        \\ \hline   
\textbf{ }&       \\     \hline
\end{array}}\overset{\text{1}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{2}&        \\ \hline   
\textbf{ }&       \\     \hline
\end{array}}\overset{\text{3}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{2}_R&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}\overset{\text{7}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{7}_R&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}\overset{\text{4}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{4}_R&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}\overset{\text{5}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{5}_R&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}\overset{\text{6}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{6}_R&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}\overset{\text{3}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{6}_R&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}\overset{\text{1}}{\begin{array}{|c|}\hline
\textbf{1}&    \\\hline
\textbf{6}_R&        \\ \hline   
\textbf{3}&       \\     \hline
\end{array}}$$ 

$X_R$ denotes the frame to be replaced.

$\therefore$ Total page faults $= 7$


$\therefore$ Difference in LRU and Optimal Page Replacement  page faults

$= (9 - 7)$

$=2$

$\therefore$ Option $A.$ is the correct answer.

 

0 votes
0 votes

                                                                        Frame Sequence : 1,2,1,3,7,4,5,6,3,1

 Least Recently Used(LRU)  : A Greedy algorithm where the page to be replaced is least recently used.

f1      f2     f3

1       2       3

4            5

3       6       1

Total no. of Page fault = 9

Optimal Page Replacement : In this algorithm, pages are replaced which would not be used for the longest duration of time in the future.

f1      f2     f3

1       2      3

         7

         4

         5

         6

Total no. of Page fault = 7

 

Difference in LRU and Optimal Page fault = (9 - 7)

=2

Hence (1) is correct option.

Reference: Page Replacement Algorithm

0 votes
0 votes
option: (A) 2

From LRU(least recently used)algorithm ,page fault=9

From optimal page replacement algorithm,page fault=7

Difference=2
Answer:

Related questions

2 votes
2 votes
1 answer
2