Intermediate Topic 28 of 51 Operating Systems
Segmentation
Dividing memory into logical variable-size units.
How it works
Segmentation divides a program's address space into logical segments such as code, data, stack and heap, each with its own base and limit. An address is a pair of segment number and offset, and hardware checks the offset against the limit and the permissions. Segments can differ in size, matching the programmer's view, and can be shared or protected independently.
Step-by-step walkthrough
- Memory is split into logical segments by purpose.
- An address is a segment number plus an offset.
- The segment table gives a base and a limit.
- An offset beyond the limit raises a fault, giving protection.
- Segments vary in size, so external fragmentation can occur.
Where it is used
Early systems and Intel x86 real and protected mode used segmentation; modern operating systems use mostly flat memory with paging, keeping segments for thread-local storage and privilege checks. It also appears conceptually in executable file layouts.
Common pitfall
Variable-size segments cause external fragmentation and need compaction. Allocating contiguous memory for a segment can fail even with enough total free memory. Segmentation faults today usually mean invalid memory access caused by null pointers or buffer overruns, not literal segments. Combine with paging, as in segmented paging, to get the benefits of both.
Where it fits in the course
Segmentation is topic 28 of 51 in Operating Systems, rated Intermediate. It follows Paging. The next topic is Virtual Memory.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Operating Systems quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Operating Systems quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Segmentation?
Where do people use Segmentation?
What is the most common mistake with Segmentation?
What should I learn before this topic?
How can I practice it?
Is Segmentation hard to learn?
How long does it take to learn Segmentation?
Which topics are related to Segmentation?
What should I study after Segmentation?
Related topics
- Paging (Operating Systems)
- Virtual Memory (Operating Systems)
- Memory Management (Operating Systems)
- Page Faults (Operating Systems)
- Image Segmentation (Graphics, Vision & Media)