What is Segmentation?
Segmentation is another memory management technique that gives the user's view of a process. The user's view is mapped into the Physical Memory.
In Segmentation, a process is divided into multiple segments. The size of each segment is not necessarily the same which is different from paging. In Paging, a process was divided into equal partitions called pages. The module contained in a segment decides the size of the segment.
Why Segmentation is needed?
We used Paging as one of the memory management techniques. In Paging, the process was divided into equal-sized pages irrespective of the fact that what is inside the pages. It also divides some relative parts of a process into different pages which should be loaded on the same page. It decreases the efficiency of the system and doesn't give the user's view of a process.
In Segmentation, similar modules are loaded in the same segments. It gives the user's view of a process and also increases the efficiency of the system as compared to Paging.
Types of Segmentation
There are two types of Segmentation. These are:
- Simple Segmentation - In Simple Segmentation, each process is divided into multiple segments and all of them are loaded into the memory at run time. They can be at non-contagious locations.
- Virtual Memory Segmentation - In Virtual Memory Segmentation, each process is divided into multiple segments and all of them do not reside at one point at a time.
Segment Table
- Segment Table stores the information about all the segments of a process.
- It helps in the mapping of the two-dimensional logical addresses to the physical addresses.
- It is stored in the main memory.
- There are two entries in the Segment Table.
- Base Address - It is the starting physical address of the particular segment inside the main memory.
- Limit - It denotes the size of a particular segment.
Translation of Logical Address into Physical Address
The CPU generates the logical address which consists of two parts:
- Segment Number(s) - It is the number of bits required to represent a Segment. It is used as an index in the Segment Table.
- Segment Offset(d) - It is the number of bits required to represent the size of a Segment.
Segment Number from the Segment Table gives the base address of a Segment in the main memory and Segment Offset gives the size of that Segment. These two together give the Physical Address of a Segment in the memory. If Offset(d)<Limit then the segment is fetched from the memory else there is an error.
.png)
Advantages of Segmentation
- There is no Internal Fragmentation.
- It gives the user's view of a process.
- It helps in dividing a program into similar modules which are called segments.
- Segment Table consumes less space than Page Table.
Disadvantages of Segmentation
- When Process is removed from the memory, it breaks memory into small pieces which leads to External Fragmentation.