edited by
2,558 views
24 votes
24 votes

Assume a demand paged memory system where ONLY THREE pages can reside in the memory at a time. The following sequence gives the order in which the program references the pages.
         $1, 3, 1, 3, 4, 2, 2, 4$
Assume that least frequently used page is replaced when necessary. If there is more than one least frequently used pages then the least recently used page among them is replaced. During the program’s execution, how many times will the pages $1,2,3$ and $4$ be brought to the memory?

  1. $2,2,2,2$ times, respectively
  2. $1,1,1,2$ times, respectively
  3. $1,1,1,1$ times, respectively
  4. $2,1,2,2$ times, respectively
  5. None of the above
edited by

3 Answers

Best answer
30 votes
30 votes

Page reference order: $1,3,1,3, 4,2,2,4$

First $2$ pages causes page fault. i.e., $1$ and $3$

Next $2$ pages no fault.

Next page i.e., $4$ fault occurs.

Now for page no. $2$ we have fault. We will replace less frequently used i.e., $4$

Next page is again $2$ so no. page fault.

Now page no. $1 2$ and $3$ all are used $2$ times so, we will replace page $1$ to accomodate page $4$ (least recently used is $1$)

So, page $1 2 3$ are brought once in memory and page $4$ is brought two times. So, answer is (B).

edited by
21 votes
21 votes

Step 1 :- Demand of page 1 , which is not present in memory.

    1
 
 

Step 2 :- Demand of page 3 , which is not present in memory.

    1
    3
 

Step 3 :- Demand of page 1 , which is already present in memory.

Step 4 :- Demand of page 3 , which is already present in memory.

Step 5 :- Demand of page 4 , which is not present in memory.

   1
   3
   4

Step 6 :- Demand of page 2 , which is not present in memory.

Here we don't have any free frame left in physical memory , so we have to remove some frame based on least frequently used page replacement algorithm.

page 1 : frequency =2 (used two times)

Page 3 : frequency=2  (used two times)

page 4 : frequency=1 (used one time)          // least frequently used so this wil be selected for replacement.

   1
   3
   2

Step 7 :- Demand of page 2 , which is already present in memory.

Step 8 :- Demand of page 4 , which is not present in memory.

page 1 :- frequency =2 (used two times)

page 3 :-frequency =2 (used two times)

page 2 :-frequency =2 (used two times)

Here when everyone has same frequency so use help of least recently used page replacement algorithm. Here we can see page 1 is the least recently used page so replace this with page 4.

   4
   3
   2

Now we can observe , which page is brought , how many number of times in main memory.

The pages $1,2,3$ and $4$ be brought to the memory $1,1,1,2 $ times, respectively.

0 votes
0 votes

So, answer is option (B)

     1   is brought once (1)

     2   is brought once (1)

     3   is brought once (1)

     4   is brought twice (2)

 

  1

3

1

3

4

2

2

4

  1

1

 

 

1

1

 

4

 

3

 

 

3

3

 

3

 

 

 

 

4

2

 

2

edited by
Answer:

Related questions

18 votes
18 votes
5 answers
1
makhdoom ghaya asked Nov 4, 2015
1,574 views
An unbiased die is thrown $n$ times. The probability that the product of numbers would be even is$\dfrac{1}{(2n)}$$\dfrac{1}{[(6n)!]}$$1 - 6^{-n}$$6^{-n}$None of the abov...
27 votes
27 votes
3 answers
3
makhdoom ghaya asked Nov 8, 2015
3,201 views
In a relational database there are three relations:$Customers = C\textsf{(CName)}$,$Shops = S \textsf{(SName)}$,$Buys = B\textsf{(CName, SName)}$.Which of the following r...