A comprehensive user-space simulator that models how operating systems manage physical memory, CPU caches and virtual memory. This educational tool demonstrates core OS memory management concepts through algorithmic correctness, realistic behavior, and clean modular design.
This video showcases the various functions that have been incorporated in this simulator
https://drive.google.com/file/d/1uHfcS9eK97FwVZj5_RyZQlIQUtZzNGV2/view?usp=sharingThe simulator implements a complete memory management pipeline:
Virtual Address → Page Table → Physical Address → Cache (L1 → L2) → Physical Memory
This is a faithful conceptual simulation implemented in user space: not a real OS kernel, but an accurate representation of how these systems work.
- Contiguous memory simulation with dynamic allocation/deallocation
- Block splitting and coalescing
- Three allocation strategies: First Fit, Best Fit, and Worst Fit
- Explicit tracking of free and allocated blocks
- Multilevel cache system (L1 and L2)
- Set-associative cache design
- FIFO and LRU replacement policies
- Hit/miss tracking with Average Memory Access Time (AMAT) calculation
- Miss penalty propagation between cache levels
- Paging-based virtual memory with 256-byte pages
- Page tables with valid bit tracking
- FIFO and LRU page replacement algorithms
- Page fault and eviction monitoring
- Physical address translation before cache access
- External fragmentation calculation
- Allocation success/failure rates
- Memory utilization metrics
- Cache performance analysis
- Page fault tracking
C++17 compatible compiler (tested with g++)
g++ -std=c++17 -Iinclude src/main.cpp src/allocator/*.cpp src/cache/*.cpp src/vm/*.cpp src/buddy/*.cpp -o memory_simInteractive mode:
./memory_sim Scripted workloads(Example):
./memory_sim < tests/allocator_basic.txt init <size>
Initialize physical memory with the specified size in bytes.
init 1024alloc <strategy> <size>
Allocate memory using the specified strategy (first/best/worst).
alloc first 100free <block_id>
Deallocate the memory block with the given ID.
free 3access <virtual_addr>
Access a virtual memory address (triggers address translation, cache lookup, potential page faults).
access 512dump
Display the current state of memory (all allocated and free blocks).
stats
Show allocation statistics including success/failure rates and fragmentation.
cache_stats
Display cache performance metrics (hits, misses, hit rate, AMAT).
vm_stats
Show virtual memory statistics (page faults, evictions, resident pages).
help
Display all available commands.
memory-simulator/
├── src/
│ ├── allocator/ # Memory allocation algorithms
│ ├── cache/ # Cache hierarchy implementation
│ ├── vm/ # Virtual memory system
│ └── main.cpp # CLI and main loop
├── include/ # Header files
├── tests/ # Scripted workload files
├── logs/ # Outputs of the tests
├── DOCUMENTATION.md # Detailed design documentation
└── README.md
The tests/ directory contains scripted workloads demonstrating:
- Memory allocation and deallocation patterns
- Fragmentation behavior across strategies
- Cache locality and conflict scenarios
- Page fault triggering and replacement
- End-to-end system integration