![]() |
VOOZH | about |
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. This is counterintuitive because having more frames should theoretically reduce page faults, as more pages can be stored in memory.
In this article, we demonstrate Belady's Anomaly using FIFO page replacement algorithm.
1. Reference array is: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Output :
When number of frames is 3, page fault : 9
When number of frames is 4, page fault : 10
2. Reference array is: 0, 1, 5, 3, 0, 1, 4, 0, 1, 5, 3, 4
Output :
When number of frames is 3, page fault : 9
When number of frames is 4, page fault : 10
FIFO page replacement algorithm is used to showcase the Belady's Anomaly. Firstly, an array of size equal to the number of frames is used, this array simulates the page frames, the operations on this array are performed in a circular array type fashion. A count variable is used to calculate the page fault, this variable is incremented whenever an element is inserted / rewritten in the page frame array.
In this code:
Two frame sizes 3 and 4 are tested respectively, with increase in number of frames the page faults should have decreased, but an anomaly is witnessed as 3 frames result in 9 page faults whereas 4 frames result in 10 page faults. This is Belady's Anomaly, it is observed in special cases of reference array and frame size.
When the number of frames are: 3, the number of page faults is : 9 When the number of frames are: 4, the number of page faults is : 10