Copy-on-Write
conceptWhen an ordinary system saves a change, it writes the new version on top of the old one, right where it sat. That's the obvious approach, and it carries a hidden bet: that nothing goes wrong mid-write. Lose power at the wrong instant and the old version is half-destroyed while the new one is half-written—the ugly middle that older systems needed repair tools for.
Copy-on-write is ZFS's refusal to ever make that bet: existing data is never written over. Ever. When you "change" a file, ZFS writes the new version onto fresh, empty space, and then—in one clean, instant switch— makes it the official one. So at every moment, what's on disk is some complete, correct state. A change either fully happened or never happened; there is nothing half-done to repair, which is why no repair pass exists.
You feel CoW everywhere before you can name it:
- Snapshots are instant and free—old blocks were never going to be overwritten, so "keep the past" is just "don't garbage-collect these yet."
- Power loss stops being scary—pull the plug mid-write; on import the pool is simply at the last committed moment. No repair pass.
- Free space is a working resource—even overwrites and deletions need fresh space to land, which is why a nearly-full CoW pool degrades (see The Free-Space Discipline).
- Sequential writes fragment over time—rewrite the middle of a file and the new blocks live elsewhere; the file's layout scatters. The steady state of a busy CoW pool is honest fragmentation managed by caching.
What it gets confused with:
- Journaling (ext4, XFS): a journal records intentions, then performs overwrites in place, and replays intentions after a crash. Repair machinery for a dangerous act. CoW removes the dangerous act—there's nothing to replay.
- The other CoWs: APFS and Btrfs share the discipline (APFS without data
checksums); qcow2 does it at the image-file level; even
cp --reflinkis CoW at the file level. The idea won. ZFS's version is distinctive for being welded to checksums and redundancy. - "CoW is slow": half-true, workload-shaped. Random-rewrite workloads (VM images, databases) pay real fragmentation costs—that's the true part and why recordsize and mirrors matter there. For most everything else the cost is noise against the durability purchased.