What is segmentation in the operating system with examples?

Hello Friends, In this blog post(What is segmentation in the operating system with examples), 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.

Inside this blog post(What is segmentation in the operating system with examples), we will explore What is segmentation in the operating system with examples? What are paging and segmentation? Why do we need segmentation in the operating system?

In segmentation, Segments are formed at program translation time by grouping logically related items. For example, a typical process may have separate code, data, and stack segments|What is segmentation in the operating system with examples|

Data or code shared with other processes may be placed in their dedicated segments in segmentation. Being a result of a logical division, individual segments generally have different sizes|What is segmentation in the operating system with examples|

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-defined 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 in the segment table.

segmentation-harware
Fig 1 Segmentation Hardware

The offset d of the 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.

Fig 2 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 essentially, pages are fixed size and segments are not in segmentation.

Quick Revision:

What is segmentation in the operating system?

Segmentation is a memory management technique where we divide the memory into variable-size memory blocks and then we can assign the processes to these variable-size blocks.

The details about each segment are stored in a table that is known as a segment table.

What are paging and segmentation?

Both are considered memory management techniques, in paging, the memory is presented to the CPU, while segmentation is a virtual memory technique where variable-size memory blocks are created and they are also known as segments.

Why do we need segmentation in the operating system?

It is used to achieve better efficiency in memory. variable size non-contiguous blocks are created and small chunks of the process are assigned to these memory blocks.

Though there is a chance of external fragmentation where the process becomes out of the system as it does not find any suitable memory block to fulfill the request|What is segmentation in the operating system with examples|

You can also go through a few more amazing blog links below related to segmentation and operating systems:

Segmentation In OS In Hindi…
Fragmentation In Hindi…
Paging vs Segmentation In Hindi…
What is segmentation in the operating system with examples…
Fragmentation & Its types in the operating system…
Similarities And Differences between Paging and 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 What is segmentation in the operating system with examples.

Please feel free to give your important feedback in the comment section below|What is segmentation in the operating system with examples|

Have a great time! Sayonara!

Anurag

I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.