Segmentation in Operating System
Segmentation in Operating System
By Sushant Gaurav
10 mins read
Last updated: 29 Jun 2024
2.7k views
Topics Covered
Segmentation divides processes into smaller subparts known as modules. The divided
segments need not be placed in contiguous memory. Since there is no contiguous
memory allocation, internal fragmentation does not take place. The length of the
segments of the program and memory is decided by the purpose of the segment in the
user program.
We can say that logical address space or the main memory is a collection of segments.
Types of Segmentation
Segmentation can be divided into two types:
Other memory management techniques have also an important drawback - the actual
view of physical memory is separated from the user's view of physical memory.
Segmentation helps in overcoming the problem by dividing the user's program into
segments according to the specific need.
Advantages of Segmentation in OS
No internal fragmentation is there in segmentation.
Segment Table is used to store the records of the segments. The segment table
itself consumes small memory as compared to a page table in paging.
Segmentation provides better CPU utilization as an entire module is loaded at
once.
Segmentation is near to the user's view of physical memory. Segmentation
allows users to partition the user programs into modules. These modules are
nothing but the independent codes of the current process.
The Segment size is specified by the user but in Paging, the hardware decides
the page size.
Segmentation can be used to separate the security procedures and data.
Disadvantages of Segmentation in OS
During the swapping of processes the free memory space is broken into small
pieces, which is a major problem in the segmentation technique.
Time is required to fetch instructions or segments.
The swapping of segments of unequal sizes is not easy.
There is an overhead of maintaining a segment table for each process as well.
When a process is completed, it is removed from the main memory. After the
execution of the current process, the unevenly sized segments of the process are
removed from the main memory. Since the segments are of uneven length it
creates unevenly sized holes in the main memory. These holes in the main
memory may remain unused due to their very small size.
Characteristics of Segmentation in OS
Some of the characteristics of segmentation are discussed below:
Example of Segmentation
Let's take the example of segmentation to understand how it works.
As shown in the image below, the base address of Segment-0 is 1400 and its length
is 1000, the base address of Segment-1 is 6300 and its length is 400, the base address
of Segment-2 is 4300 and its length is 400, and so on.
The pictorial representation of the above segmentation with its segment table is shown
below.
Segmentation Architecture
Segmentation architecture refers to the design and structure of a neural network model
used for image or video segmentation tasks. Image segmentation is the process of
dividing an image into multiple regions or segments, each representing a meaningful
object or part of the image. It plays a crucial role in computer vision applications such
as object recognition, scene understanding, and autonomous driving.
There are several popular segmentation architectures that have achieved significant
success in the field of computer vision. Here are a few notable ones:
Quiz Pop
Quiz Type
SCQ
100
Success Rate:35%
Problem of Fragmentation
Segmentation has one major disadvantage. During the swapping of processes,
processes are loaded and removed from the main memory. The swapping of processes
sometimes results in breaking the free memory space into small pieces according to
the segments. This breaking of free space into pieces is called External
Fragmentation which is also a major problem in the segmentation technique.
One thing to note here is that there is no internal fragmentation in the case of
Segmentation. Each process is loaded by bringing all its associated segments into the
main memory. As every segment of the process is loaded into the main memory by
creating partitions of the size of each segment. Thus, each segment can fit exactly in
the dynamically created partitions of the main memory. Thus, segmentation is free of
internal fragmentation.
The original x86 Intel model without memory protection was then renamed as real
mode. In real mode, the size of a segment can range from 1 byte to 64 KB. The newer
x86 Intel version was renamed as protected mode and it can support an address of
more than 64 KB in size.
The x86-64 architecture does not use segmentation in long mode. Instead, they handle
programs and their data by utilizing memory-paging. Paging (which divides memory
into equal-sized pages) is more efficient because it also serves as a way of memory
protection as only specified pages of a process can be accessed by the running
program.
There is also a Local Descriptor Table or LDT. Multiple LDTs can be defined inside
the GDT. The LDT is used to store the memory segments which are private to a
specific program, on the other hand, GDT contains global segments.
To reference any memory location in a segment, the processor combines the segment
address in the segment register with the offset value of the location.
So, we use segment number (found using segment register) and offset number (using
offset register) for the address translation.
Embrace the challenge of operating systems with our free Operating System course.
Enroll now and unlock the secrets to building efficient and responsive computing
environments!
Quiz Pop
Conclusion
Segmentation divides the secondary memory into uneven-sized blocks known
as segments. Segmentation divides processes into smaller sub-parts known
as modules.
Segmentation is done considering that the relative data should come in a single
segment.
Partition size depends upon the type and length of modules.
Segmentation can be divided into two types namely - Virtual Memory
Segmentation and Simple Segmentation.
Operating System maintains a segment table for each process.
Segment Table is used to store the records of the segments. The segment table
itself consumes small memory as compared to a page table in paging.
Intel-compatible x86 computers instruction set architecture introduced memory
segmentation.
A binary data structure known as Global Descriptor Table (GDT) is used
which tells the CPU about the memory segments.
GDT contains Segment Selector which is used to point or reference a segment.
Segmentation provides better CPU utilization as an entire module is loaded at
once.
Segmentation allows user to partition their programs into modules that operate
independently.
The swapping of processes results in the breaking of the free memory space
into small pieces. This breaking of free space into pieces is called External
Fragmentation.
When a process is completed, it is removed from the main memory. Since the
segment of the process is of uneven length it creates uneven-sized holes in the
main memory.
There is an overhead of maintaining a segment table for each process as well.