3

I am having some trouble understanding FIFO & LRU, and I am trying to change my code to those.

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 perfectly, but I am not sure of how I can make it FIFO & LRU, like this:

private void pageFaultFIFO(int pageNumber);

private void pageFaultLRU(int pageNumber);

Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
Erik Eriksson
  • 75
  • 1
  • 9

1 Answers1

3

Lets clear out your FIFO and LRU understanding.

FIFO: the operating system keeps track of all the pages in memory in a queue, with the most recent arrival at the back, and the oldest arrival in front. When a page needs to be replaced, the page at the front of the queue (the oldest page) is selected. While FIFO is cheap and intuitive, it performs poorly in practical application.

eg. if you have 10 shoes with you and your mom says trash out any 5, then you will choose the oldest 5 to trash out.


LRU: LRU works on the idea that pages that have been most heavily used in the past few instructions are most likely to be used heavily in the next few instructions too.

eg. here, if you have 10 shoes with you and your mom says trash out any 5, then you will chose those 5 shoes to trash out which you use less frequently.

nitish005
  • 106
  • 11