In an operating system, segmentation is a way to manage memory by dividing it into parts called segments that can be given to different processes. These segments can be different sizes and don't have to be stored next to each other. Segmentation was created after a method called paging, which breaks up a process into multiple pages to load into memory. Instead, segmentation keeps related parts of a process together in one segment.
A segment table keeps track of all the details about the segments and processes. When the CPU needs to use a segment, it uses the segment table to find the correct address. This table has two important pieces of information: the base and the limit. The base is the starting address of a segment, and the limit is the length of the segment. Segmentation can be done in two ways: virtual segmentation and simple segmentation, based on how the processes are divided and stored in memory.
What is a Segment Descriptor?
In the Protected mode of x86, the Memory Management Unit (MMU) uses the segment selector to access a descriptor, segment descriptors are a part of the segmentation unit, which provides the processor with the data it needs to translate a logical address into a linear address.
A segment descriptor is a special structure that describes the segment. Exactly one segment descriptor must be defined for each segment of the memory. Descriptors are eight types of quantities that contain attributes about a given region of linear address space. These attributes include the 32-bit base linear address of the segment, the 20-bit length, and granularity of the segment, the protection level, read, write, or execute privileges, the default size of the operands (16-bit or 32-bit), and the type of segment.

General Format of Descriptor
- Segment Base Address: It contains the 32-bit base address for a segment. Thus define the location of the segment within the 4 gigabyte ((232 -1)-bit ) linear address space.
- Segment Limit: It defines the size of the segment. The x86 concatenates the two fragments of the limit field to form a 20-bit value. The x86 interprets this 20-bit value in two ways, depending on the setting of the granularity bit(G).
- Granularity Bit: It specifies the unit with which the limit field is interpreted. If the G bit is 0, the limit is interpreted in a unit of one byte, else limit is interpreted in a unit of 4 Kb.
- O(Reserved by Intel): This neither can be defined nor can be used by the user. This bit must be zero for compatibility with future processors.
- U/AVL (User Bit): This bit is completely undefined, and x86 ignores it. This is an available field/bit for the user or operating system.
- P (Present Bit): The present P bit is 1 if the segment is loaded in the physical memory, if P = 0 then any attempt to access this segment causes a not-present exception.
- DPL (Descriptor Privilege Level): It is a 2-bit field the level of privilege associated with the memory space that the descriptor defines – DPL0 is the most privileged whereas DPL3 is the least privileged.
- S (System Bit): The segment S bit in the segment descriptor determines if a given segment is a system segment or a code or a data segment. If the S bit is 1 then the segment is either a code or data segment, if it is 0 then the segment is a system segment.
- Type: The specifies the specific descriptor among various kinds of descriptors.Â
- A (Accessed Bit): The x86 automatically sets this bit when a selector for the descriptor is loaded into a segment register. This means that x86 sets accessed bit whenever a memory reference is made by accessing the segment.
Conclusion
Segmentation is a technique used to break processes into smaller parts called segments, where related data is grouped together into a single segment to load into memory. The size of these segments depends on the length and type of the processes. Segment tables are used to keep track of the segments and their tasks. The CPU uses the segment descriptor and the global descriptor table to get information about the segment type and its memory. This process helps make the best use of the CPU because similar data is loaded together in one segment.