FIFO Page Replacement Algorithm - Scaler Topics (2024)

Overview

As the name suggests, FIFO is based on the “First in First out“ principle which clearly states that the oldest (first) entry, or “head” of the queue, is processed first just like the queues in movie theatres a ticket. FIFO page replacement algorithm is involved in memory management when new pages in a queue are demanded, to replace the existing page with the new page.

What is the FIFO Page Replacement Algorithm?

FIFO which is also known as First In First Out is one of the types of page replacement algorithm. The FIFO algorithm is used in the paging method for memory management in an operating system that decides which existing page needs to be replaced in the queue.

FIFO algorithm replaces the oldest (First) page which has been present for the longest time in the main memory.

In simple words, When a new page comes in from secondary memory to main memory, It selects the front of the queue which is the oldest page present, and removes it.

Why do we need to swap the pages?: Since we have a fixed number of frames and all the processes cannot be stored in the main memory at a single time we use page replacement algorithms to store pages of a process instead of the whole process.

How Does FIFO Page Replacement Work?

FIFO is implemented in the operating system by keeping track of all the pages in a queue. The newest page is at the head of the queue and the oldest (first) page is in the tail.

"To illustrate how the FIFO page replacement algorithm works in a real-life, Consider you are the owner of a supermarket which has N number of shelves to put exactly N different products.

One day, A company launches a new convenience powdered milk, organic food, and glass noodles that can be reconstituted in a microwave oven. So in order to sell the new products, you need to get rid of one old product. Now you have to find out which product you should eliminate from your store, So you need to find the product the supermarket has been stocking the longest. After finding the product, Just like the FIFO algorithm, the one at the front of the list is removed whereas the new one goes on the back of the list i.e. the reconstituted products.”

  1. The OS maintains a list of all pages which are residing in the memory.
  2. When a new page is brought from the secondary memory.
  3. The new page requests the main memory.
  4. On a page fault, the head of the list i.e. the oldest will be removed.
  5. The new page will be added at the tail of the list.

Page Fault: A page fault occurs when a page requested by a program running in the CPU is not present in the main memory, but in the address page of that program. A page fault generally creates an alert for the OS.

FIFO Page Replacement Algorithm - Scaler Topics (1)

Consider the above flow diagram for a better understanding of the FIFO page replacement algorithm in os.

FIFO Pseudocode

Here,

  • 'P' is used to represent pages.
  • 'N' is the number of pages.
  • 'C' is the Capacity.

Implementation of FIFO Page Replacement Algorithm Using A Programming Language

Step 1. Start to traverse the pages.Step 2. If the memory has less pages than capacity; else goes to step 6.Step 3. ==Push== the pages in set one at a time until the size of the set does not overflow or all page requests are fulfilled.Step 4. Increment the PF (page fault) and ==return==.Step 5. If that current page is already available in the memory, do nothing.Step 6. Else, ==Pop== and Replace the topmost page in the queue which is inserted first with the page (current) from the string.Step 7. Increase the PF(page faults) and ==stop==.

Output:

The total number of page faults are: 6

Example of FIFO Page Replacement Algorithm

Q. Consider a page reference string 1, 3, 0, 3, 5, 6 with 3-page frames. To find the number of page faults?

FIFO Page Replacement Algorithm - Scaler Topics (2)

Total Page Fault = 6.

Consider the steps below,

    • Initially, Since all the slots are empty, therefore, the first 3 elements 0, 3, 1 are allocated to the empty slots due to which the Page faults become 3.
    • After the 0, 3, and 1 element 3 comes, But now 3 is already present. So the Page faults become 0.
    • Now when 5 comes which is not available in the memory the oldest page slot 1 will be replaced. So the Page faults become 1.
    • After that 6 comes, 6 is also not present so it also gets replaced with the oldest page i.e. 3. The Page faults becomes 1.
    • At last, element 3 arrives which is not present, Hence it is replaced by element 0. So the page faults become 1.

Advantages of FIFO Page Replacement Algorithm

  • The FIFO page replacement algorithm is commonly known for its simplicity.
  • The FIFO algorithm is much easier to implement as well as understand.
  • Small systems can use the FIFO algorithm efficiently.

Disadvantages of FIFO Page Replacement Algorithm

  • FIFO algorithm in os uses an additional ==Queue== data structure.
  • It suffers from ==Belady's anomaly== problem i.e when the number of page frames increases, more memory is given to processes, but instead of decreasing, the number of page faults increases.

Note: Belady's anomaly can be prevented using stack-based algorithms like LRU.

Conclusion

  • In this article, we have discussed how it works with real-life examples and demonstrated the FIFO algorithm on the code level.
  • FIFO page replacement algorithm in os is responsible for keeping track of all the pages in a queue.
  • It is also responsible for maintaining all the pages in a queue for an operating system.
  • FIFO page replacement algorithm is a good choice When the number of incoming pages is few. Otherwise, It’s not the best replacement algorithm to use practically.

