← Back to Home

Operating Systems Lab: Page Replacement

Project Overview

This engineering lab focuses on simulating and evaluating memory management subsystem performance metrics. Developed natively in C++, the program processes page reference streams loaded dynamically via data files or user keyboard entry loops. By adjusting available frame boundaries, the system tracks and reports comparative page fault trends to demonstrate kernel processing trade-offs.

Algorithmic Architectures Explored

The lab implements and runs performance benchmark comparisons across three foundational memory layout scheduling policies:

Core C++ Implementation Analytics

The project relies heavily on the C++ Standard Template Library (STL) to organize state data tracking. Unordered sets handle high-speed page hits, while vectors capture reference constraints to simulate memory behaviors cleanly.

C++ Architecture: FIFO Engine
// FIFO Page Replacement Simulation
int fifo(const vector<int>& refString, int frames) {
    unordered_set<int> memory;
    queue<int> q;
    int faults = 0;

    for (int page : refString) {
        if (memory.find(page) == memory.end()) {
            faults++;
            if (memory.size() == frames) {
                int old = q.front();
                q.pop();
                memory.erase(old);
            }
            memory.insert(page);
            q.push(page);
        }
    }
    return faults;
}
C++ Architecture: LRU Tracker
// Least Recently Used Replacement Engine
int lru(const vector<int>& refString, int frames) {
    unordered_set<int> memory;
    unordered_map<int, int> recent;
    int faults = 0;

    for (size_t i = 0; i < refString.size(); i++) {
        int page = refString[i];
        if (memory.find(page) == memory.end()) {
            faults++;
            if (memory.size() == frames) {
                int lruPage = -1, lruTime = INT_MAX;
                for (int p : memory) {
                    if (recent[p] < lruTime) {
                        lruTime = recent[p];
                        lruPage = p;
                    }
                }
                memory.erase(lruPage);
            }
            memory.insert(page);
        }
        recent[page] = i;
    }
    return faults;
}

Simulation Runtime Execution Output

The interactive console window below tracks standard keyboard stream injections along with the comparative evaluations emitted by the processing engine:

Enter 'f' to read from file or 'k' to enter via keyboard: k Enter reference string (seperates by commas: 6, 3, 0, 1, 0, 3, 6, 6, 5, 5, 3, 0, 1, 7, 1, 4, 0, 2, 1, 4, 7, 2, 1, 7 Enter number of frames: 4 Using 4 frames: FIFO Page Faults: 11 Optimal Page Faults: 8 LRU Page Faults: 10 Program ended with exit code: 0

Lab Environment Metrics