Virtual Memory & Memory Mapping

a page-table entry

If the page table is the directory, a page-table entry (PTE) is one line in it — the record for a single page. It answers two questions at once: where does this page physically live (which frame), and what are you allowed to do with it (read, write, run). It is a small fixed-size value, typically 8 bytes on a 64-bit machine, packed with a frame number and a set of flag bits.

Reading a PTE 'at a glance', the bits you most want to know are roughly these. A present (valid) bit says whether the page is currently in RAM at all — if it is clear, touching the page triggers a page fault. A writable bit says whether writes are allowed; a user/supervisor bit says whether user-mode code may touch it; an execute or no-execute bit says whether instructions may be fetched from it. There is usually an accessed bit (set by hardware when the page is used) and a dirty bit (set when the page is written), which the OS reads to decide what to evict and what must be written back to disk. The rest of the entry holds the physical frame number.

Those few flags are how the big features are built. Memory protection is just the writable and no-execute bits; copy-on-write is a page marked present-but-read-only so the first write faults; demand paging is a page marked not-present so the first access faults and the OS loads it; swapping uses a not-present entry whose spare bits remember where on disk the page was parked. Almost every behaviour in this field is, underneath, a particular combination of PTE bits.

A read-only code page might have a PTE like: present=1, writable=0, no-execute=0, frame=0x1f4. Try to write to it and the present-but-not-writable combination makes the hardware raise a protection fault instead of letting the store through.

A frame number plus a handful of permission and status bits.

The present bit and the permission bits are doing the heavy lifting: a cleared present bit causes a page fault, while a permission mismatch (writing a read-only page, executing a no-execute page) causes a protection fault. They are different faults from the same structure.

Also called
PTEpage table entry頁表項