Monday 9 November 2020

What is Segmentation in OS?

 

Segmentation:

 

A segment can be defined as a logical grouping of instructions, such as subroutine, array, or data area.  Every program (job) is a collection of these segments. Segmentation is the technique for managing these segments. For ex: consider the following fig:

Segmented address space

Fig: Segmented address space


Each segment has a name and a length. The address of the segment specifies both segment name and the offset within the segment. For ex: the length of the segment ‘Main’ is 100 KB, ‘Main’ is the name of the segment. The operating system searches the entire main memory for a free space to load a segment. This mapping is done by a segment table. The segment table is a table where each entry of the segment table has a segment ‘Base’ and a segment ‘Limit’.

 

The segment ‘Base’ contains the starting physical address where the segment resides in memory. The segment ‘Limit’ specifies the length of the segment.


Segment table

Fig: Segment table


The logical address consists of two parts: segment number(S), and an offset into that segment (D). The segment number(S) is used as an index into the segment table. For ex: consider the fig.


Segmentation example

Fig: Segmentation example


The logical address space (a job) is divided into 4 segments, numbered from 0 to 3. Each segment has an entry in the segment table. The ‘Limit’ specifies the size of the segment and the ‘Base’ specifies the starting address of the segment. For ex: segment ‘0’ is loaded in the main memory from 1500 KB to 2500 KB. So, 1500 KB is the base and 2500 - 1500= 1000 KB is the limit.

 

Advantages of Segmentation:

  1. Eliminate fragmentation:  by moving segments around, fragmented memory space can be combined into a single free area.
  2. Segmentation supports virtual memory.
  3. It allows dynamically growing segments.
  4. It facilitates shared segments.
  5. Dynamic linking and loading of the segments is possible.

No comments:

Post a Comment