Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2.7. [4 marks] Given a machine with 5 frames show the contents of each frame usi

ID: 3598063 • Letter: 2

Question

2.7. [4 marks] Given a machine with 5 frames show the contents of each frame using the following replacement algorithms on the reference string. Also say how many page faults would occur for each algorithm. Pages are brought in on demand and the initial load of a page counts as a page fault. b) LRU - Least Recently Used c) LFU - Least Frequently Used (if there are multiple pages with the same lowest frequency choose in a FIFO manner) d) Optimal (if there are multiple pages which are not used again choose in a FIFO manner) 0 1 Lay out your answer for each algorithm like this. A zero means the frame is free, an empty cell means the content of the frame is the same as in the previous step.

Explanation / Answer

FIFO --> The page which enters first in memory block that is first one to replace.

Number of page faults = 9

FIFO Layout

1

2

3

4

3

5

6

7

6

5

4

3

4

7

6

1

5

4

1

2

0

1

6

0

2

7

0

3

1

0

4

2

0

5

LRU --> Replace the page that has not been used for long time period(oldest page from the memory).

LRU Layout

1

2

3

4

3

5

6

7

6

5

4

3

4

7

6

1

5

4

1

2

0

1

6

0

2

7

2

0

3

5

0

4

0

5

1

Number of page faults = 10

LFU --> Replace the page that is lowest frequently used and to in FIFO manner.Frequency will be reset, if it was replaced.

LFU Layout

1

2

3

4

3

5

6

7

6

5

4

3

4

7

6

1

5

4

1

2

0

1

6

0

2

7

0

3

5

2

0

4

0

5

1

At point of inserting "1" --> 6 comes 3 times, 7 comes 2 times, 3 comes 2 times, 4 comes 3 times and 5 comes 2 times and its second time usage is oldest so replace 5 with 1 and reset count of "5" to "0". next page will be replaced is 3 with 5 and reset count of "3" since it is replaced. Replace 5 with 2 since its frequency is "1" and it is the lowest compared to others.

Number of page faults = 10

Optimal --> Replace the page that will not be used for longest period of time.

Optimal Layout

1

2

3

4

3

5

6

7

6

5

4

3

4

7

6

1

5

4

1

2

0

1

6

0

2

7

2

0

3

1

0

4

0

5

Replace 1 with 6 because "1" is not used that much for the next page compare to other pages and than replace 2 with 7 and next change is at 1 and it gets replaced by 3 and than 2 is replaced by 7.
Number of page faults = 9.

1

2

3

4

3

5

6

7

6

5

4

3

4

7

6

1

5

4

1

2

0

1

6

0

2

7

0

3

1

0

4

2

0

5