Skip to content

LinkisLethe/VM_Simulator

Repository files navigation

Virtual Memory Manager Simulator

简体中文

CI C GCC Make License

This C11 simulator translates 16-bit logical addresses through a page table and a 16-entry translation lookaside buffer (TLB). It loads signed-byte values from a backing store, applies FIFO replacement to both the TLB and physical frames, and records translation statistics for a supplied address trace.

Features

  • Configurable page size and physical frame count
  • FIFO page replacement with invalidation of stale TLB entries
  • FIFO TLB replacement without duplicate insertion on page faults
  • Logical-to-physical address translation and signed-byte lookup
  • Strict validation for configuration values, address traces, and input files
  • Reproducible regression test using the included 1,000-address workload

Build and run

On Linux or macOS:

make
./mmu 10 32 > output.txt

On Windows with GCC:

gcc -std=c11 -O2 -Wall -Wextra -Wpedantic mmu_simulator.c -o mmu.exe
.\mmu.exe 10 32 > output.txt

The first argument is the number of offset bits, so 10 selects a 1,024-byte page. The second argument is the physical frame count. Running without arguments starts the interactive prompts.

The full command form accepts alternate fixture and output paths:

mmu frame-size-bits number-of-frames addresses-file backing-store statistics-file

Reference workload

The command ./mmu 10 32 processes the included files and writes these values to stat.txt:

Metric Result
Logical addresses 1,000
Page faults 501
Page-fault rate 0.501000
TLB hits 234
TLB hit rate 0.234000

Detailed translations are written to standard output. Redirect them to a file when needed; generated executables, output.txt, and stat.txt are ignored by Git.

Test

On Linux or macOS:

make test

On Windows:

python tests/test_mmu.py .\mmu.exe

The test checks the reference statistics, rejects an invalid physical-memory configuration, and rejects a malformed address trace.

Repository contents

mmu_simulator.c        MMU simulator implementation
addresses.txt          Included logical-address trace
backingstore.bin       Included 65,536-byte backing store
tests/test_mmu.py      Standard-library regression test
Makefile               GCC build and test commands

Scope

The simulator models a single process with a 16-bit logical address space. It implements FIFO policies only and does not model dirty pages, write-back, protection bits, multilevel page tables, or concurrent memory accesses.

License

Source code and documentation are licensed under the MIT License. The supplied workload files are described separately in NOTICE.

About

C11 virtual memory simulator with FIFO page and TLB replacement, input validation, and reproducible tests.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages