The Wayback Machine - https://web.archive.org/web/20240713061011/https://www.geeksforgeeks.org/non-contiguous-allocation-in-operating-system/
Open In App

Non-Contiguous Allocation in Operating System

Last Updated : 19 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Non-contiguous allocation, also known as dynamic or linked allocation, is a memory allocation technique used in operating systems to allocate memory to processes that do not require a contiguous block of memory. In this technique, each process is allocated a series of non-contiguous blocks of memory that can be located anywhere in the physical memory.

Non-contiguous allocation involves the use of pointers to link the non-contiguous memory blocks allocated to a process. These pointers are used by the operating system to keep track of the memory blocks allocated to the process and to locate them during the execution of the process.

Fundamental approaches :

There are two fundamental approaches to implementing noncontiguous memory allocation:

• Paging

• Segmentation

In paging, each process consists of fixed-size components called pages. The size of a page is defined by the hardware of a computer, and demarcation of pages is implicit in it. The memory can accommodate an integral number of pages. It is partitioned into memory areas that have the same size as a page, and each of these memory areas is considered separately for allocation to a page. This way, any free memory area is exactly the same size as a page, so external fragmentation does not arise in the system. Internal fragmentation can arise because the last page of a process is allocated a page-size memory area even if it is smaller than a page in size.

In segmentation, a programmer identifies components called segments in a process. A segment is a logical entity in a program, e.g., a set of functions, data structures, or objects. Segmentation facilitates sharing of code, data, and program modules processes. However, segments have different sizes, so the kernel has to use memory reuse techniques such as first-fit or best-fit allocation. Consequently, external fragmentation can arise.

There are several advantages to non-contiguous allocation. 

First, it reduces internal fragmentation since memory blocks can be allocated as needed, regardless of their physical location. Second, it allows processes to be allocated memory in a more flexible and efficient manner since the operating system can allocate memory to a process wherever free memory is available.

However, non-contiguous allocation also has some disadvantages.

 It can lead to external fragmentation, where the available memory is broken into small, non-contiguous blocks, making it difficult to allocate large blocks of memory to a process. Additionally, the use of pointers to link memory blocks can introduce additional overhead, leading to slower memory allocation and deallocation times.

In summary, non-contiguous allocation is a useful memory allocation technique in situations where processes do not require a contiguous block of memory. It is commonly used in operating systems, such as Unix and Linux, where processes often require variable amounts of memory that are not contiguous.

Some reference books on operating system concepts that cover non-contiguous allocation include:

  1. “Operating System Concepts” by Abraham Silberschatz, Peter Baer Galvin, and Greg Gagne.
  2. “Modern Operating Systems” by Andrew S. Tanenbaum.
  3. “Operating Systems: Three Easy Pieces” by Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau.
  4. These books provide detailed coverage of operating system concepts, including memory management and allocation techniques.

Prerequisite – Variable Partitioning, Fixed Partitioning 
Paging and Segmentation are the two ways that allow a process’s physical address space to be non-contiguous. It has the advantage of reducing memory wastage but it increases the overheads due to address translation. It slows the execution of the memory because time is consumed in address translation. 

In non-contiguous allocation, the Operating system needs to maintain the table which is called the Page Table for each process which contains the base address of each block that is acquired by the process in memory space. In non-contiguous memory allocation, different parts of a process are allocated to different places in Main Memory. Spanning is allowed which is not possible in other techniques like Dynamic or Static Contiguous memory allocation. That’s why paging is needed to ensure effective memory allocation. Paging is done to remove External Fragmentation. 

There are five types of Non-Contiguous Allocation of Memory in the Operating System:

  1. Paging
  2. Multilevel Paging
  3. Inverted Paging
  4. Segmentation
  5. Segmented Paging

Working: 
Here a process can be spanned across different spaces in the main memory in a non-consecutive manner. Suppose process P of size 4KB. Consider main memory has two empty slots each of size 2KB. Hence total free space is, 2*2= 4 KB. In contiguous memory allocation, process P cannot be accommodated as spanning is not allowed. 

In contiguous allocation, space in memory should be allocated to the whole process. If not, then that space remains unallocated. But in Non-Contiguous allocation, the process can be divided into different parts and hence filling the space in the main memory. In this example, process P can be divided into two parts of equal size – 2KB. Hence one part of process P can be allocated to the first 2KB space of main memory and the other part of the process can be allocated to the second 2KB space of main memory. The below diagram will explain in a better way: 

 

