What is Segmentation?

Computer ArchitectureComputer ScienceNetwork

Segmentation is another approach of allocating memory that can be used rather than or in conjunction with paging. In its purest form, a program is broken into multiple segments, each of which is a self-contained unit, including a subroutine or data structure.

Unlike pages, segments can vary in size. This requires the MMU to manage segmented memory somewhat differently than it would manage paged memory. A segmented MMU contains a segment table to maintain track of the segments resident in memory.

A segment can create at one of many addresses and can be of any size, each segment table entry should contain the start address and segment size. Some system allows a segment to start at any address, while other limits the start address. One such limit is found in the Intel X86 architecture, which requires a segment to start at an address that has 6000 as its four low-order bits.

A system with this limitation would not need to store these four bits in its segment table, since their value is implicit. As shown in the figure, it shows a simplified address translation scheme for segmented memory.

The offset is compared to the segment size. If the offset is higher than or the same as the segment size, signifying that the location is not a part of the segment, an error is created. If the offset has a true value, it is inserted to the beginning of the segment address to create the correct physical memory addresses. As with paging, a segmented MMU can also have a TLB to speed up the generation of segment start addresses and sizes.

In paging, the page number is sent to the page table (and TLB) to produce a frame number. This value is concatenated with the offset to produce the physical address. In segmentation, the start address generated by the segment table or TLB is added to the offset, a process much more time-consuming than concatenation.

Because segments can have different sizes, this method has both advantages and disadvantages as compared to paging. Consider the paging example for the relatively simple CPU.

In the paged memory execution, each page is of size 4K. A program of size 4K + 1 would need the MMU to allocate two pages of memory, even though the second page would use only one of its 4K locations. This is referred to as internal fragmentation. If segmentation is used, a segment of exactly size 4K + 1 can be allocated, thus avoiding this problem.

Segmentation has a problem known as external fragmentation. There are three segments resident in memory and 8K of free space. The free is subdivided such that no segment higher than 3K can be loaded into memory without changing or deleting one of the currently loaded segments. It introduces overhead by moving data back to the swap disk or relocating it in memory, either of which reduces system performance.

Updated on 27-Jul-2021 08:52:02