$linuxjunkies
>

copy-on-write

also: CoW, copy on write

A memory optimization technique where multiple processes share the same physical memory pages until one attempts to modify the data, at which point a private copy is created for that process.

Copy-on-write (CoW) defers the expensive operation of duplicating data until it's actually necessary. When a process forks or when multiple containers share a filesystem layer, they initially point to the same memory pages or file blocks. Only when one process writes to that data does the kernel create a separate copy for that writer.

This saves significant memory and improves performance, especially in scenarios with many read-only operations. For example, when you fork() a process, the child process doesn't immediately get its own copy of the parent's memory—both share pages until one modifies them.

CoW is heavily used in modern Linux systems: in fork() operations, container storage drivers (like in Docker with overlayfs), virtual machine snapshots, and filesystem features like Btrfs and LVM snapshots. Without CoW, creating a container or forking a process would be prohibitively expensive.

Related terms