OPERATING SYSTEM BASICS
This book covers the core topics in operating system including process management ,memory and file systems.
3. MEMORY MANAGEMENT
3.1. MEMORY ALLOCATION TECHNIQUES
There are two main types of memory allocation: static and dynamic. The OS uses various techniques to allocate memory effectively to ensure optimal performance and to prevent problems such as fragmentation and memory leaks.
3.1.1 Contiguous Memory Allocation
In this method, each process is allocated a single contiguous block of memory. This is simple and fast but can lead to fragmentation.
-
Fixed Partitioning: The memory is divided into fixed-sized blocks. Each block can hold exactly one process. This may waste space if a process is smaller than the partition.
-
Variable Partitioning: The memory is divided based on the actual size of the processes. This is more efficient but can still lead to external fragmentation, where free memory is split into small non-contiguous blocks.
3.1.2 Non-Contiguous Memory Allocation
To overcome fragmentation issues, non-contiguous methods are used, such as:
-
Paging: Memory is divided into fixed-size blocks called pages, and physical memory is divided into frames of the same size. Pages can be loaded into any frame, which eliminates external fragmentation.
-
Segmentation: The process is divided into variable-sized segments like code, data, and stack. Each segment is stored in a different location in memory.
-
Paging with Segmentation: Combines both techniques for more efficient memory use and protection.