Skip to content

Latest commit

 

History

History
323 lines (218 loc) · 7.21 KB

File metadata and controls

323 lines (218 loc) · 7.21 KB

Smart Memory Manager for Browser Tabs

Operating Systems Project | Page Replacement Simulation

Project Status: Active GitHub license GitHub repo size GitHub language count GitHub top language GitHub last commit

GitHub forks GitHub stars GitHub watchers


Languages & Tools

C GCC Makefile Git Markdown Windows Linux


Project Analysis

This project simulates browser tab memory behavior using classic page replacement algorithms from Operating Systems.

At a high level, it has three layers:

  1. Input and scenario setup
  2. Replacement algorithm execution
  3. Reporting and metrics visualization

Execution flow:

  1. The program reads total references, reference string, and frame count.
  2. You choose an algorithm from the menu: FIFO, LRU, or Optimal.
  3. The selected algorithm processes references step-by-step.
  4. The console prints tab openings/replacements and current memory frames.
  5. A summary reports total evictions and retention efficiency.

What It Does

  • Simulates tab replacement in constrained memory
  • Supports FIFO, LRU, and Optimal algorithms
  • Prints frame-by-frame state transitions
  • Reports total tab evictions (page faults)
  • Calculates tab retention efficiency
  • Uses browser-tab names for human-friendly output

Features

  • Interactive menu-driven terminal program
  • Clean modular structure (src/ + include/)
  • Browser-style page naming (Gmail, YouTube, StackOverflow, etc.)
  • Reusable utility helpers for output and metrics
  • Cross-platform Makefile with Windows/Linux handling
  • Sample demonstration cases in data/

Project Structure

smart-memory-manager/
├── Makefile
├── README.md
├── data/
│   └── sample_demonstration.txt
├── docs/
│   ├── references.txt
│   ├── Smart Memory Manager for Browser Tabs.pdf
│   └── SMART MEMORY MANAGER.pdf
├── include/
│   ├── fifo.h
│   ├── lru.h
│   ├── optimal.h
│   └── utils.h
└── src/
    ├── fifo.c
    ├── lru.c
    ├── main.c
    ├── optimal.c
    └── utils.c

Requirements

  • C compiler (gcc recommended)
  • Make utility (make, mingw32-make, or equivalent)
  • Git
  • Terminal (PowerShell, Bash, or Zsh)

Optional tools

  • Visual Studio Code for editing and debugging
  • WSL/MSYS2 on Windows for smoother GNU toolchain setup

Clone the Repository

git clone https://github.com/Code-Crew-Nexus/smart-memory-manager.git
cd smart-memory-manager

Compile

Option A: GNU Make (Linux/macOS, or Windows with make installed)

make clean
make

Option B: Windows with MSYS2/MinGW (mingw32-make)

mingw32-make clean
mingw32-make

Option C: Manual compile without Makefile

gcc -Wall -Iinclude -o memory_manager src/main.c src/fifo.c src/lru.c src/optimal.c src/utils.c

On Windows, the output executable is usually memory_manager.exe.


Run

Windows PowerShell

.\memory_manager.exe

Linux/macOS

./memory_manager

Input Format

The program asks for:

  1. Number of tabs in reference string (n)
  2. n space-separated integers as references
  3. Number of frames (tabs allowed in memory)
  4. Menu choice:
    • 1 FIFO
    • 2 LRU
    • 3 Optimal
    • 4 Exit

Example input:

7
0 1 2 0 3 0 4
3
1
4

Page (Tab) Mapping

  • 0 -> Gmail
  • 1 -> YouTube
  • 2 -> StackOverflow
  • 3 -> Twitter
  • 4 -> LinkedIn
  • 5 -> GeeksforGeeks
  • 6 -> Reddit
  • 7 -> WhatsApp Web

Any value outside this range maps to Unknown Tab.


Source File Responsibilities

src/main.c

  • CLI entry point
  • Reads input and handles algorithm menu loop

src/fifo.c

  • Implements FIFO replacement using cyclic pointer

src/lru.c

  • Implements LRU replacement using last-used index tracking

src/optimal.c

  • Implements Optimal replacement by checking farthest future use

src/utils.c

  • Maps page numbers to tab names
  • Prints frame state after each reference
  • Computes/display metrics

Algorithm Explanation

All algorithms process the same reference stream with limited frame capacity.

FIFO

  • Rule: evict the oldest loaded tab
  • Complexity per reference: $O(f)$ for frame search

LRU

  • Rule: evict the least recently used tab
  • Tracks recency index for each frame
  • Complexity per reference: $O(f)$

Optimal

  • Rule: evict the tab used farthest in the future (or never used again)
  • Theoretical lower bound for evictions
  • Complexity per reference can be up to $O(f \cdot n)$ due to look-ahead scans

Output Metrics

At the end of each algorithm run:

  • Total Tab Evictions (page faults)
  • Tab Retention Efficiency

Formula used:

((totalPages - pageFaults) / totalPages) * 100

Makefile Notes

The Makefile includes optional redirection targets (fifo, lru, optimal) that refer to:

  • data/ref_string1.txt
  • results/ output files

If you want to use those targets, create these resources first. Otherwise use interactive mode.


Troubleshooting

  • make not recognized on Windows

    • Use mingw32-make or install GNU Make.
  • gcc not recognized

    • Install a GCC toolchain and restart terminal.
  • Executable not launching in PowerShell

    • Run with ./ prefix equivalent: .\memory_manager.exe.
  • Unexpected tab labels

    • Use references mainly in 0-7; others are shown as Unknown Tab.

Future Improvements

  • Add batch input mode from file
  • Add side-by-side algorithm comparison report
  • Add automatic result export to results/
  • Add unit tests for replacement behavior
  • Add runtime complexity benchmark section

Contributors

This project was developed as part of the PBL initiative under Code-Crew-Nexus.

  • M. Sai Krishna
  • MD. Abdul Rayain
  • Rishit Ghosh
  • Yaram Karthik

Future contributors are welcome through issues and pull requests.