Non-Contiguous Memory Allocation in Operating System
Memory allocation is the process of giving programmes on computers space to run. Memory consists of a substantial number of bytes. The two fundamental types of memory allocation are contiguous and non-contiguous. Depending on its needs, an operating system's non-contiguous memory allocation allows a process to get several memory blocks in different locations throughout memory. The methods used to make a process's physical address space non-contiguous are paging and segmentation. Non-contiguous memory allocation divides the process into blocks (or pages or segments), which are subsequently allotted to different memory locations in accordance with the quantity of free memory.
Memory management is the capacity of an operating system to manage primary memory and swap between main memory and the disc while processes are active.
Regardless of whether a process is using a particular memory location or not, memory management keeps track of every single memory location. It decides how much RAM each process needs to have. It determines when and to which processes memory will be allocated. It monitors when memory is released or unallocated and modifies the state as necessary.
Memory allocation is the method by which the operating system allots portions of memory to a system, which are then used to hold variables, classes, and instances of structures.
We'll go into great detail on non-contiguous memory allocation in this article.
Non-Contiguous Memory Allocation: What Is It?
Depending on its needs, it enables a process to acquire several memory blocks in different parts of memory. Non-contiguous memory allocation also reduces memory waste caused by internal and external fragmentation because it utilises the memory gaps left by internal and external fragmentation.
The two methods for preventing a process's physical address space from being contiguous are paging and segmentation. Non-contiguous memory allocation separates the operation into blocks (pages or segments), which are then assigned to various memory locations according to the amount of available memory.
Although non-contiguous memory allocation can save wasted memory, it also adds to the costs associated with address translation. The memory execution is delayed because address translation takes time when the process pieces are stored in different places in memory.
In this sort of memory allocation, a process may obtain a number of memory blocks at various locations throughout the memory as necessary. Contrary to contiguous memory allocation, where all the free space is allocated in one spot, the available free space is divided throughout.
Non-contiguous memory allocation proceeds more slowly than contiguous memory allocation. Segmentation and paging are included. This allocation doesn't result in any memory loss. The subsequent procedures might be set up anywhere.
As an illustration, contiguous memory blocks in the RAM will be assigned to a process with three segments, let's say P1, P2, and P3, as follows: block 1 (-> P1), block 3 (-> P2), and block 5 (-> P3).
Operating systems employ paging as a storage technique to restore processes from secondary storage into the main memory as pages. The main concept behind paging is to isolate each procedure into its own page. The primary memory will also be split up into frames.
One page of the method should be saved in one of the memory frames. The pages can be positioned anywhere in the memory, but the objective is always to discover contiguous frames or gaps.
Process pages are kept in secondary storage unless they are required to be brought into the main memory.
According to the operating system, frame sizes change. The size of each frame must be uniform. The page size must match the frame size since the frames in Paging are mapped to the pages.
Creating the page table as a collection of registers is one of the simplest methods for paging. The page table is kept in the main memory because register capacity is constrained while page table size is typically large.
Since each free frame will be assigned to a process that needs it, this strategy avoids external fragmentation. But internal fragmentation still exists.
A data structure called the frame table keeps track of details like which frames are assigned or available, among other things. This table's entries each correspond to a single physical page frame.
The operating system, like it does for the instruction counter and register contents, keeps a copy of the page table for each process. Additionally, when the operating system manually maps a logical address to a physical address, this copy is used to convert the addresses from logical to physical.
When a process has to be allocated to the CPU, the CPU dispatcher uses this copy to specify the hardware page table.
Operating systems employ segmentation, a memory management technique, to divide memory into chunks of variable sizes. The term "segment" refers to each component, while "process" can be given to each segment.
Information about each segment is kept in a table called the segment table. The segment table is contained in one (or more) segments.
Two pieces of information about the segment are the focus of the segment table:
What makes segmentation necessary?
Up until this point, our main memory management strategy has been paging. The operating system and paging are more intimately related than the user. Even though a process may have specific connected chunks of functions that must be loaded on the same page, it divides all processes into pages.
The operating system doesn't care what the user thinks of the process. The same function might be divided up into several pages that are loaded into memory one at a time or not. As a result, the system's performance declines.
It is advisable to segment the process by breaking it up into segments. Similar types of functions are present in each segment. For instance, the library functions are in the other segment and the main function is in the first.
Below is a segmentation example with five segments labelled 0 through 4. These parts will be kept in physical memory, as shown. Each segment has a unique entry in the segment table, which includes the segment's length and start entry address in physical memory (also known as the base) (denoted as limit).
Segment 2 is 400 bytes long and begins at point 4300. In this case, a reference to byte 53 of segment 2 is therefore mapped to location 4300 (4300+53=4353). A reference to segment 3, byte 85, is represented by the equation 3200(the base of segment 3)+852=4052.
A reference to byte 1222 of segment 0 would set off an OS trap because this segment is 1000 bytes long.
Segmentation with paging
Pure segmentation is not frequently used, and few operating systems support it. The advantages of both procedures can be enhanced by combining segmentation and paging, though.
In Segmented Paging, the main memory is partitioned into segments of varying sizes, which are then further subdivided into fixed-size pages.
It points us in the direction of the appropriate segment number.
Pages: It points us to the particular page within the section.
Page Offset: This number is used to move the page up or down within the frame.
Each Page table in the section contains a variety of information about each page. The Section Table contains details for each segment. Each segment table entry links to a page table item, and each page table entry is mapped to one of the pages included within a segment.
Non-Contiguous Memory Allocation advantages and disadvantages
The allocation of non-contiguous memory has a number of benefits and drawbacks. The following are a few benefits and drawbacks:
The drawback of this memory allocation is that access is sluggish due to the need to traverse and use pointers to go to other nodes.
Most Commonly Asked Questions
1. What is memory allocation that is not contiguous?
Non-contiguous memory allocation divides the process into blocks (or pages or segments), which are subsequently allotted to different memory locations in accordance with the quantity of free memory.
2. Is contiguous or non-contiguous segmentation?
Segmentation is an OS mechanism for allocating non-contiguous memory. Instead of dividing the process into fixed-size pages, segmentation divides it into modules.
3. What is the allocation of contiguous memory?
When a user process requests memory, one of the parts of the contiguous memory block is given to that process in accordance with its requirements under the contiguous memory allocation technique of memory management.
The non-contiguous memory allocation in an OS was covered in this article. In this sort of memory allocation, a process may obtain a number of memory blocks at various locations throughout the memory as necessary. Contrary to contiguous memory allocation, where all the free space is allocated in one spot, the available free space is distributed throughout.