Counting Based Page Replacement Algorithm in Operating System Last Updated : 16 Oct, 2023 Comments Improve Suggest changes Like Article Like Report Counting Based Page Replacement Algorithm replaces the page based on count i.e. number of times the page is accessed in the past. If more than one page has the same count, then the page that occupied the frame first would be replaced. Page Replacement: Page Replacement 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 that is not available inside Main Memory. Technically, when a Page Fault occurs. Two Types of Counting-Based AlgorithmsMost Frequently Used (MFU) Algorithm: It replaces the page with a count greater than other pages i.e. which is accessed a maximum number of times in the past. Least Frequently Used (LFU) Algorithm: It replaces the page with a count lesser than other pages i.e. which is accessed a minimum number of times in the past. ExampleConsider 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, 7, 3, 2, 1Given, the number of frames = 4. Initially, all are empty Using Least Frequently Used (LFU) Algorithm(i) The 4 frames are initially empty, the first 4 blocks occupy them.7 , 0 , 1 , 2 , 0, 3, 0, 4, 2, 3, 7, 3, 2, 1 (ii) Block 0 has already occupied the frame.7 , 0 , 1 , 2 , 0 , 3, 0, 4, 2, 3, 7, 3, 2, 1 (iii) Blocks 2,1,7 are accessed least (once) and Block 7 occupied the frame first, so, Block 7 replaced with incoming Block 3.7 , 0 , 1 , 2 , 0 , 3 , 0, 4, 2, 3, 7, 3, 2, 1 Block 7 replaced with Block 3 (iv) Blocks 3,0 have already occupied the frame.7 , 0 , 1 , 2 , 0 , 3 , 0 , 4, 2, 3, 7, 3, 2, 1 (v) Blocks 2,1,3 are accessed least (once) and Block 1 occupied the frame first, so, Block 1 replaced with incoming Block 4.7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2, 3, 7, 3, 2, 1 Block 1 replaced with Block 4 (vi) Blocks 2,3 have already occupied the frame. 7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 7, 3, 2, 1 (vii) Block 4 is accessed minimum times (once) so replaced with incoming Block 7. 7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 7 , 3, 2, 1 Block 4 replaced with Block 7 (viii) Blocks 3,2 have already occupied the frame. 7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 7 , 3 , 2 , 1 (ix) Block 7 is accessed minimum times (twice) so replaced with incoming Block 1.7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 7 , 3 , 2 , 1 Block 7 replaced with Block 1Number of Page faults = Number of blocks not already present and brought inside Main Memory Page faults for the above example = 8Please refer:- Example using Most Frequently Used (MFU) Algorithm to know how MFU algorithm works.Comparing MFU and LFU Counting Based AlgorithmsMost Frequently Used Least Frequently Used Replaces page which is accessed maximum number of times. Replaces page which is accessed minimum number of times. Since most frequently page is replaced, this increases the number of page faults as in future the page has higher chances to be accessed again Since least frequently page is replaced, this decreases the number of page faults as in future the page has lower chances to be accessed again. Comment More infoAdvertise with us Next Article Counting Based Page Replacement Algorithm in Operating System S shetyeanuja2000 Follow Improve Article Tags : Operating Systems Geeks Premier League Geeks Premier League 2023 Similar Reads Page Replacement Algorithms in Operating Systems In an operating system that uses paging for memory management, a page replacement algorithm is needed to decide which page needs to be replaced when a new page comes in. Page replacement becomes necessary when a page fault occurs and no free page frames are in memory. in this article, we will discus 7 min read Page Buffering Algorithm in Operating System The Page Buffering Algorithm is used in Operating systems and Database Management Systems as a key method to streamline data access and minimize disc I/O operations. It is largely used in virtual memory systems, where data is kept on secondary storage (disc) and brought into main memory as needed.Th 7 min read Difference Between LRU and FIFO Page Replacement Algorithms in Operating System Page replacement algorithms are used in operating systems to manage memory effectively. Page replacement algorithms are essential in operating systems for efficient memory management. These algorithms select which memory pages should be changed when a new page is brought. Least Recently Used (LRU) a 3 min read Page Fault Handling in Operating System A page fault occurs when a program attempts to access data or code that is in its address space but is not currently located in the system RAM. This triggers a sequence of events where the operating system must manage the fault by loading the required data from secondary storage into RAM. Page fault 5 min read Belady's Anomaly in Page Replacement Algorithms Belady's Anomaly is a phenomenon in operating systems where increasing the number of page frames in memory leads to an increase in the number of page faults for certain page replacement algorithms. Normally, as more page frames are available, the operating system has more flexibility to keep the nec 11 min read Like