Operating systems are the backbone of modern computing. Join our free Operating System full course and become proficient in operating systems.

FIFO Page Replacement Algorithm - Scaler Topics (2024)

FAQs

FIFO Page Replacement Algorithm - Scaler Topics? ›

FIFO algorithm replaces the oldest (First) page which has been present for the longest time in the main memory. In simple words, When a new page comes in from secondary memory to main memory, It selects the front of the queue which is the oldest page present, and removes it.

What is the algorithm for page replacement using FIFO? ›

First In First Out (FIFO) -This algorithm is similar to the operations of the queue. All the pages are stored in the queue in the order they are allocated frames in the main memory. The one which is allocated first stays in the front of the queue. The one which is allocated the memory first is replaced first.

What is the drawback of the FIFO page replacement strategy? ›

Poor performance: FIFO page replacement algorithm can suffer from poor performance, especially when the number of page faults is high. Belady's Anomaly: FIFO page replacement algorithm can result in a situation known as Belady's Anomaly, where the number of page faults can increase as the number of frames increases.

What is the most effective page replacement algorithm? ›

The theoretically optimal page replacement algorithm (also known as OPT, clairvoyant replacement algorithm, or Bélády's optimal page replacement policy) is an algorithm that works as follows: when a page needs to be swapped in, the operating system swaps out the page whose next use will occur farthest in the future.

How many page faults are there in the FIFO page replacement algorithm? ›

A page fault happens when a running program accesses a memory page that is mapped into the virtual address space but not loaded in physical memory. Hence the correct answer is 15.

What is the most recently used page replacement algorithm? ›

MRU (most recently used)

MRU page replacement algorithm is the counterpart to the LRU algorithm. Instead of replacing the least recently used page, MRU replaces the most recently used page. The underlying idea is that the page that has been most recently used is likely to be accessed again in the near future.

What does a FIFO replacement algorithm associates with each page? ›

Explanation: FIFO algorithm associates with each page the time when the page was brought into memory.

When should you not use FIFO? ›

The FIFO method is not a suitable measure when you have inventory purchases or production with fluctuating prices. Inaccurately stated profits will often appear for the same period because you have different costs recorded for the same goods during that matching period.

What is the main disadvantage of FIFO? ›

What Are the Disadvantages of FIFO? The FIFO method can result in higher income tax for a business to pay, because the gap between costs and profit is wider (than with LIFO). A company also needs to be careful with the FIFO method in that it is not overstating profit.

What does FIFO page replacement suffer by? ›

FIFO replacement policy suffer from the problem Belady's Anomaly. The FIFO also replaces the resident page that has spent the longest time in memory.

Is FIFO better than LRU for page replacement? ›

FIFO-Reinsertion and 2-bit CLOCK are more efficient than LRU, with a lower miss ratio on most traces.

What is an example of FIFO in operating system? ›

The first job that came in gets done first. For example, if you ask the computer to print a document and then copy a file, the computer will start printing it first because you asked for it first. In memory management, the computer uses FIFO first to decide which program to load.

Which page replacement algorithm is least frequently used? ›

The LFU page replacement algorithm stands for the Least Frequently Used. In the LFU page replacement algorithm, the page with the least visits in a given period of time is removed. It replaces the least frequently used pages. If the frequency of pages remains constant, the page that comes first is replaced first.

Which page will FIFO replace? ›

FIFO algorithm replaces the oldest (First) page which has been present for the longest time in the main memory.

What is the FIFO policy for page replacement? ›

First In First Out (FIFO) :

This is the simplest page replacement algorithm. In this algorithm, the operating system keeps track of all pages in the memory in a queue, the oldest page is in the front of the queue. When a page needs to be replaced page in the front of the queue is selected for removal.

What is the FIFO algorithm in Java? ›

FIFO stands for First In First Out, in which we will enter the data elements into the data structure; the data element added at last in any data structure will be removed out last and the element added first will be removed first.

What is LRU and FIFO? ›

FIFO means First In, First Out, i.e., consider (in this case delete) elements strictly in arrival order. LRU is Least Recently Used, the cache element that hasn't been used the longest time is evicted (on the hunch that it won't be needed soon).

What is second chance FIFO page replacement algorithm? ›

The second chance algorithm is a page replacement policy that uses a FIFO algorithm and a hardware-provided reference bit. The page table is traversed in a FIFO (circular queue) manner. If a page table is found with its reference bit not set, then that page is selected as the next victim.

What is the relationship between FIFO and clock page replacement algorithms? ›

The relationship between FIFO and clock page replacement algorithms is that both treat the page frames allocated to a process as a circular buffer, with which a pointer is associated.

Top Articles
Latest Posts
Article information

Author: Domingo Moore

Last Updated:

Views: 6646

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.