4.1.14 · D5Computer Architecture (Deep)

Question bank — Virtual memory — concept, page table, virtual-to-physical translation

1,996 words9 min readBack to topic

True or false — justify

The virtual address offset is translated by the MMU (the hardware that maps VA→PA) just like the page number.
False. Offset indexes within a page; since a frame is the same size and same alignment as a page, the within-block position is identical, so offset bits pass through untouched — only VPN→PFN is translated.
Two processes can have the same virtual address 0x4000 pointing at the same physical byte.
Usually false, deliberately. Isolation means each process has its own page table, so identical VAs normally map to different frames. It's only true when the OS intentionally shares a frame (shared library, shared memory, copy-on-write parent/child).
A single-level page table for a 32-bit address space always wastes memory.
True in practice. It reserves one entry per possible virtual page ( entries at 4 KiB pages) whether or not the page is used, which is why real systems use Multi-level Page Tables that only allocate sub-tables for touched regions.
Making pages bigger is strictly better because it shrinks the page table.
False. Fewer entries and fewer TLB misses, yes — but bigger pages waste more to internal fragmentation and force reading more data per page fault. It's a trade-off, which is why OSes offer both 4 KiB and huge pages.
Without a TLB, a memory access needs exactly two RAM trips.
False as stated — two is only the lower bound. A single-level table needs exactly two (one to read the entry, one for the data), but Multi-level Page Tables add one RAM trip per level: a 4-level table needs 4 lookups + 1 data trip = 5. Two is the minimum because you must read at least one table entry then the data itself.
A page fault means the program did something illegal.
False in general. A fault on a valid but not-resident page is normal — the OS just loads it from disk and retries. It's only an error (segfault) when the address is genuinely unmapped or violates permissions.
The offset field is bits wide when the page size is bytes.
True. You need exactly bits to address every one of the bytes inside a single page ( is just the exponent of the page size); the remaining high bits form the VPN.
Physical RAM must be at least as large as the virtual address space.
False. Over-commitment is a core purpose: unused pages live on disk (swap), so total virtual memory across processes can far exceed physical RAM.

Spot the error

"To get the physical address (PA), add the frame number (PFN) and the offset: PA = PFN + offset."
Error: you must scale the frame number by the page size first: , i.e. concatenate PFN (high bits) with offset (low bits). Plain addition would collide frame bases with offsets.
"VPN = VA mod page_size, offset = VA / page_size."
Error: it's swapped. The remainder (VA mod 2^p) is how far into the page → offset; the quotient (⌊VA / 2^p⌋) is which page → VPN.
"On a context switch we flush the page table from RAM and rebuild it."
Error: page tables persist in RAM per process; the switch just reloads the page-table base register (CR3 on x86 — it holds the address of the current table) to point at the new process's table. See Context Switching and CR3 / Page-Table Base Register.
"The valid bit tells you whether the frame is in the CPU cache."
Error: the valid bit says whether the mapping/page is present in RAM; cache residency is a separate concern handled by Cache Memory and Locality, not the page table.
"With 20 VPN bits and 4-byte entries the table needs bytes."
Error: it needs entries × 4 bytes = bytes = 4 MiB, not bytes. Confusing entry count with byte count undercounts by the entry size.
"Since the offset isn't translated, page size doesn't affect the physical address at all."
Error: page size sets where the VPN/offset boundary falls, so it decides how many bits get translated versus passed through — it fully shapes the split, even though the offset value itself survives.

Why questions

Why is the offset guaranteed to be identical in the virtual and physical address?
Because frames and pages are the same size () and both aligned to boundaries, the position inside the block is preserved: becomes , same off.
Why fixed-size pages instead of relocating whole programs?
Whole-program relocation causes external fragmentation (free RAM exists but no single hole fits). Equal-size pages let any free frame hold any page, so placement is trivial — at the cost of a little internal fragmentation in the last page.
Why does each process get its own page table rather than one shared map?
For isolation. A private map lets identical virtual addresses land on different frames, so one process cannot read or corrupt another's memory — the central protection guarantee of paging.
Why must a faulting instruction restart instead of resuming mid-access?
The instruction never completed its memory access (the data wasn't there), so there's no partial state to resume; after the OS fixes the mapping, re-executing it cleanly performs the now-valid access.
Why is a TLB necessary if the page table already gives the answer?
The page table lives in RAM, so consulting it costs a memory trip (or several, with multi-level tables) per access. The TLB caches recent VPN→PFN mappings on-chip so most translations skip RAM entirely — locality makes this hit rate high.
Why do multi-level page tables save memory over one flat table?
They allocate a sub-table only for regions of the address space actually used; unused high-level entries stay empty, so a sparse process pays for a few small tables instead of a full -entry array.
Why does the OS load the whole page on a fault, not just the requested byte?
Spatial locality — nearby bytes are very likely to be accessed soon, so bringing in the whole aligned page amortises the expensive disk trip across many future accesses.

Edge cases

What is the offset when a virtual address is an exact multiple of the page size (e.g. 0x9000 with 4 KiB pages)?
The offset is 0 — the address sits at the very start of a page, so it maps to the base of its frame: .
Is virtual page 0 special or translated like any other?
Translated like any other via PageTable[0]. Many OSes deliberately leave VPN 0 invalid so that dereferencing a NULL pointer faults immediately — a policy choice, not a hardware rule.
What happens on an access whose offset would spill past the end of a page (an unaligned access crossing a page boundary)?
It touches two virtual pages, so the MMU performs two translations; the two pages may map to non-adjacent frames, and either translation can independently fault.
If a page table entry's valid bit is 0 but the OS knows the page is genuinely unmapped, what results?
A protection/segmentation fault, not a swap-in. The fault handler distinguishes "not resident, fetch from disk" from "no such mapping, kill the process."
With a 16-bit VA and 1 KiB pages, what is the maximum number of distinct virtual pages?
pages — that's the ceiling on page-table entries because only 64 distinct VPNs can exist in that space.
Can two different VPNs in the same process map to the same PFN?
Yes — that's aliasing (e.g. two virtual addresses of one shared buffer). It's legal; the page table just stores the same PFN in two entries, and the hardware doesn't forbid it.
What happens to a page whose valid bit is 1 but the OS later evicts it to disk?
The OS clears its valid bit (and records the disk location); the next access faults, triggering a swap-in and re-marking it valid — the mechanism behind Page Replacement Algorithms (LRU, FIFO, Clock).
If physical RAM has more frames than the virtual space has pages, is any PFN unreachable?
Yes — a process can only name PFNs its page table points to, so surplus frames simply hold other processes' pages or stay free; nothing forces a one-to-one exhaustion.
Must the TLB be fully flushed on every context switch?
No — that's the naïve design. Many CPUs tag each TLB entry with an ASID (address space identifier), so entries from different processes coexist and only the matching process's entries are used. This avoids flushing on every switch. See Context Switching and CR3 / Page-Table Base Register and TLB — Translation Lookaside Buffer.