Written in Java, it is meant to be a helper in the process of learning how OS manages the memory of the computer.
This Java-based tool simulates the translation of virtual addresses into physical addresses, demonstrating how modern hardware and software coordinate memory access.
Key Objectives:
- Visualize the translation flow from Virtual Addresses to Physical Addresses.
- Demonstrate the role of the TLB (Translation Lookaside Buffer) and Page Table.
- Simulate Page Fault handling and data retrieval from Secondary Storage (Disk).
- Implement and visualize the LRU (Least Recently Used) replacement algorithm for both RAM and TLB.
-
Parameters of simulation at choice or default: the user can provide his own parameters, but they are verified to be powers of 2.
-
-
Interactive Address Decomposition: Decomposes user-input virtual addresses into Page Numbers and Offsets.
-
Step-by-Step Execution: A "Next Step" mechanism allows users to follow the simulation at their own pace through a snapshot system.
-
Real-time Visualization: Graphical displays show the current state of TLB, Page Tables, RAM, and Disk.
-
Automated Testing: Features a "Demo Mode" for random or sequential page access sequences.
-
Performance Metrics: Real-time monitoring of Hit and Miss rates.
The simulator is built with a modular structure where each class represents a hardware or software entity:
- MemoryManager: Acts as the system controller, orchestrating the translation logic and page fault management.
- TLB: A fast associative cache mapping Page IDs to Frame IDs.
- PageTable: Maps virtual pages to physical frames and tracks state bits like Valid and Dirty.
- PhysicalMemory (RAM): Represents the main memory where active pages are stored in frames.
- Disk: Serves as secondary storage for pages not currently in RAM.
- Replacement: Implements the LRU algorithm to identify victim pages when memory is full.
- Language: Java
- UI Framework: Swing (
javax.swing) - Data Structures: Uses
Map<Page, Integer>for page tables andMap<Integer, String>for memory storage
Address Translation Logic:
Page Number = Virtual Address / Page SizeOffset = Virtual Address % Page Size
- Search TLB: Checks for an immediate mapping. A TLB Hit completes the translation.
- Search Page Table: On a TLB Miss, the system checks the Page Table for a RAM Hit.
- Handle Page Fault: If the page is not in RAM, it is fetched from Disk. If RAM is full, the LRU Algorithm selects a page to replace.
- Update Structures: The TLB and Page Table are updated with the new mapping.
- LRU Update: The
lastTimeUsedtimestamp is updated for every access to ensure correct replacement priority.
- Ensure you have the JDK installed.
- Clone the repository