Virtual Memory, Paging, Page Tables, Page Faults & TLB
Virtual address translation mechanics, page vs frame mapping, multi-level page tables, Translation Lookaside Buffer (TLB), page fault ISR handling, and inverted page tables.
Learning Objectives
- •Explain logical-to-physical address translation via Page Tables.
- •Calculate page table size and overhead for single-level and multi-level page tables.
- •Analyze the role of the TLB in reducing Effective Memory Access Time (EMAT).
- •Trace the end-to-end hardware and OS interrupt steps during a Page Fault.
Essential Prerequisites
- •Cache memory concept
- •Operating System processes and memory pointers
Virtual Memory, Paging aur TLB - RAM kam hone par bhi Bade Games chalana
Tumhare computer mein 8 GB RAM hai, lekin tum 50 GB ka GTA game ya heavy AI model chala lete ho! Ye chamatkar 'Virtual Memory' ki wajah se hota hai. Operating System aur MMU (Memory Management Unit) hard disk/SSD ka ek hissa RAM ki tarah use karte hain. Program ki memory ko chhote-chhote fixed blocks mein baanta jaata hai jinko 'Pages' (Virtual) aur 'Frames' (Physical RAM) bolte hain. Translation Lookaside Buffer (TLB) ek hardware cache hai jo Page Table ke address translations ko yaad rakhta hai taaki CPU ko baar-baar RAM ke page table pe na jaana pade.
Bhai socho tumhare paas ek chhota sa bag hai (RAM) jismein 5 kitaabein aa sakti hain, lekin syllabus mein 50 kitaabein hain (Virtual memory on SSD). Tum room mein baaki 45 kitaabein rakhte ho. Jab kisi nayi kitaab ki zaroorat padti hai, tum bag se ek kitaab nikaal kar room mein rakhte ho aur nayi kitaab bag mein daal lete ho (Page Swapping).
Page Fault kya hota hai? 'Jab CPU kisi aise virtual page ka address maangta hai jo abhi physical RAM frame mein loaded nahi hai (Valid bit = 0), toh hardware trap generate hota hai jise Page Fault kehte hain. OS hard drive se us page ko RAM mein swap-in karta hai.'
TLB Hit vs TLB Miss flow: MMU sabse pehle TLB check karta hai. Agar translation mil gaya (TLB Hit), toh 1 cycle mein physical address mil jaata hai! Agar TLB Miss hua, toh CPU ko RAM mein jaakar Page Table dekhna padta hai, jo 100x slow hota hai. Isliye TLB hit rate 99% ke aas-paas maintain kiya jaata hai.
The Core Mental Model
Why This Exists
Virtual Memory is the bedrock of modern multi-tasking operating systems. Without it, running two programs simultaneously could crash your machine if both tried using address 0x1000. It also allows running a 16 GB program on a machine with only 8 GB of physical RAM.
Beginner Foundation
When a program runs, it sees a giant playground of memory. But physical RAM doesn't have that much room. The computer cuts everything into 4 KB slices called pages. Active pages stay in fast RAM; inactive pages sleep on the SSD drive until needed.
Micro Concepts Decomposition
Virtual Memory Motivation & Isolation
Virtual Memory gives each user process the illusion of a vast, contiguous address space (e.g. 64-bit address space) while physical RAM is small and fragmented. It provides memory protection: processes cannot read or write each other's memory pages.
Paging & Address Translation Mechanics
Virtual address space is divided into fixed-size Pages (typically 4 KB). Physical memory is divided into identical-size Frames. Virtual Address = Virtual Page Number (VPN) | Page Offset. Hardware Memory Management Unit (MMU) looks up VPN in Page Table to find Physical Frame Number (PFN).
Translation Lookaside Buffer (TLB)
Looking up the page table in RAM for every single memory access would double memory latency. The TLB is an on-chip, highly-associative cache that stores recent VPN-to-PFN translations. A TLB hit resolves physical address in under 1 nanosecond.
Page Fault Lifecycle & Demand Paging
If a process accesses a page whose Valid Bit = 0 in the Page Table, hardware triggers a Page Fault trap. The OS interrupt handler: 1) blocks process, 2) finds free frame in RAM, 3) reads page from swap disk, 4) updates page table valid bit to 1, 5) restarts faulting instruction.
Hardware State Machine Architecture
Interactive Simulator
Operating Systems & Memory Management Simulator
| PROCESS | ARRIVAL TIME | BURST TIME | PRIORITY | FINISH TIME | TURNAROUND TIME (TAT) | WAITING TIME (WT) |
|---|---|---|---|---|---|---|
| Process 1 (P1) | 0 | 4 | 2 | 8 | 8 | 4 |
| Process 2 (P2) | 1 | 3 | 1 | 11 | 10 | 7 |
| Process 3 (P3) | 2 | 5 | 3 | 14 | 12 | 7 |
| Process 4 (P4) | 3 | 2 | 2 | 10 | 7 | 5 |
End-to-End Execution Trace
Step-by-Step Code Execution (C)
Sandbox Terminal Ready
Click Run Code or press Ctrl+Enter to compile and execute.
Where Students Lose Marks
Active Assessment Quiz
No Practice Questions Configured
Questions for this topic are currently undergoing faculty review.