OS-Memory
Visualizer

An interactive, step-by-step simulator for understanding how modern operating systems manage physical memory through paging, segmentation, and page replacement algorithms.

VMSim

The Abstraction of Infinite Memory

Virtual memory is a memory management technique that provides processes with the illusion of a large, contiguous address space — far larger than physical RAM. It allows the operating system to efficiently multiplex physical memory among multiple processes and to use secondary storage as an extension of RAM.

Key Insight: A process never directly accesses physical RAM. It works with virtual addresses that the Memory Management Unit (MMU) translates to physical addresses at runtime. This translation is governed by the page table, maintained by the OS kernel.

Three Pillars of Virtual Memory

Virtual memory is built on three fundamental concepts that together manage how data moves between RAM and disk.

01

Paging

Physical and virtual memory are divided into fixed-size blocks called pages (virtual) and frames (physical). The OS maps virtual pages to physical frames non-contiguously, eliminating external fragmentation. When a referenced page is not in RAM, a page fault triggers the OS to load it from disk.

02

Segmentation

Memory is divided into variable-size logical segments (Text, Data, Stack, Heap), each with its own base and limit registers. Variable-size allocation leads to external fragmentation — unusable holes of free memory — which can be resolved by compaction.

03

Page Replacement

When a page fault occurs and RAM is full, the OS must evict a page. The choice of which page to evict is governed by a replacement algorithm that exploits temporal locality (recently used pages will likely be reused) and spatial locality.

What Happens on a Page Fault?

1

Access Attempt

CPU generates a virtual address. MMU checks the page table — the valid bit is 0.

2

Trap to OS

A hardware interrupt fires. Control transfers to the OS page-fault handler.

3

Find a Frame

OS finds a free frame, or selects a victim using the replacement algorithm.

4

Load from Disk

The required page is read from swap space into the selected frame.

5

Update Table

Page table entry is updated: frame number written, valid bit set to 1.

6

Resume Process

The faulting instruction is restarted. The access now succeeds — it's a hit.

Comparing Replacement Strategies

Each algorithm makes a different tradeoff between implementation complexity, runtime overhead, and approximation quality.

AlgorithmStrategyComplexityOptimal?Notes
FIFO Evict the page that has been in memory the longest O(1) — simple queue No Can suffer from Bélády's Anomaly: more frames can increase faults.
LRU Evict the page that was least recently used O(n) — requires tracking recency Near-optimal Strong in practice. Exploits temporal locality. Hardware implementation requires timestamps.
OPTIMAL Evict the page not used for the longest time in future Requires future knowledge Yes Theoretically best possible. Unimplementable in practice; used as a benchmark.
2ND CHANCE Clock approximation of LRU using a reference bit O(1) amortized — circular buffer No (approx.) Used in real OSes (e.g. Linux). Avoids full LRU overhead with similar performance.

Key Terminology

Page Fault
Occurs when a referenced page is not present in physical memory and must be loaded from disk.
Page Hit
The referenced page is already present in a physical frame — no disk I/O required.
Hit Ratio
The fraction of memory accesses that result in a page hit. Higher is better.
Thrashing
A condition where the system spends more time swapping pages than executing processes, caused by insufficient frames.
Working Set
The set of pages a process is actively using at a given point. Must fit in RAM to avoid thrashing.
Bélády's Anomaly
A counterintuitive FIFO property: allocating more frames can sometimes increase page faults.
Compaction
Eliminates external fragmentation by relocating all occupied segments to be contiguous.
TLB
Translation Lookaside Buffer — a hardware cache for page table entries that speeds up address translation.
Reference String
Physical Memory — Frame Allocation
Page Hits
0
Page Faults
0
Hit Rate
—
Execution Log
SYS Simulator initialised. Press Step or Run All to begin.
● STANDBY Algorithm: FIFO Step: 0 / 0 VMSim — Educational Simulator

Analytics & Observations

Page Hits
0
Successful accesses
Page Faults
0
Disk I/O triggered
Hit Rate
—
% accesses in RAM
Total References
0
Memory accesses
Hit Rate
0.00%
Fault Rate
0.00%
⚠ Bélády's Anomaly Detected. With FIFO, increasing the frame count from a certain point actually increased the number of page faults for this reference string. This is visible in the Faults vs. Frames chart below.
Faults vs. Frame Count
Shows how fault count changes with frame allocation. Watch for Bélády's Anomaly when FIFO is selected.
Algorithm Comparison
Total page faults for each algorithm with the current reference string and frame count.
Observations
Complete a simulation to generate analytical observations about algorithm performance, locality patterns, and optimisation opportunities.
Full Execution Log 0 ENTRIES
SYSAwaiting simulation…