Labs / Systems Architecture

Virtual Memory Simulator

Trace virtual address translation through TLBs and Page Tables to Physical Memory.

New to this? There\'s a lesson below ↓
← BACK TO LABS
Translation Visualization
VIRTUAL ADDRESS
VPN
-
OFFSET
-
PHYSICAL ADDRESS
PFN
-
OFFSET
-
TLB
VPNPFN
PAGE TABLE
VPNVPFN
PHYSICAL MEMORY
PFNVPN
Configuration & Metrics
ACCESSES
0
TLB HITS
0
PAGE HITS
0
FAULTS
0
What's happening?

Enter a Virtual Address to see the translation process.

The lesson

Virtual Memory, Paging, and the TLB

How the MMU and OS translate Virtual Page Numbers (VPN) to Physical Frame Numbers (PFN) via the TLB and Page Table, and how page faults and replacement policies work.

1. Why Operating Systems Use Virtual Memory

Instead of letting processes access physical RAM addresses directly, the Operating System and the CPU's Memory Management Unit (MMU) give every process its own isolated Virtual Address Space starting at 0x0000. On every instruction fetch, load, or store, the MMU translates the process's Virtual Address (VA) into a Physical Address (PA) in RAM.

This layer of indirection provides three essential guarantees:

  • Process Isolation & Protection: Process A cannot read or corrupt Process B's memory because Process A's page table only maps Process A's frames, with hardware-enforced Read/Write/Execute permission bits.
  • Demand Paging (More Virtual Memory than Physical RAM): Only the actively used pages of a program need to reside in physical RAM; inactive pages stay on disk/SSD until needed.
  • Shared Memory: Multiple processes can share a single physical copy of a library (such as libc) by mapping different virtual pages to the same physical frame.

2. Paging and Address Translation (VPN → PFN)

Virtual memory is divided into fixed-size blocks called Virtual Pages, and physical RAM is divided into blocks of the exact same size called Physical Frames (in this simulator, either 256 B or 4 KB).

Every Virtual Address splits into two fields:

Offset bits  d = log₂(Page Size)
VPN bits     p = VirtualAddressBits − d     (Number of Virtual Pages = 2ᵖ)
Virtual Address:    ┌──────────────────────┬──────────────────────┐
                    │       VPN (p)        │      OFFSET (d)      │
                    └──────────┬───────────┴──────────┬───────────┘
                               │                      │
                     Translate via TLB /              │ Copied unchanged
                         Page Table                   │
                               ▼                      ▼
Physical Address:   ┌──────────────────────┬──────────────────────┐
                    │       PFN (f)        │      OFFSET (d)      │
                    └──────────────────────┴──────────────────────┘

Worked Example (Default simulator settings: 16-bit VA, 256-byte pages):

  • Page size = 256 B = 2⁸ → 8 Offset bits (2 hex digits).
  • Remaining bits = 16 − 8 = 8 VPN bits → 2⁸ = 256 Virtual Pages (0x00 to 0xFF).
  • For Virtual Address 0x3A7C: VPN = 0x3A and Offset = 0x7C. If the Page Table maps VPN 0x3A → PFN 0x05, the Physical Address is (0x05 << 8) | 0x7C = 0x057C. Notice that the Offset (0x7C) is never modified during translation.

3. The Three Outcomes of an Address Lookup

Click RESET in the simulator, enter 0100, and click ACCESS, then enter 0180 and click ACCESS. Every memory reference follows this exact hardware/OS sequence:

  1. TLB Lookup (Translation Lookaside Buffer): Because the Page Table itself is stored in main memory, reading the Page Table on every memory access would double memory latency. The TLB is a small, fast hardware cache inside the MMU that stores recent VPN → PFN translations.
    • TLB Hit (~1 cycle): The MMU forms the physical address immediately without touching the Page Table in RAM (as happened on your second access, 0x0180, which shares VPN 0x01 with 0x0100).
  2. Page Table Walk (on a TLB Miss): If the VPN is not in the TLB, the MMU indexes into the process's Page Table in RAM using the VPN and checks the Valid bit (V):
    • Page Table Hit (V = 1, ~10–100 cycles): The page is already in physical RAM. The MMU loads the VPN → PFN entry into the TLB and completes the access.
  3. Page Fault (V = 0, ~100,000+ cycles): The page is not currently in physical RAM. The CPU triggers a Page Fault trap into the Operating System kernel. The OS locates the page on disk, allocates a free physical frame (or evicts an existing page if RAM is full), loads the data into the frame, sets V = 1 and PFN in the Page Table, updates the TLB, and restarts the instruction.

4. Page Replacement (LRU vs. FIFO) and Thrashing

Set PHYSICAL FRAMES = 4 Frames. Once all 4 frames are occupied and a 5th distinct page faults, the OS must select a victim frame to evict:

  • LRU (Least Recently Used): Evicts the page whose last reference (hit or load) is oldest.
  • FIFO (First In, First Out): Evicts the page that was loaded into RAM earliest, even if it has been accessed repeatedly since loading.

Thrashing: When a process's active working set of pages exceeds the number of available physical frames, it faults continuously — evicting pages that are needed again moments later. Because disk/SSD I/O is orders of magnitude slower than RAM, CPU utilization collapses while the system spends nearly 100% of its time servicing page faults.

Exercises

1. Set VIRTUAL ADDRESS BITS = 12-bit (4KB space) and PAGE SIZE = 256 B (8-bit offset). How many VPN bits and how many total Virtual Pages exist? Decompose 0xA4F into VPN and Offset, then verify in the simulator.

Show solution
VPN bits = 12 − 8 = 4 bits → 2⁴ = 16 Virtual Pages (0x0 to 0xF). For 0xA4F: VPN = 0xA (10) and Offset = 0x4F (79).

2. Click RESET, set PHYSICAL FRAMES = 4 Frames, and access this sequence of 8 addresses on pages 0, 1, 2, 3, 0, 4, 0, 1: 0000, 0100, 0200, 0300, 0000, 0400, 0000, 0100. Compare the total Page Faults under FIFO vs. LRU.

Show solution
The first four accesses (0000, 0100, 0200, 0300) cause 4 compulsory page faults, and the second 0000 is a hit under both policies. When 0400 (VPN 4) arrives:
• FIFO evicts VPN 0 (loaded earliest at t=1), so the next 0000 faults (evicting VPN 1), and then 0100 faults too → 7 Page Faults.
• LRU sees that VPN 0 was just used at t=5, so it evicts VPN 1 (unused since t=2). Then 0000 hits, and only 0100 faults → 6 Page Faults.

Quiz

In a system with 16-bit virtual addresses and 4 KB (4096-byte) pages, how many bits are used for the page Offset and how many for the VPN?

What is cached inside the Translation Lookaside Buffer (TLB)?

What happens when a memory access misses in the TLB, but the Page Table entry has Valid bit V = 1?

What causes "thrashing" in a virtual memory system?