Why duplicating a huge file on a Mac can finish instantly
Copy-on-write means a copy does not duplicate any data at first. The original and the copy point at the same blocks on disk or in memory, and a block is duplicated only when one side tries to change it.
Duplicate a 10 GB video in Finder on an Apple APFS drive and it appears at once. The new file is just a fresh name pointing at the same blocks. Only when you edit part of one file does the system write new blocks for the changed part.
Concept of the day2 / 3
Copy-on-write
Real-life use case
Linux's fork() makes a new process without copying its memory
When a Linux program calls fork() to start a child process, the kernel does not copy the parent's memory. Both processes share the same memory pages (4 KB chunks), and the kernel marks them read-only.
File systems like ZFS and Btrfs use the same trick for snapshots: a snapshot of a whole disk takes moments, because it only keeps references to blocks that already exist.
Concept of the day3 / 3
Copy-on-write
How it helps
Shared blocks get copied only at the moment someone writes
Reading a shared block is free. A write to a read-only page makes the hardware trap to the kernel (a page fault); the kernel copies just that page, hands the writer its private copy, and lets the write go ahead.
So the cost follows what changes, not the original's size. A child process that reads a lot but writes little costs almost nothing, and since old blocks are never overwritten, a snapshot can keep pointing at them.
What it’s forEstimates how much space an original and its copy take under copy-on-write.
storage = N + c
N
blocks in the original, all still shared after the copy
c
blocks changed since the copy, each now stored twice
What it givesTotal blocks used, which grows only with the edits, not with the copy itself.