Fragmentation is an unwanted problem in the operating system in which the processes are loaded and unloaded from memory, and free memory space is fragmented. Processes can't be assigned to memory blocks due to their small size, and the memory blocks stay unused.
Contiguous memory allocation allocates space to processes whenever the processes enter RAM. These RAM spaces are divided either by fixed partitioning or by dynamic partitioning. As the process is loaded and unloaded from memory, these areas are fragmented into small pieces of memory that cannot be allocated to coming processes.
In this article, you will learn about fragmentation and its types.
What is Fragmentation?
There are mainly two types of fragmentation in the operating system. These are as follows:
1. Internal Fragmentation
When a process is allocated to a memory block, and if the process is smaller than the amount of memory requested, a free space is created in the given memory block. Due to this, the free space of the memory block is unused, which causes internal fragmentation.
For Example:
Assume that memory allocation in RAM is done using fixed partitioning (i.e., memory blocks of fixed sizes). 2MB, 4MB, 4MB, and 8MB are the available sizes. The Operating System uses a part of this RAM.
Let's suppose a process P1 with a size of 3MB arrives and is given a memory block of 4MB. As a result, the 1MB of free space in this block is unused and cannot be used to allocate memory to another process. It is known as internal fragmentation.
How to avoid internal fragmentation?
The problem of internal fragmentation may arise due to the fixed sizes of the memory blocks. It may be solved by assigning space to the process via dynamic partitioning. Dynamic partitioning allocates only the amount of space requested by the process. As a result, there is no internal fragmentation.
2. External Fragmentation
External fragmentation happens when a dynamic memory allocation method allocates some memory but leaves a small amount of memory unusable. The quantity of available memory is substantially reduced if there is too much external fragmentation. There is enough memory space to complete a request, but it is not contiguous. It's known as external fragmentation.
For Example:
Let's take the example of external fragmentation. In the above diagram, you can see that there is sufficient space (50 KB) to run a process (05) (need 45KB), but the memory is not contiguous. You can use compaction, paging, and segmentation to use the free space to execute a process.
How to remove external fragmentation?
There are various advantages and disadvantages of fragmentation. Some of them are as follows:
1.Advantages
There are various advantages of fragmentation. Some of them are as follows:
2. Disadvantages
There are various disadvantages of fragmentation. Some of them are as follows:
Conclusion
In short, both internal and external fragmentation are natural processes that result in either memory wasting or empty memory space. However, the problems in both cases cannot be completely overcome, although they can be reduced to some extent using the solutions provided above.
10 videos|99 docs|33 tests
|
|
Explore Courses for Computer Science Engineering (CSE) exam
|