A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Segmentation

College Depth 96 in the knowledge graph I know this Set as goal
8topics build on this
356prerequisites beneath it
See this on the map →
Memory Management FundamentalsContiguous Memory Allocation and FragmentationVirtual Memory and Demand Paging
segmentation segment-table code-segment data-segment stack-segment

Core Idea

Segmentation divides a process's address space into variable-size logical segments that correspond to meaningful program units: code, stack, heap, shared libraries. Each segment has a base (physical start address) and a limit (maximum length), stored in a segment table. Logical addresses are two-dimensional: a segment number and an offset within that segment. The MMU checks that the offset doesn't exceed the segment limit (generating a segmentation fault if it does) and adds the base to produce the physical address. Segmentation supports protection (code segments can be read-only), sharing (two processes map the same code segment), and growing segments (the stack segment grows dynamically). Modern x86-64 systems use paging as the primary mechanism but retain segmentation vestiges.

Common Misconceptions

Explainer

From memory management basics, you know that the OS must translate logical addresses into physical addresses and protect processes from accessing each other's memory. Contiguous memory allocation gave each process a single block of physical memory, but that approach is rigid — a process's code, data, and stack have different sizes, growth patterns, and access permissions, yet they are all crammed into one undifferentiated chunk. Segmentation solves this by splitting the process's address space into distinct logical units — a code segment, a data segment, a stack segment, a heap segment — each of which gets its own contiguous region in physical memory.

Every logical address under segmentation is two-dimensional: a segment number that identifies which segment, and an offset within that segment. When a program generates an address, the hardware looks up the segment number in the process's segment table, which stores two values per entry: the base (where this segment starts in physical memory) and the limit (the maximum valid offset). The MMU first checks that the offset is less than the limit — if it exceeds it, the hardware traps with a segmentation fault. If the check passes, the physical address is computed as base + offset. This two-step check-and-translate happens on every memory access, entirely in hardware, so the programmer writes code using logical segment-relative addresses and never needs to know where the segment actually lives in physical memory.

Segmentation enables two powerful capabilities that contiguous allocation cannot easily provide. First, per-segment protection: the segment table can mark the code segment as read-only and executable, the data segment as read-write but not executable, and the stack as read-write. An attempt to write to the code segment or execute data on the stack triggers a protection fault. Second, segment sharing: if two processes run the same program, their segment tables can point their code segments to the same physical memory, sharing one copy of the instructions while each maintains a private data and stack segment.

The major weakness of segmentation is external fragmentation. Because each segment must occupy a contiguous block of physical memory and segments vary in size, free memory becomes scattered into small gaps between allocated segments over time — the same problem you saw with contiguous allocation, just at a finer granularity. Compaction (shifting segments to consolidate free space) is expensive. This is precisely why modern systems moved to paging, which uses fixed-size pages and eliminates external fragmentation entirely. Modern x86-64 processors still have segment registers, but they are largely vestigial — the OS sets all segment bases to zero and limits to the full address space, effectively disabling segmentation and relying on paging for all address translation and protection.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsLogic Gates FundamentalsImplementing Boolean Functions with GatesKarnaugh Map SimplificationCombinational Circuit DesignFlip-Flops and LatchesBinary Counters: Design and AnalysisBinary ArithmeticFixed-Point Number RepresentationTwo's Complement RepresentationOverflow and Underflow DetectionBinary Adders: Half-Adders and Full-AddersFull Adder and Carry PropagationCarry Lookahead Adder DesignHalf Adder Circuit DesignMultiplication Circuit DesignSequential Circuit DesignRegisters and Register FilesInstruction Set Architecture (ISA)Assembly Language BasicsMemory Organization and AddressingMemory HierarchyMemory Management FundamentalsContiguous Memory Allocation and FragmentationSegmentation

Longest path: 97 steps · 356 total prerequisite topics

Prerequisites (2)

Leads To (1)