This project is a simulation of a virtual memory system implemented in C. It simulates the translation of virtual addresses to physical addresses using a two-level page table, TLB (Translation Lookaside Buffer), and physical memory (DRAM). The simulation tracks various statistics such as page faults, TLB hits, and average memory usage.
- C compiler (e.g., GCC)
- Make tool
- Clone the repository:
git clone <repository_url>
- Navigate to the project directory:
cd <os_project>
- Compile the code:
make
- Generate random addresses:
./seed.sh
- Run the program with the address file:
./vm_sim ./data/address_file.txt
- Clean page table binaries in data dir after running a simulation (for predictable behaviour)
make clean
Alternatively you could just do
./run.shbut make sure to give execute permissions to file withchmod 777 run.sh
Upon running the program, you'll be prompted to select various options:
- Logging address translations: Choose whether to log each address translation.
- TLB and Page Replacement Algorithm: Choose between FIFO and LRU policies.
- Process Translation Access Pattern: Choose the access pattern for address translation (Sequential, Random, Locality of Reference, Repeated).
- Number of Processes to Simulate: Specify the number of processes to simulate.
- main.c: Entry point of the program containing the main logic.
- vmTypes.h: Header file containing custom data types and structures.
- dTypes.h: Header file containing constants and macros used in the program.
- Page Tables: Implemented as two-level page tables consisting of a page directory and page tables.
- TLB: Simulated as a cache for frequently accessed translations.
- Physical Memory: Represented as DRAM (Dynamic Random Access Memory) storing page frames.
- Address Translation: Virtual addresses are translated to physical addresses using page tables and TLB.
- Page Fault Handling: Page faults are handled by loading pages from disk into physical memory.
- Page Fault Rate: Percentage of address translations resulting in page faults.
- TLB Hit Rate: Percentage of TLB accesses resulting in cache hits.
- Average Time Spent Retrieving Data from Disk: Average time (in milliseconds) spent reading data from disk.
- Average Memory Usage: Average amount of memory (in bytes) used during address translation.