Professional Documents
Culture Documents
Name:
Ahmad Saleem
Roll No.:
18144156-052
Semester:
4th(Evening)
Department:
Information Technology(IT)
Submitted To:
Mr. Sohail Baber
On the other hand, if you have a large number of items that are referenced
essentially randomly, or some items are accessed slightly more often than,
or items are typically referenced in batches (i.e. item A is accessed many
times over a short period, and then not at all), then an LRU cache eviction
scheme will likely be better.
• MFU implementation is fairly expensive.
• It do not approximate OK replacement very well.
1|Page
Page replacement algorithm (MFU)
Example:
Ref String:
1 3 3 2 5 2 1 4 2 2 5
F0 1 1 1 1 1 1 1 4 4 4 4
F1 3 3 3 5 5 5 5 5 5 5
F2 2 2 2 2 2 2 2 2
f f h
f f h h
f h h h
Frequencies:
1 , 2 , 3 , 4 , 5
0 0 0 0 0
1 1 1 1 1
2 2 2 2
0 3 0
4
Page Fault: 05
Page Hit: 06
Page fault probability: (5/11)*100= 45.45%
2|Page
Page replacement algorithm (MFU)
Code:
#include<stdio.h>
#include<conio.h>
struct node
{
int pno,freq;
}frames[20];
int n;
int page_found(int pno)
{
int fno;
for(fno=0;fno<n;fno++)
if(frames[fno].pno==pno)
return fno;
return -1;
int get_free_frame()
{
int fno;
for (fno=0; fno<=n; fno++)
if (frames[fno].pno==-1)
return(fno);
return(-1);
}
int get_mfu_frame()
{
int fno;
3|Page
Page replacement algorithm (MFU)
int selfno=0;
for (fno=1; fno<n; fno++)
if(frames[fno].freq>frames[selfno].freq)
selfno=fno;
return selfno;
}
void main()
{
int p_request[]={5,8,10,14,10,9,5,10,8,5,1,10,9,12,10};
int size=15;
int page_falts=0,i,j,fno;
clrscr();
printf("\nHow many frames:"); scanf("%d",&n);
for (i=0; i<n; i++)
{
frames[i].pno=-1
frames[i].freq=0;
}
printf("\nPageNo Page Frames Page Fault");
printf("\n---------------------------------------------------");
for(i=0;i<size;i++)
{
j=page_found(p_request[i]);
if(j==-1)
{
j=get_free_frame();
if (j==-1)
j=get_mfu_frame();
4|Page
Page replacement algorithm (MFU)
page_falts++;
frames[j].pno=p_request[i];
frames[j].freq=1;
printf("\n%4d\t ",p_request[i]);
for (fno=0; fno<n; fno++)
printf("%4d:%2d",frames[fno].pno,frames[fno].freq);
printf(" : YES");
}
else //page found in frame j
{
printf("\n%4d\t ",p_request[i]);
frames[j].freq++;
for (fno=0; fno<n; fno++)
printf("%4d:%2d",frames[fno].pno,frames[fno].freq);
printf(" : NO");
}
}
printf("\n-------------------------------------------------------");
printf("\n Number of Page_Falts=%d",page_falts);
getch();
}
5|Page