Lesson 25 of 26 · 13 min read
Distributed file systems (NFS, AFS) and hypervisors
Compare stateless idempotent NFSv2 against stateful callback-based AFSv2, then look underneath the OS to see how hypervisors virtualize guest OSes via traps and shadow page tables.

Course syllabus · lesson 25 of 26
In this lesson
Our final content lesson pairs two classic architectural pivots: moving file systems across networks (NFS vs. AFS), and sliding one extra layer of virtualization underneath the operating system itself (Virtual Machine Monitors / Hypervisors).
The crux of the problem spans two design frontiers: how a distributed file protocol trades server statelessness (fast crash recovery) against explicit client-cache callbacks (scalable performance), and how a hypervisor runs unmodified operating systems safely on shared physical hardware.
Compare NFS revalidation and AFS callbacks
Step 1 of 3
Cache a file at the client
An NFS client can cache file blocks and attributes. Classic AFS caches whole files locally and receives a callback promise from the server.
Part 1: Sun NFSv2 vs. The Andrew File System (AFS)
Sun NFSv2: Statelessness and idempotency
Early distributed systems kept per-client open-file tables on the server — causing huge headaches whenever the server crashed and forgot who held which file open! Sun's NFSv2 chased one brilliant goal: make requests independent of server-side open-file state.
- Opaque File Handles (
vol_id, inum, generation): Because the protocol does not rely on an open-file descriptor remembered by the server, everyNFSPROC_READorNFSPROC_WRITErequest carries the self-contained file handle, exact byte offset, and length! - Idempotency (
TIP: IDEMPOTENCY IS POWERFUL): Writingbytes Xatoffset = 512twice produces the exact same file contents as writing it once if no conflicting write intervenes. A repeated read or lookup has no update effect, though its result can change as other clients modify the filesystem. If the server reboots mid-edit, the client simply retries until the server responds — the file server can resume without reconstructing NFS client sessions once the underlying filesystem is available. - Wait: server write buffering rule: An NFS server must force modified data and metadata to stable disk before sending the
WRITEACK! Otherwise, if the server acknowledged from RAM and crashed 10 ms later, the client would assume the write succeeded forever while the disk held old garbage. - Caching weakness: Because NFS servers forget who caches blocks, clients cache data and use
GETATTRto validate it when cached attributes expire or client policy calls for revalidation. Flushing dirty data at close and validating at open improves visibility across clients. Read behavior during an existing open depends on cache policy.
A client can retry a read after the server reboots from its handle, offset, and count. For example, reading 4 KiB at offset 8,192 uses the same values whether the request is the first attempt or a retransmission. A generation field matters if inode 72 is deleted and reused. An old handle for generation 8 must fail against generation 9, even though the inode number matches. Otherwise a delayed request may operate on a different file.
Consider a write to bytes 8,192 through 12,287 that reaches stable storage but loses its reply. A retry sends the same bytes to that range. With no conflicting writer, the repeated write preserves the contents. An append operation that asks the server to choose the current end would append twice if implemented the same way. Even writes at fixed offsets need care with concurrent updates. If another client's write to that range occurs between the original request and its retry, the retry can replace that newer data.
Andrew File System (AFSv2): Stateful whole-file caching & callbacks
AFSv1 checked cached copies with the server on open. AFSv2 used callbacks to reduce that validation traffic:
- Whole-file client caching: On an open without a valid cached copy, the client fetches the entire file into its local cache (
Fetch). Reads and writes on that open can then run locally. A modified file is sent back at close (Store). - Callbacks replace polling: When handing a client a file, the AFS server records a stateful callback promise: "I will notify you if anyone else modifies this file." Clients can reuse a copy while its callback remains valid, without checking every open with the server.
- Cache consistency (last closer wins): If two clients edit private copies, the last successful store installed by the server wins. A client that already has a file open can continue reading its local version. Clients must revalidate cached copies when callback state is lost on server restart or the validity of a promise can no longer be established.
Compare bandwidth and validation traffic for a read-mostly workload. Suppose 100 clients each open the same 64 KiB file 20 times over a day. After the initial fetches, if the file never changes and all callbacks stay valid, AFS can satisfy the remaining 1,900 opens locally. The initial fetches transfer 6.25 MiB total. A client that revalidates on every open would send up to 2,000 validation requests under the same schedule, although a timed attribute cache can avoid some of those trips. The server pays for callbacks with a subscription list and invalidation traffic proportional to the number of clients caching a changed file.
Now change the access pattern: each client opens an uncached 64 MiB file to inspect only a 4 KiB header. A whole-file fetch transfers 16,384 times as much payload as a single block read. Once cached, the file can support later reads locally, so the result depends on how much of it each client eventually uses and how often the cache copy is invalidated or evicted.
Nested translation: guest VA -> guest table -> guest PA -> EPT -> machine MA
Shadow translation: guest VA -> VMM-maintained shadow table -> machine MA
Part 2: Virtual Machine Monitors (Hypervisors)
Why stop virtualizing at processes when an entire data center wants to consolidate Linux, BSD, and Windows servers onto shared physical hosts? A Virtual Machine Monitor (VMM / Hypervisor) inserts itself beneath operating systems, turning one physical server into isolated virtual machines — an OS for operating systems (Appendix B)!
Every mechanism we studied for processes reappears one level lower:
- Deprivileged CPU & Trap-and-Emulate: Normally a kernel expects full Ring 0 control. The VMM moves the guest OS down (say Ring 1 or hardware non-root mode) while keeping guest user apps in Ring 3. Whenever a guest kernel tries a privileged operation (like updating
PTBRor halting the CPU), hardware traps to the real VMM, which validates and emulates the virtual register update safely! - Three layers of memory (
VA -> PA -> MA) via Shadow Page Tables: Guest applications think they map virtual (VA) to physical (PA), while the VMM actually maps guest "physical" (PA) to real hardware machine addresses (MA)! In software virtualization, the VMM synthesizes hidden Shadow Page Tables (VA -> MA) loaded into realCR3, intercepting guest page-table edits and page faults to keep shadow entries synchronized. Modern CPUs (Intel VT-x / AMD-V+ Extended Page TablesEPT/NPT) move two-dimensionalVA -> PA -> MAwalks straight into silicon! - The Information Gap & Balloon Drivers: The VMM knows its frame mappings but generally lacks the guest's knowledge of page use. A guest balloon driver allocates and pins guest physical pages, tells the VMM their frame numbers, and lets the VMM reclaim the machine backing. The guest can use its own free lists and replacement policy to satisfy the allocation.
Follow a privileged instruction and a memory reference
A guest changes its page-table root as part of switching processes. In a trap-and-emulate design, the VMM intercepts the privileged register write, records the guest's intended virtual register value, validates what translation context the guest may use, and resumes the guest. A software VMM can choose a corresponding shadow page table for the hardware. With hardware-assisted virtualization, a guest kernel can run at its normal kernel privilege inside non-root mode, and virtualization controls determine which operations cause a VM exit. Ordinary instructions can run directly. The guest still has separate user and kernel privilege levels inside the VM.
Use 4 KiB pages and guest virtual address 0x35AB. The guest page table maps virtual page 3 to guest frame 7, giving guest physical address 0x75AB. The VMM assigns guest frame 7 to machine frame 0x2C, so the final address is 0x2C5AB. With shadow tables, hardware walks a VMM-managed entry that maps 3 directly to 0x2C. When the guest changes its own page tables, the VMM must invalidate or rebuild stale shadow entries and cached translations. Write-protecting guest page-table pages is one way for the VMM to catch edits.
With EPT, the CPU consults the guest page table and the second-stage mapping. The guest table itself lives at guest physical addresses. Fetching each guest page-table entry also requires translating its address through EPT. A four-level guest walk paired with four-level EPT could therefore require up to 4 * (4 + 1) + 4 = 24 translation-related entry reads before the data access in an uncached model. Translation caches, TLBs, and large pages can bypass much of this work. A guest PTE that fails the guest's own checks can produce a guest page fault. A failure of the second-stage mapping produces an exit for the VMM to handle.
Now ask a VM with 2 GiB configured to inflate its balloon by 256 MiB. At 4 KiB per frame, the balloon driver needs 256 * 1024 / 4 = 65,536 guest frames. If the guest has that much readily available, it can satisfy the request with limited disruption. Otherwise it may reclaim cache or page out anonymous memory. The driver keeps the ballooned frames reserved while the VMM releases their host backing. Deflating returns pages to normal guest use once they can be backed again. A VMM that guesses poorly when reclaiming pages itself may swap a page that the guest was about to free.
Worked trace: AFS invalidation, NFS cache expiry, and a guest fault
Trace Client 1 and Client 2 sharing file /shared/cfg (v1):
- AFS flow: Client 1 opens
/shared/cfg-> Server sends full filev1and registersCallback(C1, cfg). Client 2 also opens/shared/cfg-> getsv1+Callback(C2, cfg). Client 1 editscfglocally (zero server traffic during writes!) and callsclose()-> streamsv2to Server -> Server breaks callbacks toC2(BreakCallback(cfg)), invalidating C2's cache! Next time C2 callsopen(), C2 fetchesv2. - VMM shadow page fault trace: Inside a software VMM, a guest process hits an unmapped guest virtual address. Hardware traps to the VMM first -> VMM notices the address is also missing from the guest page table -> VMM forwards a virtual page fault into the guest OS trap handler -> guest OS allocates a guest
PAand updates its guest PTE -> guest touches it -> VMM updatesVA -> MAin the shadow page table! - Change one input: What happens in NFSv2 if Client 1 updates
/shared/cfg, flushes onclose(), and Client 2 already read block0of/shared/cfg500 msearlier with a3-secondattribute-cache timer? If Client 2 keeps using the cached attributes until expiration, it may servev1for up to another 2.5 seconds in this model. Once revalidation detects the update, it invalidates the old block and fetches the new version. A client policy that revalidates on the next open may shorten the window.
Finally, put every mechanism across CPU, memory, concurrency, persistence, and tooling together in systems debugging (gdb, valgrind) and cold traces.
Before you move on
Try it in your workspace
Compare stateless NFSv2 idempotent requests + attribute-cache polling against stateful AFSv2 whole-file caching + server callbacks, then trace how a VMM handles guest traps and shadow page tables.
Keep a short note of what you tried, what passed, and what you still need to check.
0 of 3 checked.
Saved in this browser when storage is available. Uncheck any item to revisit it. This is your own record, not an assessment.