segmentation-feature

What is segmentation in the operating system?

Hello Friends, In this blog post, I am going to discuss the segmentation process. Segmentation is a memory management scheme that divides the address space of a single process into blocks that may be placed into noncontiguous areas of memory to reduce the average size of a request.

In segmentation, Segments are formed at program translation time by grouping together logically related items. For example, a typical process may have separate code, data, and stack segments.

Data or code shared with other processes may be placed in their own dedicated segments in segmentation. Being a result of a logical division, individual segments generally have different sizes.

Although different segments may be placed in separate, noncontiguous areas of physical memory, items belonging to a single segment must be placed in contiguous areas of physical memory. Thus, segmentation possesses some properties of both contiguous and noncontiguous schemes for memory management.

A logical address space is a collection of segments. Each segment has a name and a length. The addresses specify both the segment name and the offset within the segment. The user, therefore, specifies each address by two quantities – a segment name and an offset.

For simplicity of implementation, segments are numbered and are referred to by a segment number, rather than by a segment name. Thus a logical address consists of two tuples.

<segment number, offset>

Since physical memory in segmented systems generally retains its linear array organization, some address translation mechanism is needed to convert a two-dimensional virtual segment address into its unidimensional physical equivalent.

Thus, we must define an implementation to map two-dimensional user define addresses into one-dimensional physical addresses. This mapping is affected by a segment table.

Each entry of the segment table has a segment base and segment limit. The segment base contains the starting physical address where the segment resides in memory whereas the segment limit specifies the length of the segment.

Fig 1 shows the use of a segment table. A logical address consists of two parts – a segment number, s, and an offset into that segment, d. The segment number is used as an index into the segment table.

segmentation-harware
Fig 1 Segmentation Hardware

The offset d of logical address must be between 0 and the segment limit. if it is not, we trap the operating system that is a logical addressing attempt beyond the end of the segment.

If this offset is legal, it is added to the segment base to produce the address in the physical memory of the desired byte.

Fig2 shows the situation with five segments numbered from 0 through 4. The segment table has a separate entry for each segment giving the beginning address of the segment in physical memory(or base) and the length of that segment(or limit).

segment-example
Fig 2 Segmentation Example

Segment 2 is 4 bytes long and begins at location 4300. Thus a reference to byte 53 of segment 2 is mapped onto location 7300+53=4353. A reference to byte 1222 of segment 0 will result in a trap to the operating system because this segment is only 1000 bytes long.

The implementation of paging differs from paging in an essential way, pages are fixed size and segments are not in segmentation.

In the case of any queries, you can write to us at a5theorys@gmail.com we will get back to you ASAP.

Hope! you would have enjoyed this post about Segmentation along with its hardware and example.

Please feel free to give your important feedbacks in the comment section below.

Have a great time! Sayonara!