CLI-based Operating System memory management simulator that models how modern OSes handle physical memory allocation, virtual memory, and cache hierarchy, with real-time statistics and visualization.
This project focuses on systems-level design, algorithmic correctness, and performance trade-offs in memory management.
- Simulate dynamic memory allocation and deallocation
- Implement multiple allocation strategies
- Model multilevel CPU cache hierarchies
- Implement paging-based virtual memory
- Observe fragmentation, cache behavior, and page faults
- Simulates a contiguous block of physical memory
- Dynamic allocation and deallocation
- Allocation strategies:
- First Fit
- Best Fit
- Worst Fit
- Correct block splitting and coalescing
- Tracks:
- Used / free memory
- External fragmentation
- Allocation success / failure
- Memory utilization
- Power-of-two memory management
- Allocation size rounded to nearest power of two
- Recursive block splitting
- Buddy coalescing on deallocation
- Tracks:
- Internal fragmentation
- Allocation statistics
- Memory utilization
AUTO— Power-of-two requests routed to Buddy allocatorPHYSICAL— Always use physical allocatorBUDDY— Always use buddy allocatorFORCED— Explicit override mode
- Paging-based virtual memory
- Per-process page tables
- Virtual → Physical address translation
- Page replacement policies:
- FIFO
- LRU
- CLOCK
- Tracks:
- Page faults
- Page replacements
- Page fault rate
- Free / total frames
- Multi-level cache hierarchy:
- L1 Cache
- L2 Cache
- L3 Cache
- Configurable cache size, line size, and associativity
- Replacement policies:
- FIFO
- LRU
- Memory access flow:
Virtual Address → Page Table → Physical Address → L1 → L2 → L3 → Main Memory
- Cache hits and misses per level
- Hit ratios
- Main memory accesses
- Average Memory Access Time (AMAT)
The simulator provides an interactive command-line interface to control all components of the memory system.
memsim> init
memsim> create 1
memsim> setproc 1
memsim[P1 | AUTO | LRU]> alloc 4KB
memsim[P1 | AUTO | LRU]> access 0
memsim> statsinit— Initialize the memory systemquit— Exit the simulatorhelp— Display all available commands
create <pid>— Create a new processsetproc <pid>— Set current process contextterminate <pid>— Terminate a processprocess [pid]— Display process information
alloc <size>— Allocate memory (supports B / KB / MB)free <pid> <address>— Free allocated memorymode <auto|buddy|physical|forced>— Set allocation modestrategy <first|best|worst>— Set physical allocation strategy
access <address> [write]— Access virtual memorypolicy <fifo|lru|clock>— Set page replacement policy
dump— Dump physical memory layoutstats— Show system statisticsbench [alloc|cache]— Run benchmarkstest [name]— Run predefined memory tests
color <on|off>— Toggle colored output
- C++17 compatible compiler
- CMake
- Ninja (recommended)
mkdir build
cd build
cmake ..
ninja
./memory-simulatormemory-simulator/
├── src/
│ ├── allocator/
│ ├── buddy/
│ ├── cache/
│ ├── virtual_memory/
│ ├── cli/
│ └── main.cpp
├── include/
├── tests/
├── docs/
├── CMakeLists.txt
└── README.md
- Clean separation between allocators, cache, and virtual memory
- Modular and extensible architecture
- Accurate modeling of OS memory-management behavior
- Emphasis on correctness and performance trade-offs
- No real disk I/O (page faults are symbolic)
- Single-threaded simulation
- Timing values are relative, not hardware-accurate






