1Definition
Virtual Memory is a memory management technique that enables the execution of processes that are not completely loaded into physical RAM by treating a section of secondary disk storage (Swap-Space) as an extension of main memory. Demand Paging is the primary implementation of virtual memory where individual pages are swapped into RAM only when demanded during execution. A Page Fault is a hardware interrupt raised when a program accesses a valid logical page that is not currently loaded into physical RAM.
2Simple Explanation
Historically, if a computer had 4GB of RAM, you could not launch a 10GB application. Virtual Memory removes this barrier! It creates the illusion of an infinite RAM pool.
Instead of loading a whole 10GB program into RAM at startup, the OS uses a Lazy Pager. The Lazy Pager brings zero pages into RAM initially (Pure Demand Paging). When the CPU executes Instruction 1, it discovers the page isn't in RAM. The MMU raises a Page Fault Trap. The OS pauses the app, reads the missing 4KB page from the hard drive, places it into an open RAM frame, updates the Page Table, and restarts the instruction. The user never notices, except for a microsecond disk read pause!
3Real-Life Example / Analogy
Streaming a Movie on Netflix: When you watch a 2-hour 4K movie (15GB file), Netflix does not force you to download all 15GB to your phone's memory before hitting play. It downloads only the current 5-second scene (Demand Paging). As you watch, it streams future scenes on demand. If your internet stutters and a scene isn't ready, the video pauses briefly (Page Fault), loads the buffer, and resumes.
4Diagram / Visual Representation
5Working / How It Works
- Valid-Invalid Bit Scheme:
- Bit = 1 (Valid): Page is legal and currently loaded in physical RAM frame.
- Bit = 0 (Invalid): Page is either illegal OR valid but currently stored on secondary swap disk.
- Detailed 6-Step Page Fault Handling Sequence:
- CPU generates logical address access to page marked
Invalid (0)in Page Table. - MMU hardware catches invalid bit and triggers a Page Fault Trap to OS kernel.
- OS checks process internal PCB table to verify if access is legal or illegal memory access (If illegal -> Abort process).
- OS locates missing page on secondary Swap-Space disk and allocates a free frame from the Free-Frame List.
- OS executes disk I/O operation to copy missing page into the allocated RAM frame.
- Disk read completes -> OS updates Page Table entry bit to
Valid (1)-> OS restarts the interrupted CPU instruction seamlessly.
- CPU generates logical address access to page marked
6Types / Components / Characteristics
- Pure Demand Paging: Starting process execution with zero pages in RAM. The very first instruction immediately triggers a page fault.
- Locality of Reference: Principle stating that program execution tends to cluster around specific localized memory regions (loops, functions) for periods of time, allowing demand paging to achieve near-RAM speed performance.
- Swapper vs. Pager:
- Swapper: Manipulates whole processes (Medium-Term Scheduler).
- Pager: Manipulates individual pages of a process.
7Solved Examples / Problems
Problem: Calculate the Effective Access Time (EAT) of a Demand Paging system given:
- Main Memory Access Time = 100 ns
- Page Fault Service Time = 10 milliseconds ()
- Page Fault Rate (1 page fault per 1,000 accesses).
Solution:
- Analysis: A page fault rate of just 0.1% slows effective memory access from 100ns to 10,100ns (a 100x slowdown!).
8Advantages, Disadvantages & Applications
- Virtual Memory Advantages: Programs can be vastly larger than physical RAM; increases Degree of Multiprogramming and CPU utilization.
- Disadvantages: Page fault disk I/O introduces memory latency; system can suffer from Thrashing if RAM is insufficient.
9Important Points to Remember
- A
0Valid/Invalid bit means the page is either out-of-bounds OR valid but residing on swap disk. - Page Fault handling requires restarting the interrupted instruction.
10Test Your Understanding
- MCQ: What hardware signal is triggered when a process attempts to access a page marked with an Invalid (0) bit in the Page Table?
- A) System Call Interrupt
- B) Page Fault Trap
- C) Segmentation Fault Trap
- D) Context Switch Signal
Show answer
B. - Conceptual Question: Detail the exact 6-step sequence executed by the OS to service a Page Fault.
- Application Question: Calculate the Effective Access Time (EAT) for a system with and Page Fault Service Time = .
