In the case of non-contiguous memory allocation, the processes would acquire the overall space in the memory. They are not present in a single place but at different locations as per the process requirement. This particular technique reduces overall memory wastage, which leads to external or internal fragmentation.
In this article, we will look more into the Non-Contiguous Memory Allocation in Operating Systems according to the GATE Syllabus for (Computer Science Engineering) CSE. We will read ahead to find out more about it.
Table of Contents
- What is Non-Contiguous Memory Allocation in an Operating System?
- Pros of Non-Contiguous Memory Allocation
- Cons of Non-Contiguous Memory Allocation
What is Non-Contiguous Memory Allocation in an Operating System?
Segmentation and paging are the two ways that allow the physical address space of a process to be non-contiguous. They have the advantage of reducing wastage of memory, but they increase the overheads because of address translation. They slow the memory execution because of the time consumption in address translation.
In the case of non-contiguous allocation, the OS needs to maintain the table that is known as the Page Table for every process that consists of the base address of each of the blocks acquired by the processes in memory space. In this type of memory allocation, all the different parts of a given process get allocated to different places in the main memory.
One thing to note is that spamming is allowed, which isn’t readily allowed in Static or Dynamic Contiguous memory allocation. This is the reason why paging is required so as to ensure effective allocation of memory. It is primarily done to remove any sort of external fragmentation.
Working
A process can be spammed, in this case, across different main memory spaces in a very non-consecutive fashion. Suppose the process P is of size 4 KB. Now, let us consider that the main memory consists of two empty slots, and each of them has a size of 2 KB. Thus, the total free space would be 2*2= 4 KB. In the case of contiguous memory allocation, the process P cannot be accommodated since spanning is not allowed.
In the case of contiguous allocation, the memory space must be allocated to the entire process. If not, then the space would remain unallocated. But in the case of non-contiguous memory allocation, the process can be divided into various parts, hence filling the space present in the main memory. For instance, in this example, the process P can be further divided into two parts that have an equal size of 2 KB. Thus, one part of process P could be first allocated to the 2 KB space of the main memory, while the other part of this process can be allocated to the second 2 KB space of the main memory. The diagram given below will explain this in a better way:
But how we divide a process for allocating it into the main memory is very crucial to understand. The process is divided after we analyse the total number of empty spaces along with their sizes in the main memory. Only then do we divide the given process. This process is very time-consuming. Their overall numbers, as well as sizes, change every single time due to the execution of the processes present already in the main memory.
To avoid such a time-consuming process, one can divide the process present in the secondary memory in advance before reaching for execution in the main memory. All the processes get divided into several parts of equal sizes, and they are known as pages.
Plus, we can also divide the main memory into several parts with equal sizes, known as frames. Now, it is very crucial to understand that:
The size of the page in the process = The size of the frame in the memory
But, their actual numbers can be different.
Consider an empty main memory with each frame of 2 KB, along with two processes, P1 and P2, that are 2 KB each. The diagram given below will help you understand this in a better way:
Resolvent main memory:
Thus, we can conclude that the process of paging allows the memory address space of the given process to be non-contiguous. Thus, paging is comparatively flexible since only pages in a process are moved. It allows the residing of more processes in the main memory than in the contiguous allocation.
Pros of Non-Contiguous Memory Allocation
The primary advantage of this type of memory allocation is that it won’t suffer from external fragmentation. For example, the 5 KB data that we wanted to insert in the above-mentioned picture can be inserted since 5 KB can be further broken into pieces (the 4 KB one in the first part and the remaining 1 KB one in the second part).
Cons of Non-Contiguous Memory Allocation
The primary disadvantage of this type of memory allocation is that the access is very slow. Since we have to access all the other nodes using pointers, we have to traverse them one by one.
Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Syllabus, GATE Previous Year Question Paper, and more.
Also Explore,
- Batch Operating System
- Binary Semaphores in Operating System
- Contiguous Memory Allocation in Operating System
- Counting Semaphores in Operating System
- Deadlock Detection and Recovery in Operating System
- Deadlock Prevention in Operating System
- Distributed Operating System
- Dynamic Partitioning in Operating System
- Fixed Partitioning in Operating System
- Functions of Operating System
- Methods for Handling Deadlock in Operating System
- Multiprocessing Operating System
- Multiprogramming Operating System
- Multitasking Operating System
- Network Operating System
- Operating System Services
- Paging in OS
- Process in Operating System
- Process Scheduler in Operating System
- Process Scheduling in Operating System
- Process State in Operating System
- Real-Time Operating System
- Resource Allocation Graph in Operating System
- Semaphores in Operating System
- Time-Sharing Operating System
- Types of Operating System