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:
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.
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.
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:
- Eliminate fragmentation: by moving segments around, fragmented
memory space can be combined into a single free area.
- Segmentation supports virtual memory.
- It allows dynamically growing segments.
- It facilitates shared segments.
- Dynamic linking and loading of the segments is
possible.
No comments:
Post a Comment