AfterAcademy Tech
•
07 Apr 2020

In general, if we think the page faults should directly depend on the frame size. Like if the frame size is more then there are more pages of the processes available at any time in the memory. This would mean that the number of hits would increase. But, this is not the case in the FIFO page replacement algorithm. So, let's start the blog and understand why FIFO suffers from Belady’s Anomaly and what is this Belady's Anomaly?
In this page replacement algorithm, the OS maintains a queue that keeps track of all the pages in memory, with the oldest page at the front and the most recent page at the back.
When there is a need for page replacement, the FIFO algorithm, swaps out the page at the front of the queue, that is the page which has been in the memory for the longest time will be swapped. Now let's take an example and understand Belady’s Anamoly.
Example:
Consider the page reference string of size 12: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 with frame size 3(i.e. maximum 3 pages in a frame).

Total Page Fault = 9
Page Fault ratio = 9/12 i.e. total miss/total possible cases
Hit ratio= 3/12 i.e total hit/ total possible cases
Now, let's see what happens when we increase the frame size from 3 to 4.

Total Page Fault = 10
Page Fault ratio = 10/12 (total miss/total possible cases)
Hit ratio= 2/12 (total hit/ total possible cases)
So, here as we are increasing the frame number the hit ratio should increase because now more pages of processes are available in the memory at a time. So, the chances of hits should increase but here the opposite is happening. The hit ratio is decreasing in place of increasing although we have increased the frame size. This is called Belady’s Anamoly. This problem comes in FIFO page algorithms. However, this unusual behavior is only observed sometimes. It doesn't mean that every time the frame size is increased the page faults will increase.
LRU and Optimal Page Replacement algorithm doesn't suffer from this problem. In these algorithms, the page faults decrease as the frame size is increased.
This was about Belady's Anomaly. Hope you learned something new today.
Do share this blog with your friends to spread the knowledge. Visit our YouTube channel for more content. You can read more blogs from here.
Keep Learning 🙂
Team AfterAcademy!
AfterAcademy Tech
In this blog, we will discuss Dijkstra's Algorithm. We will discuss what is the Dijkstra's Algorithm, how can we find the shortest path from source to other vertices using Dijkstra's Algorithm in Graph, Illustration using an example, its pseudo-code.

AfterAcademy Tech
In this blog, we will see one of the deadlock avoidance methods i.e. Banker's Algorithm. In this algorithm, we will discuss that if we are given the number of resources available and the number of resources required by the process then we can tell that if the system will go in deadlock or not. We will understand this concept with the help of an example.

AfterAcademy Tech
You are given a string S and its length L and you need to sort its characters based on their frequency. The characters in the output will be distinct and ordered based on their frequency in S, higher frequency comes first.

AfterAcademy Tech
Write a program to check whether the two strings are an anagram of each other or not. Like, "s" is an anagram of "t" if the characters of "s" can be rearranged to form "t". This simple problem will let you understand the concepts of string manipulation.
