memory-managementoperating-systempage-tables

Valid Bit and Dirty Bit in page tables


Is there any reason that the Valid-Bit in a page table would ever be turned off (set to invalid)? Also when working with the dirty bit, I know that the dirty bit is supposed to be set whenever there is a write request on the page table entry in question. However, why is the dirty bit useful?


Solution

  • Is there any reason that the Valid-Bit in a page table would ever be turned off (set to invalid)?

    1. When a page table is initialized because one page table entry (pte) is created, the other ptes in that page table need to be marked invalid so they don't get used.
    2. If the page gets kicked/swapped out from memory, its pte needs to be marked invalid so that the OS can intercept the page fault upon any future read/writes and swap the correct memory back in.

    Also when working with the dirty bit, I know that the dirty bit is supposed to be set whenever there is a write request on the page table entry in question. However, why is the dirty bit useful?

    The dirty bit allows you to detect which pages have been written to in memory only (not yet propagated back to disk). If the OS wants to evict a dirty page, it sees that the dirty bit is set and now knows that it should write the changes back to disk before evicting the page. Without the dirty bit, 1) either the OS would need to compare every bit of the page to its backing disk-page to check if it was dirty before evicting it, or 2) it would have to adopt a burdensome "immediately-write-back" (normally called "write-through") policy where every write to memory must immediately be written to disk.