title: Page table: Page fault
body: <p>I have a few questions regarding page tables, especially when a page fault occurs.</p>
  
  <p>I understand that a page fault occurs when the CPU demands a page, but it is not present in the RAM, and has to be fetched from the swap space. The page table uses the higher order bits of the virtual address for indexing, and also contains an invalid bit that indicates if the page is in the memory.</p>
  
  <p>Here is what I don't understand. Does the page table contain the physical addresses for those pages also for whom the invalid bit is set? I mean, they are not present in the physical memory. So, my understanding is that those pages for whom the invalid bit is set, the corresponding physical addresses should be blank. Am I missing something?</p>
  
  <p>Another question is why can't we have entries only for those pages that are present in the memory. This way, the size of the page table can be made smaller.</p>
  
  <p>Yet another question is that when the operating system swaps-in a page after a page fault into the RAM, is the physical address of the frame to which the page is assigned converted to virtual address for updating the page table?</p>
  
  <p>Can someone please clarify these doubts? Thanks!</p>