Q5Operating System
Question
Explain the concept of Segmentation with its advantages and disadvantages.
Answer
Segmentation is a memory management scheme where a program is divided into variable-sized logical segments, each with its own base and limit in physical memory.
In segmentation, the logical address space is divided into variable-size segments (code, data, stack, heap, etc.). A logical address is a pair (segment-number, offset). The segment table contains the base address and limit (size) for each segment. The CPU translates a logical address by looking up the segment table: physical address = base[segment-number] + offset (if offset < limit).
- Supports the user's logical view of memory (code, data, stack are naturally separate segments).
- Facilitates sharing of code segments (e.g., shared library segments can be mapped into multiple processes).
- Provides protection at the segment level (e.g., code segment can be marked read-only).
- Segments can grow or shrink independently (e.g., stack or heap).
- No internal fragmentation — segments are exactly as large as needed.
- External Fragmentation: Variable-size segments leave holes in physical memory over time.
- Compaction required to eliminate fragmentation — expensive.
- Segment table overhead: Each process needs a full segment table in memory.
- More complex memory management than paging.
Modern systems often combine segmentation with paging (segmented paging or paged segmentation) to get benefits of both. Intel x86 architecture uses a segmentation model (though most modern OS like Linux use a flat segmentation model effectively bypassing it).