The First-In, First-Out (FIFO) Page
Replacement Algorithm
Another
low-overhead paging algorithm is the FIFO (First-In,
First-Out) algorithm. To illustrate how this works, consider a supermarket
that has enough shelves to display exactly k different products.
One day, some company introduces a new convenience food—instant, freeze-dried,
organic yogurt that can be reconstituted in a microwave oven. It is an
immediate success, so our finite supermarket has to get rid of one old product
in order to stock it.
One
possibility is to find the product that the supermarket has been stocking the
longest (i.e., something it began selling 120 years ago) and get rid of it on
the grounds that no one is interested any more. In effect, the supermarket
maintains a linked list of all the products it currently sells in the order
they were introduced. The new one goes on the back of the list; the one at the
front of the list is dropped.
As
a page replacement algorithm, the same idea is applicable. The operating system
maintains a list of all pages currently in memory, with the page at the head of
the list the oldest one and the page at the tail the most recent arrival. On a
page fault, the page at the head is removed and the new page added to the tail
of the list. When applied to stores, FIFO might remove mustache wax, but it
might also remove flour, salt, or butter. When applied to computers the same
problem arises. For this reason, FIFO in its pure form is rarely used.
Write your own example :P
#include<stdio.h>#include<conio.h>
void main()
{
int a[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1;
char f='F';
clrscr();
printf("Enter the Number of Pages:");
scanf("%d",&n);
printf("Enter %d Page Numbers:",n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
}
}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
}
p=0;
for(k=0;k<q1;k++)
{
if(b[i+1]==a[k])
p=1;
}
}
printf("\nNo of faults:%d",m);
getch();
}
OUTPUT
No comments:
Post a Comment