Copy-on-Write
Sharing a copy until the moment one side writes to it, deferring the cost of duplication until it's actually needed.
Copy-on-write is a strategy for sharing data cheaply: two owners are handed the same underlying storage, and neither pays the cost of a real copy until one of them writes. At that point, and only then, the writer's view is duplicated and diverges from the original, while a reader that never writes never triggers the copy at all.
The technique appears at several layers that rarely get connected. When a Unix process calls fork(), the child gets its parent's entire memory space mapped copy-on-write rather than physically duplicated — cheap and instant, with actual page copies happening lazily, one 4KB page at a time, only for the pages either side later modifies. Filesystems like ZFS and Btrfs apply the same idea to disk blocks: a Filesystem Snapshot is nearly free to create because it shares every existing block with the live filesystem, and only diverges block-by-block as writes land. Some database engines use it for transaction isolation, giving a long-running read a consistent view without blocking writers, since the writer's changes land on new copies rather than mutating what the reader is looking at.
The trade copy-on-write makes is complexity for cost: tracking which pages or blocks are shared and which have diverged requires reference counting (see Garbage Collection) or a similar bookkeeping structure, and a workload that writes to nearly everything it touches gets little benefit and pays that bookkeeping overhead anyway. It earns its keep specifically when most of the shared data survives unmodified — the common case for both process forking and filesystem snapshots.
See also4
Inode
The record a Unix filesystem keeps about a file's metadata and data location — everything except its name.
Systems & Tooling9 connections
Process
A running program with its own memory, environment, and identity.
Systems & Tooling33 connections
Idempotence
The property that performing an operation twice has the same effect as performing it once.
Systems & Tooling34 connections
Atomic File Write
Replacing a file so that readers and crashes see either the complete old version or the complete new one, never a half-written mix, by writing a temporary file and renaming it over the original.
Systems & Tooling12 connections
Linked from9
- Agent SandboxAgents & Language Models
Confining an agent's commands to a limited environment, so that a mistaken or hijacked action can only damage what the sandbox allows it to reach.
- Atomic File WriteSystems & Tooling
Replacing a file so that readers and crashes see either the complete old version or the complete new one, never a half-written mix, by writing a temporary file and renaming it over the original.
- Disk ImageSystems & Tooling
A single file holding the complete contents and structure of a disk, used to install operating systems, run virtual machines, preserve old media, and copy drives exactly for forensic investigation.
- Filesystem SnapshotSystems & Tooling
A point-in-time, near-free copy of a filesystem's state, made possible by sharing unchanged blocks with the live data.
- ImmutabilityComputation & Algorithms
A value that cannot change after construction, so sharing it never risks a caller seeing another caller's edit.
- InodeSystems & Tooling
The record a Unix filesystem keeps about a file's metadata and data location — everything except its name.
- Persistent Data StructureComputation & Algorithms
Data structures that preserve every previous version when changed, sharing unchanged parts between versions so "copying" is cheap.
- RAIDSystems & Tooling
Combining several disks into one logical volume for speed, redundancy, or both, through striping, mirroring, and parity, and why it is never a substitute for backups.
- Virtual MemorySystems & Tooling
Giving every process its own private address space that the kernel maps onto physical memory page by page, on demand.