Demand Paging is a method of virtual memory management where pages are loaded into physical memory only when they are requested by a running program. This approach contrasts with pre-paging systems that attempt to predict which pages will be needed and load them in advance.
How It Works
When a process is started, the operating system creates its page table but does not immediately load any pages into physical memory. Instead, all pages are initially marked as "not in memory." When the CPU tries to access a page that isn't in memory:
Advantages
- Efficient memory usage as only needed pages are loaded
- Lower initial loading time for programs
- More processes can run simultaneously with limited physical memory
- Support for programs larger than physical memory
- Reduced I/O and storage transfers
- Better system responsiveness for multiple users
Disadvantages
- Performance overhead due to page fault handling
- Increased hardware complexity (requires MMU)
- Potential for thrashing when physical memory is over-committed
- Additional complexity in system design
- Unpredictable program execution times due to page faults
Performance Considerations
The effectiveness of demand paging depends on several factors:- Locality of reference - Programs that exhibit high locality perform better
- Page size - Balancing fragmentation against transfer overhead
- Page replacement algorithm - Critical for deciding which pages to remove
- Frame allocation policy - How frames are distributed among processes
- Working set management - Identifying actively used pages to prevent thrashing