Segmentation in Operating System (OS)
Segmentation in Operating System
- Segmentation is more like, user’s end of memory management scheme.
- Just like paging, it divides or segments the memory. But, while paging divides memory into fixed size, segmentation divides the memory in variable segments, which are then loaded into logical memory space. There are following types of segmentation –
- Virtual Memory Segmentation – Each processes is segmented into n divisions, however, they are not segmented all at once.
- Simple Segmentation – Each processes is segmented into n divisions, they are all together segmented at once exactly at runtime. While, they may be scattered in the memory i.e. can be non contiguous.
How Segmentation works?
Just like page table or TLB, for segmentation all the information necessary is stored into the segment table. The relationship between the logical and physical address is a bit more complex here.
The unit involved here are –
- Segment table
- Base Address
- Segment Number (s)
- Segment Offset (d)
The correlation and mapping for the logical address which is 2 dimensional address and the physical address is done with the help of segment table.
The starting address of the memory where the data is stored in its logical format in the system.
Say Base address is 8000, then the data will be available in addresses from 8000 onwards.
Since the size of each segment is different, thus each segment has its own limit defined and it tells the system about the size or length of any particular segment.
Further for mapping to physical form for the CPU the following are required –
- Segment Number (s) – It is basically the total number of bits that are required to store any particular address of the segment in consideration
- Segment Offset (d) – Number of bits required for the size of the segment.
The process can be easily visualised from the image below-
Contrast with Paging
- Page size is fixed
- Can lead to internal fragmentation
- Size is decided by the Hardware
- Address mapping is simple and page table is sufficient
- Segment size is variable
- Can lead to external fragmentation
- Size is decided by the user
- Address mapping is complex even with the help of segment table, segment number and offset.
- Memory Management Introduction
- Partition Allocation Method
- Buddy- System Allocator
- Types of Paging
- Mapping Virtual address to Physical Address.
- Virtual Memory
- Demand Paging
- Implementation of Demand paging and page fault
- Page Replacement Algorithms
- Belady’s Anomaly
- Static vs Dynamic Loading
- Static vs Dynamic Linking
- Translational Look Aside Buffer
- Process Address Space
- Difference between Segmentation and Paging