Advertisement
Tiger0915

pageFault.c

Dec 4th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. /* placement round */
  2.     for(i=0; i< numPageFrames; i++) {
  3.         /* if we've reached a page not in memory, use that index */
  4.         if(pageTable[i].valid == 0) {
  5.             pageTable[i].vmPage = pageNumber;
  6.             pageTable[i].valid = 1;
  7.             pageTable[i].referenced = 0;
  8.             pageTable[i].modified = 0;
  9.             return (0);
  10.         }
  11.     }
  12.  
  13.     /* Replacement Loop, because placement failed */
  14.     loopStart = clockHand;
  15.     do {
  16.         /* if current spot is not referenced, replace it */
  17.         if(pageTable[clockHand].referenced == 0) {
  18. //            freeFrame(logicalAddress); <-----------------DO WE EVER NEED TO FREEFRAME() ??
  19.             pageTable[clockHand].vmPage = pageNumber;
  20.             pageTable[clockHand].valid = 1;
  21.             pageTable[clockHand].referenced = 0;
  22.             clockHand++; /* increment clock pointer for next time */
  23.             if(pageTable[clockHand].modified == 1) {
  24.                 pageTable[clockHand].modified = 0;
  25.                 return (2);
  26.             } else return (1);
  27.         } else { /* if spot has already been referenced, set it to unreferenced and move on */
  28.             pageTable[clockHand].referenced = 0;
  29.         }
  30.         /* if we failed for this index, increment clockHand, if over threshold, reset to 0 */
  31.         clockHand++;
  32.         if(clockHand >= numPageFrames) clockHand = 0;
  33.     } while(clockHand != loopStart);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement