When a program calls fork(), the operating system creates a child process that is an exact copy of the parent. In the 1970s that meant physically duplicating every page of memory — instantly expensive, even if the child immediately replaced itself with a new program via exec().
Copy-on-write (COW) changed the game with a beautifully lazy idea: instead of copying, let both parent and child point at the same physical pages and mark them all read-only. Nothing is duplicated yet. The moment either process tries to write to one of those pages, the hardware raises a fault, the kernel steps in, makes a private copy of just that page, and lets the write proceed. Pages that are never written are never copied at all.
The result is that fork() goes from work — proportional to the size of the process — to roughly work plus a small per-write overhead paid lazily. For programs that fork only to exec a new binary right away, the total copy cost approaches zero.
Comments
Loading comments...