/* * LFU.java (Implements Least Frequently Used Algorithm to find a * the victim page.) * * Written by : Nitin Motgi (nmotgi@cs.ucf.edu) * * Portions copyright(c) 2001 to School of Electrical Engineering and * Computer Science, UCF, Orlando. * * Use and distribution of this source code are strictly governed by * terms and conditions set by the authors. * * $Id : LFU.java, v1.0.0 03/14/2001. $ * * Revision History: * * 1. Created basic structure Nitin, v1.0.0 03/17/2001. * 2. Added Documentation. Nitin, v1.0.1 03/17/2001. * 3. Final Documentation Check. Nitin, v1.4.3 03/26/2001. * 4. Final Variable Name Check. Nitin, v1.4.4 03/26/2001. * 5. Final Functionality Check. Nitin, v1.4.5 03/26/2001. */ /* Import some of the libraries.*/ import java.lang.*; import java.util.*; import java.io.*; /* This class implements Least Frequently Used (LFU) to pick up the victim page out from the frame. A timing mechanism is implemented which stamps the page with current time, whenever the page is accessed and when it has to remove one of the pages to fit in the current one, it uses the one which has not been accessed for quite a long time.*/ class LFU extends PagingAlgorithm{ String[][] szRequest; int nPageSize; int nNoOfRequest; public LFU(String[][] szRequest,int nNoOfRequest, int nNoOfFrames, int nPageSize,boolean bDebug){ this.szRequest = szRequest; this.nNoOfRequest = nNoOfRequest; this.nPageSize = nPageSize; super.nNoOfFrames = nNoOfFrames; super.bDebug = bDebug; super.Create(); }/* End of constructor.*/ public void read(int nProgName, int nPageIndex,int nAddress){ super.read(nProgName, nPageIndex, nAddress); }/* End of read.*/ public void load(int nProgName, int nProgSize){ super.load(nProgName, nProgSize, nPageSize); }/* End of read.*/ public void write(int nProgName, int nPageIndex,int nAddress){ super.write(nProgName, nPageIndex, nAddress); }/* End of read.*/ public void unload(int nProgName){ super.unload( nProgName); }/* End of read.*/ public void Start(){ System.out.println("Using LFU ..."); for(int nIndex=2; nIndex < nNoOfRequest; nIndex++){ if(szRequest[nIndex][0].equals("load")) load(Integer.parseInt(szRequest[nIndex][1]), Integer.parseInt(szRequest[nIndex][2])); if(szRequest[nIndex][0].equals("read")) read(Integer.parseInt(szRequest[nIndex][1]), (int)Integer.parseInt(szRequest[nIndex][2])/nPageSize, Integer.parseInt(szRequest[nIndex][2])); if(szRequest[nIndex][0].equals("write")) write(Integer.parseInt(szRequest[nIndex][1]), (int)Integer.parseInt(szRequest[nIndex][2])/nPageSize, Integer.parseInt(szRequest[nIndex][2])); if(szRequest[nIndex][0].equals("unload")) unload(Integer.parseInt(szRequest[nIndex][1])); }/* End for.*/ System.out.println("Number of page faults for LFU:"+super.nPageFault); }/* End of Start.*/ public int getVictim(int nProgName){ Frame newFrame; int nEmptyIndex=-1; int nFreq = 9999999; int nLFUIndex=-1; for(int nIndex=0; nIndex < super.nNoOfFrames; nIndex++){ newFrame = (Frame)super.FrameList.elementAt(nIndex); if(newFrame.bFrameStatus == false) return nIndex; else{ if(nFreq >= newFrame.nAccessFreq){ nLFUIndex = nIndex; nFreq = newFrame.nAccessFreq; }/* End if.*/ }/* End if.*/ }/* End for.*/ return nLFUIndex; }/* End of getVicitim.*/ }/* End of LFU.*/