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 Fragmentation→→Virtual 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 Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Assembly Language Basics → Memory Organization and Addressing → Memory Hierarchy → Memory Management Fundamentals → Contiguous Memory Allocation and Fragmentation → Segmentation

Longest path: 97 steps · 356 total prerequisite topics

Prerequisites (2)

Leads To (1)