Home

CopyonWrite

Copy-on-write (COW) is a resource management strategy in which multiple callers can share a single instance of data and only incur the cost of copying when a modification is necessary. Under COW, reads can access the shared data without duplication, while writes trigger a duplication so that the writer receives an isolated copy. This approach aims to reduce unnecessary copying and improve performance by deferring work until it is actually needed.

In memory management, COW is famously used during process creation in many operating systems. When a process

In file systems and storage, COW enables efficient snapshots and atomic updates. Instead of overwriting blocks

Applications beyond file systems include persistent data structures in programming, where structural sharing allows efficient versioning

forks,
the
parent
and
child
initially
share
the
same
physical
memory
pages.
These
pages
are
marked
as
read-only,
and
a
reference
count
tracks
how
many
processes
reference
each
page.
If
either
process
writes
to
a
shared
page,
a
page
fault
occurs;
the
kernel
then
creates
a
private
copy
of
the
page
for
the
writing
process
and
updates
the
page
table.
Subsequent
writes
affect
only
the
private
copy,
while
reads
continue
to
reference
the
shared
data
until
a
copy
is
required.
in
place,
new
blocks
are
allocated
for
changes
and
metadata
updates
are
performed
atomically,
preserving
previous
versions.
File
systems
such
as
Btrfs,
ZFS,
and
APFS
use
COW
to
implement
snapshots,
rollbacks,
and
crash-consistent
updates
with
reduced
risk
of
data
corruption
and
without
duplicating
unchanged
data.
without
copying
entire
structures.
While
COW
offers
performance
and
memory
advantages,
it
introduces
overhead
for
reference
tracking
and
potentially
increased
write
amplification
in
certain
workloads.