A comprehensive operating system memory management simulator that implements dynamic memory allocation strategies, multilevel cache simulation, and virtual memory with paging.
Demo Video:
Synapse.Demo.Video.1.mp4
-
Physical Memory Allocation
- First Fit, Best Fit, Worst Fit strategies
- Dynamic block splitting and coalescing
- Fragmentation analysis
-
Buddy Allocation System
- Power-of-2 allocation
- Fast allocation/deallocation
- Automatic buddy coalescing
-
Multilevel Cache Simulation
- L1, L2, L3 cache support
- Configurable size, block size, and associativity
- FIFO, LRU, LFU replacement policies
-
Virtual Memory
- Paging with configurable page size
- Address translation
- FIFO, LRU, Clock page replacement
- Page fault handling
- Memory utilization
- Internal and external fragmentation
- Cache hit/miss ratios
- Page fault rates
- Allocation success rates
- C++17 compatible compiler (g++ 7.0 or later)
- Make
- Linux/Unix environment (or WSL on Windows)
# Clone or navigate to the project directory
cd Synapse
# Build the project
make
# Clean build files
make clean
# View available make targets
make helpThe executable will be created at bin/memsim.
Run the simulator without arguments for interactive mode:
./bin/memsimRun with a workload file:
./bin/memsim tests/workload1_basic_allocation.txt# Initialize physical memory (size in bytes)
init memory <size>
# Initialize buddy allocator (size and minimum block size)
init buddy <size> <min_block_size>
# Initialize virtual memory (virtual_bits, page_size, physical_size)
init virtual <vbits> <psize> <physize>
# Initialize cache (level, size, block_size, associativity, policy)
init cache <level> <size> <block> <assoc> <policy>
# Example: init cache L1 1024 64 4 lru# Set allocation strategy (first_fit, best_fit, worst_fit)
set allocator <strategy># Allocate memory (returns block ID)
malloc <size>
# Free memory block
free <block_id>
# Access memory address (for cache/VM simulation)
access <address> [write]# Display memory layout
dump memory
# Display statistics
stats
# Display cache statistics
cache stats
# Display virtual memory statistics
virtual stats
# Show help
help
# Exit simulator
exit$ ./bin/memsim
> init memory 1024
> set allocator first_fit
> malloc 100
Allocated block id=1 size=100 bytes
> malloc 200
Allocated block id=2 size=200 bytes
> dump memory
> stats
> free 1
> dump memory
> exit$ ./bin/memsim
> init buddy 1024 64
> malloc 50
Allocated block id=1 size=50 bytes
> malloc 100
Allocated block id=2 size=100 bytes
> dump memory
> stats
> exit$ ./bin/memsim
> init cache L1 512 64 2 lru
> init cache L2 2048 64 4 fifo
> access 0
> access 64
> access 128
> access 0
> cache stats
> exit$ ./bin/memsim
> init virtual 16 256 4096
> access 0
> access 256
> access 4096
> virtual stats
> exitThe tests/ directory contains comprehensive test workloads:
- workload1_basic_allocation.txt - Basic allocation and deallocation
- workload2_best_fit.txt - Best fit strategy testing
- workload3_worst_fit.txt - Worst fit strategy testing
- workload4_buddy_system.txt - Buddy allocator testing
- workload5_cache.txt - Cache simulation
- workload6_virtual_memory.txt - Virtual memory testing
- workload7_integrated.txt - Full system integration
- workload8_fragmentation.txt - Fragmentation analysis
- workload9_cache_policies.txt - Cache policy comparison
- workload10_stress_test.txt - Stress testing
# Run a specific test
make run-workload FILE=tests/workload1_basic_allocation.txt
# Run all tests
make testmemory-simulator/
├── bin/ # Compiled executables
├── build/ # Object files
├── docs/ # Documentation
│ |── DESIGN_DOCUMENT.md # Detailed design documentation
│ |── TESTING.md # Guide for testing/ workloads
│ └── USER_GUIDE.md # A comprehensive user guide
├── include/ # Header files
│ ├── buddy_allocator.h
│ ├── cache.h
│ ├── memory_block.h
│ ├── physical_memory.h
│ ├── simulator.h
│ └── virtual_memory.h
├── src/ # Source files
│ ├── allocator/
│ │ └── physical_memory.cpp
│ ├── buddy/
│ │ └── buddy_allocator.cpp
│ ├── cache/
│ │ └── cache.cpp
│ ├── virtual_memory/
│ │ └── virtual_memory.cpp
│ ├── main.cpp
│ └── simulator.cpp
├── tests/ # Test suite (10 workloads)
│ ├── run_all_tests.sh # Automated test runner
│ ├── workload1_basic_allocation.txt
│ ├── workload2_best_fit.txt
│ ├── workload3_worst_fit.txt
│ ├── workload4_buddy_system.txt
│ ├── workload5_cache.txt
│ ├── workload6_virtual_memory.txt
│ ├── workload7_integrated.txt
│ ├── workload8_fragmentation.txt
│ ├── workload9_cache_policies.txt
│ └── workload10_stress_test.txt
├── Makefile # Build configuration
└── README.md # This file
- First Fit: Fast allocation, moderate fragmentation
- Best Fit: Better space utilization, slower allocation
- Worst Fit: Leaves larger holes, can exhaust large blocks
- Memory size must be power of 2
- Allocations rounded to power of 2
- Fast O(log n) allocation and deallocation
- Automatic coalescing with buddy blocks
- Configurable multi-level cache
- Set-associative organization
- Multiple replacement policies
- Realistic hit/miss propagation
- Page-based address translation
- Demand paging simulation
- Multiple page replacement algorithms
- Page fault tracking
| Operation | Time Complexity | Notes |
|---|---|---|
| First/Best/Worst Fit | O(n) | n = number of blocks |
| Buddy Allocation | O(log n) | n = memory size |
| Cache Access | O(k) | k = associativity |
| Page Translation | O(1) | Direct page table lookup |
| Page Fault | O(n) | n = number of frames |
- Total memory size
- Used/free memory
- Memory utilization percentage
- External fragmentation
- Internal fragmentation
- Allocation success rate
- Total accesses
- Hits and misses
- Hit ratio and miss ratio
- Per-level statistics
- Page faults and hits
- Page fault rate
- Disk accesses
- Page table state
This is an educational simulator with the following simplifications:
- Single process model
- Symbolic disk I/O (no actual disk access)
- Simplified cache model (no write-back, coherence)
- No memory protection or access control
- Fixed page size per simulation
- No TLB (Translation Lookaside Buffer)
- Deterministic behavior (no concurrency)
See docs/DESIGN_DOCUMENT.md for detailed information.
This simulator is designed for:
- Operating systems courses
- Computer architecture courses
- Systems programming education
- Algorithm comparison and analysis
- Performance trade-off understanding
The modular design allows easy extension:
- New Allocation Strategies: Implement in
PhysicalMemoryclass - New Cache Policies: Add to
ReplacementPolicyenum and implement - New Page Replacement: Add to
PageReplacementPolicyand implement - Additional Metrics: Extend statistics tracking in each component
- Visualization: Add graphical output capabilities
# Ensure you have C++17 support
g++ --version
# Clean and rebuild
make clean
make# Check file permissions
chmod +x bin/memsim
# Verify workload file format
cat tests/workload1_basic_allocation.txtWhen extending this project:
- Follow the existing code structure
- Add appropriate test workloads
- Update documentation
- Ensure clean compilation with no warnings
- Test thoroughly with various configurations
- Operating System Concepts by Silberschatz, Galvin, Gagne
- Modern Operating Systems by Andrew Tanenbaum
- Computer Architecture: A Quantitative Approach by Hennessy & Patterson
This is an educational project. Feel free to use and modify for learning purposes.
Memory Management Simulator Project
- v1.0 (December 2025)
- Initial release
- All core features implemented
- Comprehensive test suite
- Full documentation
For questions or issues, please refer to the design document or create an issue in the project repository.
Happy Simulating! 🚀