A professional, interactive visual simulator for the classic UNIX System V buffer cache management algorithms (getblk and brelse). This tool is designed for Computer Science students to visualize kernel-level disk I/O buffering.
Built with the cutting-edge React 19.2 and Tailwind CSS v4.2 stack.
- Dynamic Initialization: Configure the number of Hash Queues and initial disk blocks via a sleek Setup Wizard upon launch.
- Real-time Animations: Watch blocks physically slide between Hash Queues, the Free List, and Waiting Queues using Framer Motion layout transitions.
- Textbook Logic: Faithful implementation of all 5 textbook scenarios of the
getblkalgorithm. - Interactive Controls: Request blocks, release them, or manually mutate states (Free, Busy, Delayed) to trigger specific kernel behaviors.
- Live Terminal Logs: A dedicated system log tracks every kernel decision, process sleep, and wakeup signal.
- Educational Documentation: Always-visible guides and a VS Code-themed pseudocode editor to learn the theory while you play.
The UNIX kernel rarely reads/writes directly to a hard disk. Instead, it uses a Buffer Cache in main memory to speed up operations. The getblk algorithm is the "manager" that finds or allocates memory for disk blocks.
- Cache Hit: The block is already in the Hash Queue and is Free. The kernel locks it and hands it to the process.
- Cache Miss: The block is not in memory. The kernel grabs the oldest buffer from the Free List (Least Recently Used), reassigns it to the new block, and moves it to the correct Hash Queue.
- Locked Block: The block is found, but it is Busy (locked by another process). The requesting process goes to sleep.
- Out of Memory: The block is not found, and the Free List is completely empty. The process goes to sleep waiting for any buffer to be released.
- Delayed Write: The kernel tries to reuse a buffer from the Free List, but it contains unsaved modifications. It initiates an Asynchronous Write and restarts the search.
For a deep dive into the underlying logic, check out the original C++ implementation of this algorithm here:
👉 View Full C++ Gist on GitHub
When you first load the app, you will see the System Setup screen.
- Hash Queues: Enter how many bins you want to organize blocks into (Default is 4).
- Initial Blocks: Enter the total number of blocks to start with.
- Assign Block Numbers: A list of emerald-bordered inputs will appear. Enter your starting block IDs here. These inputs strictly allow only numbers and highlight individually on focus.
Once initialized, you have full control over the kernel:
- [getblk]: Type a Block ID in the control panel to request it. Watch the animations as blocks slide between Hash Queues and the Free List.
- [brelse]: Type a Busy block's ID and click release to return it to the back of the Free List (LRU policy).
- Force Status: Manually set blocks to Delayed or Busy to test how the algorithm reacts to Scenario 3 or Scenario 5.
App.jsx: Main entry point and high-level layout.useBufferCache.js: The "Brain" - holds the full C++ logic translated to React state.SetupScreen.jsx: Dynamic initialization wizard with numeric validation and glowing focus highlights.AlgorithmModal.jsx: Theory guide with VS Code-style syntax highlighting.GuideModal.jsx: Step-by-step interactive user walkthrough.Block.jsx: Animated UI component for the disk blocks.
- React 19.2: Utilizing Concurrent Rendering and optimized hooks.
- Tailwind CSS v4.2: Ultra-fast CSS-first styling engine.
- Framer Motion: Smooth "sliding" layout animations.
- Lucide React: Professional system iconography.
-
Clone the repository: git clone https://github.com/your-username/unix-buffer-simulator.git
-
Install Dependencies: npm install
-
Run Development Server: npm run dev
-
Build for Production: npm run build
MIT License - Feel free to use this for educational purposes.