Virtual Memory & Demand Paging

pure demand paging

Imagine starting a long road trip having packed absolutely nothing in advance — you buy each item only at the exact moment you first reach for it. You begin completely empty, and your bag fills up purely in response to immediate need. Pure demand paging is this extreme, principled version of demand paging: never bring any page into memory until the very first time the program actually references it. Start a program with no pages resident at all.

Concretely, in pure demand paging a process begins execution with every page-table entry marked invalid — not a single page of its code or data is preloaded. The first instruction the CPU tries to execute immediately causes a page fault, because even that instruction's page is not in memory; the OS services it and brings the page in. Each subsequent reference to a not-yet-loaded page faults in turn, until the program's working set has trickled into RAM. After this warm-up burst of faults, the program settles down and runs mostly fault-free, since locality keeps it within the pages already loaded. The contrast is with schemes that preload some pages at start-up; pure demand paging preloads nothing and lets every page be pulled in strictly on its first use.

Why it matters: pure demand paging is the cleanest statement of the lazy-loading principle, and it is the baseline against which optimizations like prepaging are compared. Its great virtue is that nothing unnecessary is ever loaded — a program that touches only a tenth of its pages reads only a tenth from disk. Its cost is the cluster of faults right at start-up, when many first-touches happen close together. Real systems usually soften this with prepaging (loading a few pages they predict will be needed) so the program does not stall on a fault for literally every one of its first references, but the underlying philosophy remains pure demand paging: by default, load on demand, not in advance.

A program is launched with all page-table entries invalid. Its very first instruction faults (bringing in the code page), then its first data access faults, then the next, in a short burst of perhaps a dozen faults — after which it runs for millions of instructions with hardly another fault.

Begin with nothing loaded; every page arrives strictly on first reference.

Pure demand paging is an idealized baseline, not how most real systems literally start every program — they typically prepage a handful of pages to avoid a fault on every single one of the first references. The principle (load on demand) holds; the strict 'load absolutely nothing first' rule is usually relaxed.

Also called
start with zero pages純粹依需求分頁