How to set up this function for FIFO & LRU?

I am having trouble understanding FIFO and LRU and am trying to change the code to them.

Here's my default pageFault method:

private void pageFault(int pageNumber){
  pageFaults++;

  try {
    pageFile.seek(pageNumber*PageSize);
    for(int b=0;b<PageSize;b++)
        RAM[freePos*PageSize+b]=pageFile.readByte();
  } catch (IOException ex) {
    Logger.getLogger(MemoryManager.class.getName()).log(Level.SEVERE, null, ex);
  }

  pageTable[pageNumber] = freePos; 
  freePos++; 
}

      

The method works fine, but I'm not sure how I can make it FIFO and LRU, for example:

private void pageFaultFIFO (int pageNumber);

private void pageFaultLRU (int pageNumber);

+3


source to share


1 answer


Allows you to clear your understanding of FIFO and LRU.

FIFO : The operating system keeps track of all pages in memory in the queue, with the most recent arrival in the back and the oldest arrival in front. When a page needs to be replaced, the page at the top of the queue (oldest page) is selected. Although FIFO is cheap and intuitive, it does not perform well in practice. <i>

eg. if you have 10 shoes with you and your mom says she is dropping all 5, then you will choose the oldest 5 to destroy.




LRU: LRU is working to ensure that the pages that have been used most frequently in the last few instructions are likely to be used in the next few instructions. <i>

eg. here, if you have 10 boots with you and your mom says she is dropping all 5, then you will choose those 5 boots to be destroyed that you use less often.

+3


source







All Articles