- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- Process Management
- Processes in Operating System
- States of a Process
- Process Schedulers
- Process Control Block
- Operations on Processes
- Inter Process Communication (IPC)
- Context Switching
- Multi-threading
- Scheduling Algorithms
- Process Scheduling
- Types of Scheduling
- Scheduling Algorithms Overview
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithm
- HRRN Scheduling Algorithm
- Priority Scheduling Algorithm
- Multilevel Queue Scheduling
- Lottery Scheduling Algorithm
- Starvation and Aging
- Turn Around Time & Waiting Time
- Burst Time in SJF Scheduling
- Process Synchronization
- Process Synchronization
- Solutions For Process Synchronization
- Hardware-Based Solution
- Software-Based Solution
- Critical Section Problem
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Peterson's Algorithm
- Dekker's Algorithm
- Bakery Algorithm
- Semaphores
- Binary Semaphores
- Counting Semaphores
- Mutex
- Turn Variable
- Bounded Buffer Problem
- Reader Writer Locks
- Test and Set Lock
- Monitors
- Sleep and Wake
- Race Condition
- OS Deadlock
- Introduction to Deadlock
- Conditions for Deadlock
- Deadlock Handling
- Deadlock Prevention
- Deadlock Avoidance (Banker's Algorithm)
- Deadlock Detection and Recovery
- Deadlock Ignorance
- Memory Management
- Memory Management
- Contiguous Memory Allocation
- Non-Contiguous Memory Allocation
- First Fit Algorithm
- Next Fit Algorithm
- Best Fit Algorithm
- Worst Fit Algorithm
- Fragmentation
- Virtual Memory
- Segmentation
- Buddy System
- Slab Allocation
- Overlays
- Paging and Page Replacement
- Paging
- Demand Paging
- Page Table
- Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Belady's Anomaly
- Thrashing
- Storage and File Management
- File Systems
- File Attributes
- Structures of Directory
- Linked Index Allocation
- Indexed Allocation
- Disk Scheduling Algorithms
- FCFS Disk Scheduling
- SSTF Disk Scheduling
- SCAN Disk Scheduling
- LOOK Disk Scheduling
- I/O Systems
- I/O Hardware
- I/O Software
- OS Types
- OS - Types
- OS - Batch Processing
- OS - Multiprocessing
- OS - Hybrid
- OS - Monolithic
- OS - Zephyr
- OS - Nix
- OS - Linux
- OS - Blackberry
- OS - Garuda
- OS - Tails
- OS - Clustered
- OS - Haiku
- OS - AIX
- OS - Solus
- OS - Tizen
- OS - Bharat
- OS - Fire
- OS - Bliss
- OS - VxWorks
- OS - Embedded
- OS - Single User
- Miscellaneous Topics
- OS - Security
- OS Questions Answers
- OS - Questions Answers
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Operating System - Contiguous Memory Allocation
In the context of operating systems, memory allocation refers to the process of assigning blocks of memory to various programs and processes running on a computer. The blocks of memory can be allocated continuously or non-continuously. Based on this, we have two types of memory allocation techniques: contiguous memory allocation and non-contiguous memory allocation.
In this chapter, we will discuss contiguous memory allocation, how to implement it in operating systems, and its advantages and disadvantages.
- Contiguous Memory Allocation
- Fixed Partitioning
- Dynamic Partitioning
- Advantages of Contiguous Memory Allocation
- Disadvantages of Contiguous Memory Allocation
Contiguous Memory Allocation
Contiguous memory allocation as the name suggests, allocates a single continuous block of memory to a process. The block of memory is allocated to a process is enough to hold the entire process. This means that the process can access all its memory locations without any interruptions.
The image below shows the main memory allocates storage to three processes P1, P2, and P3 using contiguous memory allocation −
In the image above, the process P1 is allocated 3 blocks of memory (F1, F2, and F3). P2 is allocated 2 blocks of memory (F5 and F6). Similarly, P3 is allocated 1 block of memory (F8). There some gaps in between the allocated memory blocks ( at F4 and F7 ). How these gaps are formed even though we are continuously allocating memory? To understand this, read our chapter on Fragmentation.
We have two types of contiguous memory allocation techniques −
- Fixed Partitioning (Static)
- Dynamic Partitioning (Variable)
Fixed Partitioning in Contiguous Memory Allocation
The fixed partitioning or static partitioning is a memory allocation technique where the main memory is divided into partitions of fixed sizes. Each partition can hold exactly one process. When a new process loaded into memory, it is allocated a partition of fixed size. If the process is smaller than the partition size, the remaining memory in the partition will be wasted. If the process is larger than the partition size, it cannot be loaded into memory.
The image below shows internal fragmentation happening in main memory during fixed partitioning −
As the image above shows, one of main drawbacks of fixed partitioning is internal fragmentation. We can see that process are not using the entire allocated memory. This will lead to a situation where even though there is enough total memory available, it may not be possible to allocate memory to a new process, because the available memory may not be contiguous.
Dynamic Partitioning in Contiguous Memory Allocation
The dynamic partitioning or variable partitioning is a memory allocation technique where the main memory is divided into partitions of varying sizes depending on the size of the processes being loaded into memory. When a new process is loaded into memory, it is allocated to the first available partition that is large enough to hold the process. If no such partition is available, the process has to wait until a partition becomes free.
The image below shows external fragmentation happening in main memory during dynamic partitioning −
The major issue with dynamic partitioning is external fragmentation. In the image above, we can see that there are some gaps in the memory after allocating and deallocating memory to various processes. This situation happens when a process is terminated from memory, and it's neighboring processes are still running.
These gaps will add up over time as more processes are loaded and unloaded from memory. In such case, you need to restart the system to make the main memory free again.
Advantages of Contiguous Memory Allocation
The contiguous memory allocation technique is preferred in some scenarios due to the following advantages −
- Simplicity − Contiguous memory allocation is simple to implement and manage. The operating system can easily keep track of the memory blocks allocated to each process.
- Fast Access − The entire process is stored in a single block of memory. No any calculation is needed to find the memory location of a process. So overall access time is faster.
- Low Overhead − Contiguous memory allocation has low overhead as there is no need for complex data structures to manage memory allocation.
Disadvantages of Contiguous Memory Allocation
Even though contiguous memory allocation is simple and fast, it comes with some drawbacks −
- Wastage of Memory − During contiguous memory allocation, there are gaps created in memory due loading and unloading of processes. This can lead to wastage of memory.
- Fragmentation − Contiguous memory allocation can lead to internal and external fragmentation. This reduce the overall efficiency of memory usage.
- Limited Flexibility − Contiguous memory allocation is not suitable for virtual memory systems and in the case where process are larger than the available memory itself.
Conclusion
Contiguous memory allocation is a simple and fast memory allocation technique used by operating systems. There are two types of contiguous memory allocation techniques: fixed partitioning and dynamic partitioning. The main drawback of contiguous memory allocation is wastage of memory due to fragmentation. However, it is still used in the case OS focuses on simplicity and speed over memory efficiency.