0
0
Operating Systemsknowledge~10 mins

Demand paging in Operating Systems - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Demand paging
Process starts
Page needed?
No
Use page in RAM
Continue execution
Process ends
Yes
Page fault occurs
Load page from disk to RAM
Update page table
Resume process execution
Demand paging loads pages into RAM only when the process needs them, handling page faults by loading missing pages from disk.
Execution Sample
Operating Systems
Process requests page 5
Is page 5 in RAM?
No -> Page fault
Load page 5 from disk to RAM
Update page table
Resume process
This simulates a process requesting a page not in RAM, causing a page fault and loading the page on demand.
Analysis Table
StepActionPage RequestedPage in RAM?Page Fault?Result
1Process requests page5NoYesPage fault occurs
2Load page from disk5NoYesPage 5 loaded into RAM
3Update page table5YesNoPage table updated
4Resume execution5YesNoProcess continues using page 5
5Process requests page3YesNoPage 3 used directly
6Process ends---Execution complete
💡 Process ends after all needed pages are accessed
State Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
Page Requested-55553-
Page in RAMNo pagesNoYes (page 5)Yes (page 5)Yes (page 5)Yes (pages 3,5)Yes (pages 3,5)
Page FaultNoYesYesNoNoNoNo
Key Insights - 3 Insights
Why does a page fault happen even though the process requested a page?
A page fault happens because the requested page is not currently loaded in RAM, as shown in execution_table step 1 where 'Page in RAM?' is 'No'.
What happens after the page fault occurs?
After the page fault, the system loads the page from disk into RAM and updates the page table, as seen in steps 2 and 3 of the execution_table.
Does the process always cause a page fault when requesting a page?
No, if the page is already in RAM, no page fault occurs. For example, in step 5, page 3 is in RAM and used directly without fault.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 1. What is the status of the requested page in RAM?
AThe page is not in RAM
BThe page is already in RAM
CThe page is being removed from RAM
DThe page is corrupted
💡 Hint
Check the 'Page in RAM?' column at step 1 in the execution_table
At which step does the page table get updated to include the new page?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for the action 'Update page table' in the execution_table
If the process requests a page already in RAM, what changes in the execution_table?
AA page fault occurs
BThe page is loaded from disk
CThe process uses the page directly without fault
DThe page table is updated
💡 Hint
Compare step 5 where 'Page in RAM?' is 'Yes' and 'Page Fault?' is 'No'
Concept Snapshot
Demand paging loads pages only when needed.
If a page is not in RAM, a page fault occurs.
The OS loads the page from disk into RAM.
Page table is updated to reflect the new page.
Process resumes using the loaded page.
This saves memory and speeds up execution.
Full Transcript
Demand paging is a memory management technique where pages are loaded into RAM only when the process requests them. When a process tries to access a page not in RAM, a page fault occurs. The operating system then loads the required page from disk into RAM and updates the page table. After this, the process resumes execution using the newly loaded page. If the page is already in RAM, the process uses it directly without causing a page fault. This method helps save memory and improves efficiency by loading only necessary pages.