The Copy That Does Not Happen Until You Write
Subtitle: Share one page until someone writes.
Left column - Before the write:
A and B point at one shared page Only the page table was copied Every shared page marked read-only Copy is instant at any size fork of 2 GB returns in under 1 ms
Right column - After B writes:
The CPU raises a page fault Kernel copies just that one 4 KB page Flips the new page to writable B gets a private copy, A keeps v1 The same instruction then resumes
Simple difference:
Copy = duplicate the page table only Write = duplicate one page, on demand
Taped rule strip:
You pay per page touched, not per byte owned.
- The order of the mechanism - three beats:
- Intercept the write
- Copy one page privately
- Leave the original untouched
Where it shows up:
fork in an operating system Database and ZFS or Btrfs snapshots Virtual machine snapshots Version control history
- Honest test - three steps:
- fork under heavy write traffic
- Watch resident set size climb
- Free copy becomes a near-full copy
Sticky note - Common beginner mistake:
The cost is deferred, not removed. It arrives as latency at the worst moment. Redis saving while writes pour in can copy nearly every page, so peak memory nears double the dataset and the host starts swapping.