Skip to content

Copy-on-Write

Copy-on-Write (CoW) never overwrites a referenced block in place. An update is written elsewhere, then metadata is atomically redirected to the new version.

old root ──→ old metadata ──→ old data
new write → new data + copied metadata path
new root ───────────────────→ new version

Readers following the old root see a complete old version. Readers following the published new root see a complete new version. The critical operation is publishing the root or equivalent commit record atomically.

  1. Read the metadata path to the target block.
  2. Allocate a new block and write the changed data.
  3. Copy and update each affected metadata node toward the root.
  4. Atomically publish the new root pointer.
  5. Reclaim old blocks only when no snapshot references them.

If a crash happens before the new root is published, the old tree remains valid. After publication, the new tree is authoritative.

A snapshot initially needs only another reference to the existing root. Unchanged blocks remain shared. Space grows with later divergence, not with the original logical dataset size.

Snapshots are cheap to create, not free to retain. They keep old blocks reachable, which delays reclamation and can turn deletion into metadata-heavy work.

One small logical update may create:

  • a new data block;
  • several new metadata blocks;
  • allocation and reference-count updates;
  • additional garbage-collection or defragmentation work.

This is CoW write amplification. Long-lived snapshots can also pin old extents and make free space fragmented.

EventExpected behavior
Crash before new root publicationold root remains authoritative
Crash after durable publicationnew tree must be reachable and internally consistent
Partial child writechecksum or structural validation must reject invalid content
Lost reference updatespace may leak or stale reachability may remain
Low free spaceallocation and metadata updates can stall or fail

CoW provides an atomic-update pattern, but durability still depends on write ordering, flush semantics, checksums, and recovery metadata.

  • free space versus actually allocatable contiguous space;
  • snapshot count, age, and exclusive referenced bytes;
  • data and metadata fragmentation;
  • metadata/data allocation balance;
  • scrub errors, checksum failures, and repair status;
  • write amplification and latency as the pool fills.
PropertyCopy-on-WriteWrite-Ahead Log
Commit primitivePublish new rootPersist log record
Old versionNaturally retainedRecovered from log/checkpoint
Snapshot fitExcellentRequires additional structure
Main pressureFragmentation and metadata writesLog growth and checkpoint cost

Many production systems combine the ideas: a log protects metadata transitions while CoW structures provide versioning or snapshots.

CoW is used in snapshotting filesystems, persistent trees, virtual-disk images, and storage arrays. Redirect-on-write is a related snapshot technique that redirects later changes while preserving the original location; implementations differ, so treat product terminology carefully.

  • What is the atomic publication unit?
  • How are reference counts or reachability tracked?
  • What happens when free space becomes fragmented?
  • Can snapshots prevent space reclamation?
  • Is sequential performance hiding random physical allocation?