Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Segmentation in OS is a memory management technique in which the process is divided into logically related partitions or segments and then allocated to the memory.
Each segment represents a different portion of a program or process, such as code, data, or stack. Memory may be used more effectively when it is segmented and organized and allocated according to the requirements of individual processes.
Each segment in segmentation is given a specific number or identity along with its size. The operating system maintains a segment table that contains the base address and length of each segment in the memory. When a program is loaded into memory, it is separated into segments, and the segment table is updated accordingly.
The segments are allocated in a non-contiguous manner in the physical memory. Unlike pages, the segments can be of variable size.
Why is Segmentation in OS required?
In paging, the process was divided into pages of equal size. In doing so, it may be possible that some part of the function or code in the process may be on one page and some on other. Consider a simple C program, where there is the main function, an add function to add two numbers, and a display function to run a loop and print the first ten natural numbers.
When the process is divided into pages, it may be possible that the add function may be divided into various pages. Also, the logic in the loop may be contained in more than one page. Because of this, the entire function will not be loaded at once. This is where segmentation comes into the picture. In segmentation, the entire process will be divided into logically related segments such that one segment will have the entire main function, the other will have the entire add function, and so on.
Segmentation gives greater control to the user.
Types of Segmentation in Operating System
There are two types of segmentation in the operating system:
1. Virtual Memory Segmentation
Virtual memory segmentation divides processes into n chunks. Not all of the segments are separated at the same time. The execution time of a program may or may not include virtual memory segmentation.
2. Simple Segmentation
Despite the fact that the segmentation is done all at once, Simple Segmentation breaks the operations into n segments. Simple segmentation occurs during the execution of a program. Because simple segmentation scatters the segments into memory (in a noncontinuous manner), one segment of the process may be located in a different location than another.
How Does Segmentation Work?
Segmentation in operating systems is a memory management technique that divides a process into segments of variable sizes, each representing a logical unit like a function or data structure. Unlike paging, segmentation doesn't require equal-sized blocks. When a process is loaded into memory, segments are allocated dynamically based on its requirements. This approach facilitates efficient memory utilization and enables sharing of memory segments among processes. Each segment is tracked in a segment table, storing its base address and length. Segmentation enhances memory access efficiency and supports multitasking environments by allowing flexible memory allocation.
What is Segment Table?
In order to know which segment is present at which address in the physical memory, every process has its segment table. The segment table is one of the most important parts of the segmentation. It helps in mapping the logical address generated by the CPU to the physical address of the memory.
Segment Number
Base
Limit
0
6000
600
1
1500
300
2
400
500
3
2837
100
The segment table consists of:
1. Segment Base- The base represents the starting address of the segment in the physical memory.
2. Segment Limit- Limit determines the size of the segment. Suppose the limit of a segment is 600 bytes, and the base address of the segment in the memory is 4000. We have assumed the memory to be byte-addressable. Therefore the last byte of the segment will be at the 4599th byte in the physical memory.
Translation of Logical address into physical address by segment table
CPU (Central Processor Unit) produces the logical address, but this is just a virtual address that is not present in our memory, so we need to translate the logical to a physical address. Translation of logical (or virtual) address into physical address is done by a unit called MMU (Memory Management Unit) which checks the range and permissions, and this process is programmed by OS.
Here is the diagram below to understand the process:
In the above diagram, The CPU produces the logical address, which then converts to a physical address using MMU (Memory Management Unit). Now this physical address can be used in memory for the assignment of processes.
Here is the diagram of the architecture of the segmentation that shows how logical address is used:
CPU produces the logical address, which has 2 parameters that are segment number, shows the specific segment, and the segment offset shows the size of that segment. Then OS searches this segment number in the segment table, and MMU does computation to check the offset, where offset should be lesser than or equal to the limit of that segment because only then that segment can be accessed. If the condition gets true, the segment can be accessed. Here the physical address will be (base + D).
For example, If we search for base 1500, which is a segment (S - 5), and D is 200. Then MMU does a computation where D should be lesser than or equal to the limit; here, D is 200, which is lesser than the limit, which is 300. So this segment can be accessed, and the physical address will be (base + D), which is 1500 + 200 = 1700. So the accessing will start from the memory index 1500 to 1700.
Characteristics of Segmentation in OS
The segmentation technique has the following characteristics:
The segmentation method employs variable-size partitioning.
Secondary memory partitions are referred to as segments in general.
The length of modules has a significant impact on partition size.
This approach divides main memory and secondary memory into divisions of varying sizes.
Segment Table consumes less space in comparison to Page table in paging.
Advantages of Segmentation in OS
There is no internal fragmentation as the segments are allocated the space as much as it requires, provided the memory is big enough to accommodate that segment. Unlike fixed partitioning, memory is not wasted in segmentation.
Memory consumed by the segment table is comparatively less than by page tables.
The user has more control means the process divides into segments logically from the point of view of the user, unlike paging.
Overhead is less in segmentation means the additional cost or resources used for segmentation are very less.
MMU (Memory Management Unit) takes care of the segment offset; it gets out of bounds or is not correct.
Crucial Data can be recovered within the segment. For example, If there are 3 functions in C++, Then segmentation will divide each function into a segment to prevent and separate the data.
Disadvantages of Segmentation in OS
It causes external fragmentation; If the total free memory is enough to be allocated by a process but can not because the process needs a contiguous memory, but only non-contiguous memory is free.
Memory management is complex compared to other techniques; There are different processes and conditions that make it more complex than other techniques like segmentation needs to take care of the division of processes logically from the point of view of the user.
Overhead is involved with maintaining a segment table for each operation; the segment table keeps track of the segments, which takes memory and time both for processing and computations.
Segments of unequal size are not suited as well for swapping; Swapping in and out can be hectic as the segments are of different or unequal sizes.
Access time to get the instruction increases due to the necessity for two memory accesses, one for the segment table and one for the main memory.
Data sharing between the processes can be difficult as the data can be divided into its own segments, so a segment can not access the data of another segment.
The time of accessing the memory can be increased as the computation is needed in the process of segmentation.
Example of Segmentation
Segmentation in OS is a memory management technique that divides a program into logical units or segments such as the main program, functions, and data structures. When a program is loaded into memory, the operating system separates it into:
Code segment (for the main program)
Function segments (individual functions)
Data segment (variables and data structures)
Each segment is assigned a unique segment number and a base address, indicating where it resides in memory.
During execution, the CPU generates logical addresses consisting of a segment number and an offset. For example, to access a variable, the system uses the data segment number along with the offset inside that segment.This technique ensures efficient memory utilization, supports variable-sized segments, and aligns memory allocation with the program’s structure optimizing overall performance in modern operating systems.
Architecture Segmentation in Operating System
In operating systems, segmentation is a memory management technique that divides a process into logical units called segments. Each segment corresponds to a specific function of a process—such as the code segment, data segment, or stack segment—making memory organization more efficient and manageable.
How Segmentation Works
The CPU generates a logical address that consists of:
A segment number
An offset within that segment
The operating system uses a segment table to map each segment number to its:
Base address in physical memory
Length of the segment
This mapping allows the system to translate logical addresses into physical addresses, enabling flexible and secure memory access.
Benefits of Segmentation in Operating Systems
Efficient memory allocation for different parts of a process
Supports dynamic memory growth in applications
Improved protection and security by assigning specific access rights to each segment
Logical separation of data, code, and stack enhances process management
Challenges in Segmentation
Despite its benefits, segmentation faces several limitations:
External fragmentation may occur, reducing memory efficiency
May require integration with paging techniques to optimize memory usage in modern operating systems
Frequently Asked Questions
What is segmentation and paging?
Segmentation is a memory management technique in which the process is divided into logically related segments and then allocated to the memory. In paging, the process is divided into equal partitions which no logical pages and these pages are allocated to the memory known as frames.
What is segmentation and fragmentation in OS?
Fragmentation is a condition where the space for the processes in memory is free, but processes can not be allocated because of contiguous or non-contiguous conflicts. Segmentation is a memory management technique that helps in reducing internal directly but is prone to external fragmentation.
Where is segmentation used in OS?
Operating systems employ segmentation as a memory management strategy to efficiently organize and allocate memory resources. The division of main memory into logical chunks, such as code, data, stack, and heap, is a prevalent practice in modern operating systems.
What is the difference between segmentation and partitioning in OS?
Segmentation divides a process into logical units (segments) based on its structure, while partitioning divides the physical memory into fixed-size blocks (partitions). Segmentation offers flexibility in memory allocation, whereas partitioning allocates memory in predefined chunks.
Conclusion
Segmentation is a non-contiguous memory management technique where the process is divided into logically related segments, and the track of these segments is kept by the segment table. The segment table consumes comparatively less memory than the page table. Segmentation also helps in reducing internal fragmentation, and it is also prone to external fragmentation.
In this article, we discussed what is segmentation, the types of segmentation, why segmentation is required in OS (Operating System), segment table, Translation of Logical address into a physical address by segment table, and the characteristics, advantages, and disadvantages of Segmentation.