But, in what manner we divide a process to allocate them into main memory is very important to understand. The process is divided after analysing the number of empty spaces and their size in the main memory. Then only we do divide our process. It is a very time-consuming process. Their number as well as their sizes changing every time due to execution of already present processes in main memory. 

In order to avoid this time-consuming process, we divide our process in secondary memory in advance before reaching the main memory for its execution. Every process is divided into various parts of equal size called Pages. We also divide our main memory into different parts of equal size called Frames. It is important to understand that: 

 

Size of page in process 
= Size of frame in memory



Although their numbers can be different. Below diagram will make you understand it in a better way: consider empty main memory having a size of each frame is 2 KB, and two processes P1 and P2 are 2 KB each. 

 

Resolvent main memory, 

 

Concluding, we can say that Paging allows the memory address space of a process to be non-contiguous. Paging is more flexible as only pages of a process are moved. It allows more processes to reside in main memory than Contiguous memory allocation.
 


Previous Article
Next Article

Similar Reads

Difference between Static Allocation and Heap Allocation
Static Allocation v/s Heap Allocation Static Allocation: Static allocation is an allocation procedure that is used for the allocation of all the data objects at compile time. In this type of allocation, allocation of data objects is done at compile time only. As in static allocation, the compiler decides the extent of storage which cannot be change
3 min read
Buddy Memory Allocation Program | Set 1 (Allocation)
Prerequisite - Buddy System Question: Write a program to implement the buddy system of memory allocation in Operating Systems.Explanation - The buddy system is implemented as follows- A list of free nodes, of all the different possible powers of 2, is maintained at all times (So if total memory size is 1 MB, we'd have 20 free lists to track-one for
13 min read
Difference between Static allocation and Stack allocation
Static Allocation: Static allocation is a procedure which is used for allocation of all the data objects at compile time. Static allocation is possible only when the compiler knows the size of data object at compile time. In this type of allocation, formation of data objects is not possible under any circumstances at run time. In static allocation,
2 min read
Allocation of frames in Operating System
An important aspect of operating systems, virtual memory is implemented using demand paging. Demand paging necessitates the development of a page-replacement algorithm and a frame allocation algorithm. Frame allocation algorithms are used if you have multiple processes; it helps decide how many frames to allocate to each process. There are various
3 min read
Best-Fit Allocation in Operating System
INTRODUCTION: Best-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In Best-Fit, the operating system searches through the list of free blocks of memory to find the block that is closest in size to the memory request from the process. Once a suitable block is found, the operating system spli
4 min read
Resource Allocation Graph (RAG) in Operating System
As Banker's algorithm using some kind of table like allocation, request, available all that thing to understand what is the state of the system. Similarly, if you want to understand the state of the system instead of using those table, actually tables are very easy to represent and understand it, but then still you could even represent the same inf
5 min read
Difference between Contiguous and Noncontiguous Memory Allocation
1. Contiguous Memory Allocation : Contiguous memory allocation is basically a method in which a single contiguous section/part of memory is allocated to a process or file needing it. Because of this all the available memory space resides at the same place together, which means that the freely/unused available memory partitions are not distributed i
2 min read
First-Fit Allocation in Operating Systems
INTRODUCTION: First-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In First-Fit, the operating system searches through the list of free blocks of memory, starting from the beginning of the list, until it finds a block that is large enough to accommodate the memory request from the process.
3 min read
Worst-Fit Allocation in Operating Systems
For both fixed and dynamic memory allocation schemes, the operating system must keep a list of each memory location noting which are free and which are busy. Then as new jobs come into the system, the free partitions must be allocated. These partitions may be allocated in 4 ways: 1. First-Fit Memory Allocation 2. Best-Fit Memory Allocation 3. Worst
2 min read
Buddy System - Memory Allocation Technique
Static partition techniques are limited by having a fixed number of active processes, and space use may not be optimal. The buddy system is a memory allocation and management technique that uses power-of-two increments. Assume the memory size is 2U and a size of S is required. In this article, we are going to discuss the Buddy System in detail alon
8 min read
Article Tags :