使用倒置页表(Inverted Page Table)时是否需要存在位?若需,原因是什么?
Great question—short answer: yes, we still need the present bit, and here are the practical, real-world reasons why:
Handling in-progress page swaps
Suppose a physical page is in the middle of being swapped out to disk. Even though the virtual page it’s mapped to is no longer present in memory, we might not delete the inverted page table entry right away (due to synchronization locks or batch processing workflows). The present bit acts as a quick, atomic flag to mark this entry as temporarily invalid, so the kernel doesn’t mistakenly treat it as a valid mapping while the swap operation is ongoing.Managing shared memory correctly
When multiple processes share a single physical page, removing one process’s mapping doesn’t mean the physical page is no longer in use. The present bit lets the kernel track whether the physical page still has any active mappings. As long as the present bit is set (because other processes are still using the page), the kernel knows not to free the physical page or delete the inverted page table entry.Reducing overhead from entry creation/deletion
Instead of deleting inverted page table entries every time a physical page is freed, it’s way more efficient to just flip the present bit to 0. Later, when that physical page is reused for a new virtual mapping, we can update the entry’s details (like the process ID and virtual page number) and set the present bit back to 1. This avoids the cost of dynamically allocating and deallocating page table entries constantly.Resolving ambiguous edge cases
There are messy scenarios where it’s not clear if a table entry is still valid—like when a process crashes abruptly and leaves some entries in a half-cleaned state. The present bit gives the kernel an unambiguous signal: if it’s 1, the mapping is active; if 0, the entry is stale and can be safely ignored or repurposed.
内容的提问来源于stack exchange,提问作者Niki

