AdityaPandey-DEV/VMM
A comprehensive virtual memory simulation framework designed for educational use, featuring multi-level page tables, TLB, demand paging, and various page replacement algorithms. It supports multi-process simulation with an interactive web GUI for visualization and metrics analysis.
Virtual Memory Manager (VMM) Simulator
Authors: Aditya Pandey, Kartik, Vivek, Gaurang
A complete, professional virtual memory simulation framework for learning, teaching, and research. Implements core OS memory management concepts including multi-level page tables, TLB, demand paging, swap, and multiple page replacement algorithms.
Features
Core Functionality
- Multi-level Page Tables: Single-level and two-level page table support
- Translation Lookaside Buffer (TLB): Configurable size with FIFO and LRU policies
- Demand Paging: Lazy allocation with page fault handling
- Swap/Backing Store: Simulated disk storage for paged-out memory
- Page Replacement Algorithms:
- FIFO (First-In-First-Out)
- LRU (Least Recently Used - exact implementation)
- Approx-LRU (Aging/NFU algorithm for O(1) replacement)
- Clock (Second-Chance algorithm)
- OPT (Optimal/Belady's algorithm for comparison)
Advanced Features
- Multi-process Support: Isolated virtual address spaces per process
- Comprehensive Metrics: Page faults, TLB hit/miss ratios, swap I/O, average memory access time
- Flexible I/O: JSON, CSV, and console output formats
- Trace Generation: Synthetic trace patterns (sequential, random, locality, working set, thrashing)
- Performance Instrumentation: Simulated access times and throughput measurement
Web GUI
A modern, interactive web-based visualization interface is available in the gui/ directory!
Quick Start GUI:
cd gui
python3 -m http.server 8000
# Open http://localhost:8000 in your browserFeatures:
- Real-time visualization of TLB, page tables, and physical frames
- Interactive configuration and simulation controls
- Performance charts and metrics dashboard
- Step-by-step execution with detailed event logging
See gui/README.md for complete GUI documentation.
Quick Start (Command Line)
Build
makeGenerate Sample Traces
make tracesRun a Simple Simulation
./bin/vmm -r 64 -p 4096 -t traces/working_set.trace -a LRU -T 32Run All Tests
make testUsage Examples
Example 1: Small RAM, FIFO Algorithm
./bin/vmm -r 16 -p 4096 -t traces/sequential.trace -a FIFO -T 16Expected: High page fault rate with small RAM
Example 2: Medium RAM, LRU Algorithm with JSON Output
./bin/vmm -r 64 -p 4096 -t traces/working_set.trace -a LRU -T 64 \
-o results/lru_output.json --csv results/lru_metrics.csvExpected: Moderate page fault rate, good TLB hit rate with locality
Example 3: Large RAM, Clock Algorithm, Verbose Mode
./bin/vmm -r 256 -p 4096 -t traces/locality.trace -a CLOCK -T 128 -VExpected: Low page fault rate, detailed per-process statistics
Example 4: Compare Algorithms
# Run with different algorithms and compare CSV output
for algo in FIFO LRU CLOCK OPT; do
./bin/vmm -r 32 -p 4096 -t traces/random.trace -a $algo -T 32 \
--csv results/${algo}_comparison.csv --config-name $algo
doneCommand-Line Options
Required
-t, --trace FILE- Input trace file (format:pid op addr)
Memory Configuration
-r, --ram SIZE- Physical RAM size in MB (default: 64)-p, --page-size SIZE- Page size in bytes (default: 4096)-s, --swap SIZE- Swap size in MB (default: 256)-v, --vspace SIZE- Virtual address space in MB (default: 4096)
Algorithms
-a, --algorithm ALGO- Replacement algorithm: FIFO, LRU, APPROX_LRU, CLOCK, OPT (default: CLOCK)-T, --tlb-size SIZE- TLB entries (default: 64)--tlb-policy POLICY- TLB policy: FIFO, LRU (default: LRU)--pt-type TYPE- Page table type: SINGLE, TWO_LEVEL (default: SINGLE)
Simulation
-n, --max-accesses N- Stop after N memory accesses--seed SEED- Random seed (default: 42)
Output
-o, --output FILE- JSON output file--csv FILE- CSV output file--config-name NAME- Configuration name for CSV output
Verbosity
-V, --verbose- Verbose output with per-process metrics-D, --debug- Debug output with trace-level logging-q, --quiet- Quiet mode (errors only)
Trace Format
Input trace files are text files with one memory access per line:
<pid> <op> <virtual_address>
Where:
pid- Process ID (integer)op- Operation:R(read) orW(write)virtual_address- Virtual address in hex (0x...) or decimal
Example:
0 R 0x1000
0 W 0x2000
1 R 0x1000
Trace Generation
Generate synthetic traces with various patterns:
# Sequential access pattern
./bin/trace_gen -t sequential -n 10000 -o traces/sequential.trace
# Random access pattern
./bin/trace_gen -t random -n 20000 -p 8 -o traces/random.trace
# Working set with locality
./bin/trace_gen -t working_set -n 15000 -p 4 -o traces/working_set.trace
# Temporal/spatial locality
./bin/trace_gen -t locality -n 12000 -o traces/locality.trace
# Thrashing pattern (pathological)
./bin/trace_gen -t thrashing -n 25000 -o traces/thrashing.traceOutput Formats
Console Summary
==================== SIMULATION SUMMARY ====================
Memory Accesses:
Total: 10000
Reads: 8000 (80.0%)
Writes: 2000 (20.0%)
Page Faults:
Total: 845
Fault Rate: 8.45%
TLB Performance:
Hits: 9234
Misses: 766
Hit Rate: 92.34%
...
JSON Output
Complete metrics including per-process breakdown (use -o filename.json)
CSV Output
Single-line format for spreadsheet analysis (use --csv filename.csv)
Build Targets
makeormake all- Build release versionmake debug- Build with debug symbols and sanitizersmake release- Build optimized versionmake test- Run test suitemake traces- Generate sample trace filesmake valgrind- Run with memory leak checkermake format- Format code with clang-formatmake clean- Remove build artifactsmake distclean- Remove all generated files
Architecture
See DESIGN.md for detailed architecture and design decisions.
See API.md for developer API documentation.
See TESTPLAN.md for test cases and acceptance criteria.
Extending the VMM
The simulator is designed for easy extension:
- Add New Replacement Algorithm: Implement in
src/replacement.c - Custom Trace Patterns: Extend
trace_generate()insrc/trace.c - Additional Metrics: Add counters in
src/metrics.h/c - Memory-Mapped Files: Extend page fault handler in
src/vmm.c - Copy-on-Write: Add COW logic to frame allocator and page fault handler
- Shared Memory: Implement reference counting in
FrameInfo
See docs/API.md for extension points.
Performance Optimization
The implementation includes several optimizations:
- Bitmap for Free Frames: O(1) frame allocation
- Hash-based Page Tables: For sparse address spaces (in two-level PT)
- Approximate LRU: O(1) replacement using aging counters
- Efficient TLB: Direct search with LRU tracking
- Cache-friendly Data Structures: Contiguous arrays where possible
Compile with optimizations:
make releaseDependencies
- GCC or compatible C compiler (C11 standard)
- GNU Make
- bc (for test arithmetic)
- clang-format (optional, for code formatting)
- valgrind (optional, for memory leak checking)
Troubleshooting
Compilation Errors
- Ensure GCC supports C11:
gcc --version - Install missing dependencies:
sudo apt-get install build-essential
Trace File Errors
- Verify trace format: each line must be
pid op addr - Check file permissions:
ls -l traces/
Segmentation Faults
- Run with debug build:
make debug && ./bin/vmm_debug ... - Use valgrind:
make valgrind - Enable debug logging:
./bin/vmm ... -D
License
This project is released for educational and research purposes.
Authors
Development Team:
- Aditya Pandey - Core VMM implementation, memory management subsystems
- Kartik - Page table implementation, replacement algorithms
- Vivek - TLB simulation, metrics collection and reporting
- Gaurang - Trace generation, testing framework, documentation
This project was collaboratively developed as a comprehensive teaching/learning tool for operating systems courses and virtual memory research.
References
- Operating System Concepts by Silberschatz, Galvin, and Gagne
- Modern Operating Systems by Andrew S. Tanenbaum
- Linux kernel memory management documentation