In a computer system, storage unit processes and resources are continuously loaded and released from memory, because of this; free memory space is broken into small pieces. This causes the creation of small non-used inefficient memory spaces, which are so small that normal processes cannot fit into that small memory block. This is causing system capacity or performance degradation. This problem is known as fragmentation. The state of fragmentation depends on the system of memory allocation. In most cases, memory space is wasted, which is known as memory fragmentation.
Reason for memory fragmentation
User processes and resources are loaded and released from the main memory; the same processes are stored in blocks of main memory. During the loading and swapping of the process, there are many spaces that are not able to load any other process due to their size. Due to the dynamic allocation nature of main memory processes, the main memory is available, but not enough to load another process in its place

Types of memory fragmentation:
There are two types of memory fragmentation

Also check: optimal page replacement algorithm
Internal Fragmentation
At the point when a process is assigned to a memory block and if that process is small than the requested memory space, it makes a vacant space in the assigned memory block. The difference between assigned and requested memory space is then called internal fragmentation. Commonly, the internal fragmentation of memory is isolated into fixed-sized blocks.

The reason for the internal fragmentation occurrence
When the memory assigned to a process is larger than the memory requested by the process. For example, if the memory space is divided into fixed-size blocks of 50 bytes. Let us consider the process in that a P1 request of only 40 bytes and a fixed-sized block of 50 bytes are assigned to the process. Now, the difference between allocated and requested memory is 10 bytes. This unutilized space is known as internal fragmentation.
Also check: classification of embedded systems
The solution to avoid internal fragmentation
Memory ought to be partitioned into variable-size blocks and assigned to the most suitable block for the memory-requested process. In basic terms, internal fragmentation can be decreased by effectively allocating the littlest partition but sufficient for the process. However, the issue will not be solved completely but it can be reduced to some extent.
External Fragmentation
Typically external fragmentation occurs in the case of dynamic or variable size segmentation. Although the total space available in memory is sufficient to execute the process; however, this memory space is not contiguous, which restricts process execution.

Reason for external fragmentation event
When the portions of memory allocated to keep any external process are not continuous and are too small. For example, if RAM has a total of 20 KB of free space but is not in a contiguous manner, or it is in a fragmented way. If a process with a size of 20 KB wants to load on RAM, it cannot load because space is not contagiously free.
Also Check: Paging in Operating System
Measures to avoid external fragmentation
The solution to external fragmentation is condensation or alteration of memory contents. In this technique, all the contents of the memory are manipulated and all the free memory is put together in a big block. To make condensation possible, the transfer must be dynamic. In addition, external fragmentation can be solved by a paging or segmentation mechanism, which will allow a process to acquire physical memory in a non-convolutional way.
The following diagram shows how fragmentation can lead to memory wastage and a compaction technique can be used to create more free memory than fragmented technology.


Compare Internal and External Fragmentation
The following are important differences between internal fission and external fission.
Internal Fragmentation | External Fragmentation | |
Memory block size | It occurs when allocated memory block are of fixed size. | It occurs when the allocated memory blocks are of different sizes. |
Occurrence | It occurs when a process requires more space or uses less space than the size of an allocated memory block. | It occurs when a process is removed from main memory. |
Process | Process of internal fragmentation occurs when paging is employed. | Process of external fragmentation occurs when segmentation is employed. |
Solution | Best fit block search is the solution for internal fragmentation. | Compaction is the solution for external fragmentation. |
Conclusion
In short, both internal and external fragmentation is a natural process that relates to either empty memory space or memory wasting. Although the problem of both cases cannot be solved completely, it can be reduced to some extent with the solutions given above.