Open In App

Most Frequently Used (MFU) Algorithm in Operating System

Last Updated : 06 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

MFU Algorithm is a Page Replacement Algorithm in the Operating System that replaces the page accessed a maximum number of times in the past. If more than one page is accessed the same number of times, then the page which occupied the frame first will be replaced.

Page Replacement

It is a technique of replacing a data block (frame) of Main Memory with the data block (page) of Secondary Memory when all the frames of Main Memory are occupied and CPU demands for the data block which is not available inside Main Memory, technically, when Page Fault occurs.

Example:

Consider a Main Memory with a number of frames = 4 and the following are the data block access requests made by the CPU.

CPU Requests – 7, 0, 1 , 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1

Given, the number of frames = 4. Initially, all are empty

Page Replacement Using the Most Frequently Used (MFU) Algorithm

(i) The 4 frames are initially empty, the first 4 blocks occupy them.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

First four blocks occupy the 4 frames

First four blocks occupy the 4 frames

(ii) Block 0 has already occupied the frame.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

Next Iteration

(iii) Block 0 is accessed maximum times, so replaced with incoming Block 3.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

Next Iteration

Block 0 replaced with Block 3

(iv) Blocks 2,1,3,7 are accessed once and Block 7 occupied the frame first, so, Block 7 replaced with incoming Block 0.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

next iteration

Block 7 replaced with Block 0

(v) Block 0 is accessed maximum times so replaced with incoming Block 4.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

Block 0 replaced with Block 4

Block 0 replaced with Block 4

(vi) Blocks 2,3 have already occupied the frame.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

next iteration

(vii) Block 2 and Block 3 are accessed maximum times and Block 2 occupied the frame first, so, Block 2 replaced with incoming Block 0.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

Block 2 replaced with Block 0

Block 2 replaced with Block 0

(viii) Block 3 has already occupied the frame.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

next iteration

(ix) Block 0 is accessed maximum times so replaced with incoming Block 2.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

Block 0 replaced with Block 2

Block 0 replaced with Block 2

(x) Block 1 has already occupied the frame.

7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 , 1

Final Image

Final Image

Conclusion

All the data block access requests made by CPU are completed using Most Frequently Used (MFU) Algorithm. In this algorithm, as most frequently accessed page is replaced, this increases the number of Page Faults. Number of Page Faults for above example are 5+4 = 9 page faults.

Frequently Asked Questions

Q.1: What is a data block in Operating System?

Answer:

The memory in Operating System consists of data blocks which contains data in bytes/words. Every data block has the same size.

Q.2: What is a Frame and a Page in Operating System?

Answer:

The Main Memory is made up of data blocks called Frames. The Secondary Memory is made up of data blocks called Pages. Frame size = Page size.

Q.3: What is a Page Fault in Operating System and why does it occur?

Answer:

Absence of a particular page is known as Page Fault. It occurs when CPU demands for a page which is not present inside the Main Memory.

Q.4: How does Operating System deals with Page Fault?

Answer:

When Page Fault occurs, it brings that page from Secondary Memory to Main Memory so that CPU can access it. If all the frames of Main Memory are occupied with data, it replaces the page using replacement algorithms.

Q.5: Other than Most Frequently Used (MFU) Algorithm, what are some other Page Replacement Algorithms in Operating System?

Answer:

Some of the Page Replacement Algorithms include First In First Out, Last In First Out, Most Recently Used, Least Recently Used, Optimal Page Replacement, etc.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads