Loading an entire process into RAM at startup is wasteful — many pages may never be used. We need a way to load pages only when they’re actually needed.
Demand paging loads pages from disk only when they are first accessed (on-demand), reducing RAM usage and startup time.
- Process starts, page table marked with all pages “not present”
- Process runs, accesses first page → page fault
- OS loads that page from disk into RAM
- Subsequent accesses hit RAM (no fault)
- If RAM is full, evicts a page (LRU, FIFO, etc.)
- Lazy loading: pages loaded only when needed
- Reduces initial RAM usage
- First access is slow (disk read), subsequent fast
- Basis for virtual memory systems
- Built from: Paging, Page Fault
- Builds into: Virtual Memory, Thrashing
- Related: Swap Space, Page Replacement
- Contrasts with: Prepaging (load pages before needed)
- Too many page faults = thrashing
- Page fault handling overhead (~1ms for disk read)
- Critical processes may need pages locked in RAM (mlock)