1

i am reading about page faults in demand paging. page faults happen when 1) the memory being is accessed is illegal 2)the page is valid but not present in main memory

i read that with valid-invalid bit you can tell if the memory is not in logical address space,because the corresponding bit will be marked invalid.

the same valid-invalid bit is used to identify the above 2 condition.

my question how does the os know if the memory being accessed is illegal or if the page is valid but not in main memory with just one valid-invalid bit? thank you!

SuperAadi
  • 627
  • 1
  • 6
  • 15

1 Answers1

1

In Demand Paging if the valid-invalid bit is set(1), it means that the associated page is both legal and in memory. However if the valid-invalid bit is not set(0), it means the following:

  1. Either the page is not valid. It means that page is not in process logical address space. OR
  2. The corresponding page is on disk.

The invalid page access causes a page-fault trap. And we handle it in the following way. Quoting from Operating Systems principles by Silberschatz, Galvin, Gagne

  1. We check an internal table(usually kept with the process control block) for this process to determine whether the reference was a valid or an invalid memory access.
  2. If the reference was invalid, we terminate the process. If it was valid, but we have not yet brought in that page, we now page it in.
  3. We find a free frame(by taking one from the free frame list, for example).
  4. We schedule a disk operation to read the desired page into the newly allocated frame.
  5. When the disk read is complete, we modify the internal table kept with the process and the page table to indicate that the page is now in memory.
  6. We restart the instruction that was interrupted by the trap. The process can now access the page as though it had always been in memory.
Sumeet
  • 8,086
  • 3
  • 25
  • 45