Simulation of Unix's Buffer Cache. This Simulation is implemented in Python. This serves as a tool to give some insight into how Buffer Cache in Unix Operating System handles all the Process requests for read/write operations.
- Python
- Linux / Unix Terminal (Some Terminals don't support the escape codes for colours, and may output poorly formated results)
Simply run the main.py
file using the command > python main.py
.
This is a simple command-line Simulation of Unix's Buffer Cache Management System. Using this you can simulate the scenarios which can occur while handling the read/write requests of different processes in a Unix System.
Buffer Cache is a fast memory which OS uses to perform the read/write operations much quicker than reading/writing directly from the secondary storage devices (which is comparatively slower). It maintains several buffers of some predefined sizes and uses them to store data which gets read from/written to secondary storage devices and allocates these buffers to Processes requesting to read data from storage.
Buffer Cache uses getblk
algorithm to handle allocation of buffers to processes.
There are 5 different Scenarios which you can encounter in the getblk
algorithm, namely :
- Block in the hash queue, and its buffer is free.
- Cannot find a block on the hash queue => allocate a buffer from the free list.
- Cannot find a block on the hash queue => allocate a buffer from the free list but buffer on the free list marked “delayed write” => flush “delayed write” buffer and allocate another buffer.
- Cannot find a block on the hash queue and free list of the buffer is also empty.
- Block in the hash queue, but the buffer is busy. All of these 5 scenarios with their corresponding Hash Tables are shown in the Scenarios folder.
Following are a few of the snapshots of the user interface for this tool. You can find more snapshots in the imgs folder.