Memory Management Simulator
This project simulates operating system memory management at a user-space level. It models: Dynamic memory allocation using:
- First Fit
- Best Fit
- Worst Fit
- Buddy allocator
Multilevel CPU caches (L1 and L2) with configurable block size and associativity. Virtual memory using paging with page table and simple page replacement. Memory statistics and metrics, including fragmentation, utilization, and allocation success/failure rates. This is not an actual OS kernel, but a detailed simulation for educational and testing purposes.
memory-simulator/ ├── src/ │ ├── allocator/ │ │ └── memory_manager.cpp / .h │ ├── buddy/ │ │ └── buddy_allocator.cpp / .h │ ├── cache/ │ │ └── cache.cpp / .h │ ├── virtual_memory/ │ │ ├── VirtualMemory.cpp / .h │ │ └── TLB.cpp / .h │ └── main.cpp ├── tests/ │ ├── first_fit_basic.txt │ ├── best_fit_fragmentation.txt │ ├── worst_fit_behavior.txt │ ├── buddy_basic.txt │ ├── buddy_merge.txt │ ├── buddy_internal_fragmentation.txt │ ├── cache_log.txt │ ├── cache_11_12.txt │ ├── virtual_memory_basic.txt │ ├── full_pipeline.txt │ └── outputs/ # Stores test outputs ├── include/ ├── docs/ ├── run_tests.sh ├── Makefile ├── memsim.exe └── README.md
🔹 Option 1: Automated Setup (Recommended)
- Use the provided setup script (works in Git Bash / Linux / WSL):
chmod +x setup.sh
./setup.shThis will:
- Compile the project
- Generate memsim (use this to test the scripts - memsim has already been added in case installation problem)
- Automatically create run_tests.sh
- Outputs are saved in tests/outputs/ folder.
All test workloads are stored in the tests/ directory. Run the full test suite:
./run_tests.sh✔ Outputs are saved in:
tests/output/The project includes the following test artifacts:
-
Memory Allocation Tests
- buddy_basic.txt
- buddy_merge.txt
- buddy_internal_fragmentation.txt
- first_fit_basic.txt
- best_fit_fragmentation.txt
- worst_fit_behavior.txt
-
Cache Tests
- cache_log.txt
- cache_11_12.txt
-
Virtual Memory Tests
- virtual_memory_basic.txt
-
End-to-End Test
- full_pipeline.txt
-
Each test validates:
- Allocation correctness
- Fragmentation behavior
- Cache hit/miss tracking
- Page faults and TLB behavior
-
Memory Allocation Algorithms:
- First Fit
- Best Fit
- Worst Fit
- Buddy Allocator (splitting and merging)
-
Memory Metrics:
- Total memory
- Used memory
- Free memory
- Internal fragmentation
- External fragmentation
- Allocation success/failure rate
- Memory utilization
-
Cache Simulation:
- L1 and L2 caches
- FIFO replacement (LRU optional)
- Tracks hits and misses
-
Virtual Memory Simulation:
- Paging
- Page table
- Page hits and faults
- Optional disk latency simulation
-
Integration:
Virtual address → Page Table → Physical Memory → Cache → RAM
The simulator reports:
-
Memory
- Allocation requests
- Successful / failed allocations
- Internal & external fragmentation
- Memory utilization
-
Cache
- L1 cache hits & misses
- L2 cache hits & misses
-
Virtual Memory
- Page hits
- Page faults
https://drive.google.com/drive/folders/1m7OwzK-W1MICDUqCmw6kZCg1oRbF7VG_?usp=sharing
Nishant Singh