100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is Pure Demand Paging?

Learn what pure demand paging is -- zero pages preloaded, guaranteed startup fault -- with examples and OS interview questions answered.

mediumQ155 of 224 in Operating Systems Est. time: 5 minsLast updated:
Open Code Lab

Expected Interview Answer

Pure demand paging is a memory management policy where absolutely no page of a process is loaded into RAM until the process actually references it, so every process starts execution with zero resident pages and takes a page fault on its very first instruction.

Under pure demand paging, the loader does not pre-load any code or data pages when a process starts; the OS sets up an empty page table (all entries marked not-present) and lets the CPU raise a page fault the instant the process tries to fetch its first instruction. The page fault handler then locates the required page in the executable or backing store, allocates a physical frame, copies the page in, updates the page table, and restarts the faulting instruction. This is contrasted with prepaging, where the OS speculatively loads a batch of pages it expects will be needed. Pure demand paging minimizes wasted memory and I/O for pages that turn out never to be used, but it pays a page fault for every single first touch, including a guaranteed fault on process startup, which can hurt latency for short-lived or bursty workloads.

  • Loads only pages a process actually touches, minimizing wasted memory
  • Avoids I/O for pages that would never be referenced
  • Simple, predictable fault-driven loading model
  • Foundation for understanding locality and working-set behavior

AI Mentor Explanation

Pure demand paging is like a groundstaff crew that prepares absolutely no part of the outfield in advance and only mows, rolls, or marks a specific patch the instant a fielder is actually sent to stand there. The very first fielder placed at the start of play causes a delay while that patch is prepared from scratch, since nothing was readied beforehand. As play continues, only the patches players actually occupy ever get prepared, so effort is never wasted on unused ground, but the very first step onto any new patch always costs a pause.

Step-by-Step Explanation

  1. Step 1

    Process created with empty page table

    No pages are pre-loaded; every page table entry starts marked not-present.

  2. Step 2

    First instruction fetch faults

    The CPU tries to fetch the entry-point instruction and immediately raises a page fault, since nothing is resident.

  3. Step 3

    Fault handler loads the page

    The OS locates the needed page in the executable or backing store, allocates a free frame, and copies it in.

  4. Step 4

    Instruction restarts

    The page table is updated to present, and the faulting instruction is re-executed, now succeeding.

What Interviewer Expects

  • Understanding that zero pages are pre-loaded, including code pages
  • Awareness that the very first instruction always faults
  • Contrast with prepaging as the natural follow-up comparison
  • Discussion of the tradeoff between wasted memory and fault overhead

Common Mistakes

  • Assuming the entry-point page is loaded automatically at process start
  • Confusing pure demand paging with prepaging or working-set prefetching
  • Forgetting that a page fault must occur before any execution can begin
  • Overstating demand paging as always faster than prepaging

Best Answer (HR Friendly)

Pure demand paging means the operating system does not load a single page of a program in advance, not even the very first instruction it needs to run. It waits until the program actually asks for something, then fetches just that piece, which keeps memory lean but guarantees a small delay the first time anything, including the program’s very first instruction, is touched.

Code Example

Pure demand paging: page table starts fully not-present
struct pte {
    int present;
    int frame;
};

/* At process creation, ALL entries are not-present -- pure demand paging */
void init_page_table(struct pte *table, int num_pages) {
    for (int i = 0; i < num_pages; i++) {
        table[i].present = 0;   /* nothing pre-loaded, not even entry point */
        table[i].frame   = -1;
    }
}

/* First instruction fetch always faults under pure demand paging */
void handle_page_fault(struct pte *table, int page_num) {
    int frame = allocate_frame();
    load_page_from_backing_store(page_num, frame);
    table[page_num].present = 1;
    table[page_num].frame   = frame;
}

Follow-up Questions

  • Why does pure demand paging guarantee a page fault on process start?
  • How does prepaging try to reduce the number of initial page faults?
  • What is the relationship between locality of reference and demand paging efficiency?
  • How does copy-on-write interact with demand paging for forked processes?

MCQ Practice

1. Under pure demand paging, how many pages are loaded when a process is first created?

Pure demand paging loads no pages in advance at all -- every page, including the entry point, is fetched only on first reference.

2. What is the immediate consequence of starting a process under pure demand paging?

Since no page, not even the entry point, is resident at start, the first instruction fetch is guaranteed to raise a page fault.

3. What is the main tradeoff of pure demand paging compared to prepaging?

Pure demand paging avoids loading pages that are never used, but every first reference to any page costs a fault, unlike prepaging which batches loads speculatively.

Flash Cards

What is pure demand paging?A policy where zero pages of a process are loaded until each is actually referenced, including the entry point.

Does a process always fault at start under pure demand paging?Yes -- the first instruction fetch always raises a page fault since nothing is preloaded.

What is the main benefit of pure demand paging?It never wastes memory or I/O loading pages that turn out to be unused.

What is the main cost of pure demand paging?A page fault is paid on every first touch of every page, including process startup.

1 / 4

Continue Learning