A Python library to simulate memory management techniques like allocation, segmentation, swapping, TLB, pagination and the Buddy System using Jupyter notebooks.
The Memory Management Examples repository demonstrates key memory management concepts implemented in Python using Jupyter notebooks. The goal is to provide clear, visual, and interactive examples of how memory is managed in an operating system, with a focus on the following concepts:
- Segmentation: Dividing memory into variable-sized blocks.
- Memory Allocation: Implementing allocation strategies such as First-fit, Best-fit, and Worst-fit.
- Swapping: Managing processes in limited memory spaces.
- Translation Lookaside Buffer (TLB): A cache to speed up virtual memory access.
- Pagination: Implementing page tables and a paging system.
- Buddy System: Implementing the buddy memory allocation
This project is designed for anyone learning about memory management or those looking to simulate memory management techniques in Python.
To run the examples, you need python >= 3.10 and the required dependencies installed
-
Clone this repository:
git clone https://github.com/lorenzomaiuri-dev/memory-management-examples.git cd memory-management-examples
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Linux/Mac venv\Scripts\activate # On Windows
-
Install the dependencies
pip install -r requirements.txt
You can explore the concepts interactively by running the Jupyter notebooks
Here’s a list of Jupyter notebooks you can run to see the different memory management strategies in action:
- segmentation.ipynb: simulates memory allocation using segmentation. This simulation models physical memory, allocates segments for processes, and displays the memory allocation
- swapping_FIFO.ipynb: simulates swapping, a memory management technique where an entire process is moved between memory and disk (secondary storage). This simulation includes the concepts of physical memory, a "swap area" (disk), and process swapping.
- allocation.ipynb: simulates First Fit, Best Fit, and Worst Fit allocation algorithms for dynamic memory allocation. This simulation implement and compare these memory allocation strategies for managing free memory blocks in a contiguous memory system
- pagination.ipynb: simulates pagination and the FIFO page replacement policy
- TLB.ipynb: simulates how a TLB (Translation Lookaside Buffer) caches virtual-to-physical address mappings to speed up address translation
- buddy_system.ipynb: simulates how the Buddy Memory Allocation works, splitting the memory into halfs to try to satisfy a memory request as suitably as possible
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository
- Create a new branch (git checkout -b feature/your-feature)
- Commit your changes (git commit -am 'Add new feature')
- Push the branch (git push origin feature/your-feature)
- Open a Pull Request
Please ensure all pull requests pass the existing tests and include new tests for any added functionality
This project is licensed under the GPL-3.0 License. See the LICENSE file for more details
Special thanks to all contributors and resources that made this project possible