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

Copy-on-Write Memory Optimization

College Depth 100 in the knowledge graph ☐ I know this ☆ Set as goal
370prerequisites beneath it
See this on the map →
Demand Paging and Page FaultsProcess Creation: fork() and exec()→
optimization paging fork

Core Idea

Copy-on-write defers copying memory pages until a process modifies them, reducing overhead when child processes immediately exec(). When fork() creates a child, both parent and child share physical pages; modification triggers a page fault and copy. CoW is essential for efficient process creation in modern operating systems and reduces memory waste.

Explainer

From your study of demand paging, you know that the OS can intercept memory accesses through page faults and respond by loading pages on demand rather than upfront. Copy-on-write (CoW) applies the same principle to a different problem: when fork() creates a child process, must the OS immediately duplicate every page of the parent's address space? The answer is no — and avoiding that copy makes process creation dramatically faster.

Consider what happens without CoW. A process with 500MB of memory calls fork(). The OS must allocate 500MB of new physical memory and copy every byte, even though the child process will likely call exec() within microseconds, replacing all that memory with a new program. This is an enormous waste of time and memory. With CoW, fork() does no copying at all. Instead, the OS points the child's page table entries at the same physical frames the parent uses and marks every shared page as read-only in both page tables. The two processes share all their memory, and neither knows it.

The deferred copy happens through the page fault mechanism you already understand. When either process — parent or child — tries to write to a shared page, the CPU triggers a page fault because the page is marked read-only. The OS page fault handler recognizes this as a CoW fault (not a genuine protection violation), allocates a new physical frame, copies the contents of the shared page into it, updates the writing process's page table to point to the new copy with write permissions, and resumes execution. The other process keeps the original page. From this point forward, the two processes have independent copies of that one page — but only that page. All unmodified pages remain shared.

This optimization is particularly powerful because of how fork() is typically used. The overwhelmingly common pattern is fork() followed immediately by exec(), which replaces the child's entire address space with a new program. With CoW, this pattern touches zero data pages — the child never writes to the parent's memory, so no copies ever occur. Even when fork() is used without exec(), most pages are read-only code and shared libraries that neither process will modify. In practice, CoW means a fork() that would have copied hundreds of megabytes instead copies only the page tables themselves — a few kilobytes — and defers the rest to the rare moments when it is actually needed.

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 → Cache Memory Design → Cache Replacement Policies → Virtual Memory and Paging → Virtual Memory and Demand Paging → Page Replacement Algorithms → Demand Paging and Page Faults → Copy-on-Write Memory Optimization

Longest path: 101 steps · 370 total prerequisite topics

Prerequisites (2)

Leads To (0)

No topics depend on this one yet.