#include #include #define N 8 typedef struct { bool present; unsigned loc; } PTE; static void dump(const PTE pt[]) { puts("VPN Present Location"); for (int i = 0; i < N; i++) printf("%3d %7s %8u\n", i, pt[i].present ? "yes" : "no", pt[i].loc); } int main(void) { PTE pt[N] = { {true, 0}, {true, 1}, {false, 4}, {true, 2}, {false, 6}, {false, 2}, {true, 3}, {false, 7} }; puts("=== Tiny VM with Swap Simulator ==="); puts("Initial page table:"); dump(pt); puts("\nCPU references VPN 2 -> present bit clear -> PAGE FAULT"); puts("Handler reads disk block 4, evicts VPN 0 to swap 0, places page in PFN 0"); pt[0].present = false; pt[0].loc = 0; pt[2].present = true; pt[2].loc = 0; puts("Page table after fault handling:"); dump(pt); puts("\nCPU references VPN 6 -> present, PFN 3, no fault"); puts("Large virtual memory illusion maintained."); return 0; }