Independent values do not require immediate duplication
Copy-on-write delays duplication until a modification requires separate contents. After Linux fork, ordinary private memory behaves as independent parent and child state. Implementing that behavior does not require immediately copying every data page into a second physical allocation. Their page tables can initially reference the same backing pages while the operating system arranges to separate pages when required. Distinguish the program-visible contract from its current physical implementation. A child must not silently change a parent’s private variable merely because the two initially share storage. COW is a way to preserve that independent-value contract while avoiding work on pages that remain unchanged. It is an optimization of copying, rather than an instruction that private state has become application-visible shared memory.
Detect a write before changing the mapping
Write protection can make a modification attempt fault so that the operating system can examine it. The kernel must distinguish an authorized write to a private COW region from a genuinely prohibited access. When separate contents are needed, it obtains another physical page, copies the old contents and redirects the writing process’s mapping. Resuming the instruction then changes the writer’s private view while preserving the other process’s view. That is the conceptual path, not a promise that every COW-related fault performs a physical copy. A page that no longer has competing references may be reusable, and implementations have further optimizations. Fault counts, newly allocated pages and copied bytes are therefore different measurements. Do not infer one directly from another without checking the relevant kernel behavior and sharing state.
Follow x through the parent and child
Let the parent hold x=7 in an ordinary private region before fork. Immediately afterward both processes read seven. The child writes nine, triggering whatever COW resolution is required. The child then reads nine while the parent still reads seven. If the parent subsequently writes eleven, the child’s nine remains unchanged. These results are compatible with both processes using the same variable name and numerical virtual address: their address-space mappings can now reach different physical pages. Explicit shared mappings, such as those created with MAP_SHARED, follow a different contract. Open file descriptions inherited through file descriptors also have their own sharing rules. Never use this private-memory example as proof that every resource inherited at fork has become a separate copy or that every kind of mapping remains isolated.
Changed bytes and copying granularity differ
Assume two shared 4 KiB pages for an illustrative calculation. Changing one byte in the first page can require separating the page, even though the logical update is tiny. A hundred later writes to that already-private page do not necessarily trigger a hundred further copies. Conversely, writing one byte in each of a hundred distinct pages can require substantial page preparation despite a small total number of changed bytes. Count the pages first modified, their placement, and the sharing that still exists when estimating work. The 4 KiB assumption makes the example easy to follow; it is not a statement that every real mapping uses that granularity. Huge pages, page splitting and implementation-specific optimizations can change the actual work, so measured copied bytes cannot be derived from application write size alone.
Measure the deferred work as well as fork
A child that soon replaces its program with exec may avoid modifying most inherited private pages, making much of the deferred copying unnecessary. A child that instead overwrites a large working set can incur faults, allocations and copies after fork returns. Timing only the process-creation call therefore misses an important portion of the workload. Separate creation, child initialization, first writes and completion when designing an experiment. COW also does not make fork itself cost-free or universally constant-time: process structures and page tables still require work. Compare the complete operation needed by the application, including tail latency and peak memory. An improvement in one short timing interval is not evidence that the total job improved under the same load and resource constraints.
Interpret accounting and experiments carefully
Adding the RSS reported separately for parent and child can count shared resident pages twice. PSS apportions shared pages, but its interpretation still depends on observation time and the set of mappings or processes included. A useful experiment establishes a private region, specifies parent-child synchronization, checks the two observed values, waits for the child and cleans up resources. Minor-fault counters can provide supporting observations, but they also reflect other allocation and kernel activity; do not label them exact physical-copy counts. There is an additional programming restriction when fork originates in a multithreaded process: the child’s permitted operations before exec are constrained. A small single-threaded example demonstrates private-value behavior, not a universally safe process-launch design for an already multithreaded application.
Include the end of sharing in the lifecycle
COW also needs lifetime management. When a child exits or unmaps a region, the remaining references can change which work is necessary for a later parent write. Conversely, long-lived children can keep inherited contents referenced while the parent continues modifying its own private view. Investigate which regions each process retains and for how long, rather than considering process count alone. A benchmark using short-lived children may not represent a service with long-lived workers. Include termination and unmapping when reasoning about peak memory and delayed copying. These observations explain where costs can move without assigning a universal number of copied pages to a particular application or kernel version.