Why copying a process doesn't copy all of its memory: the boundaries of copy-on-write
When a program calls fork to create a child process, the call returns almost immediately. Intuitively, the operating system should copy the entire block of m…

When a program calls fork to create a child process, the call returns almost immediately. Intuitively, the operating system should copy the entire block of memory the parent process occupies: tens of megabytes, hundreds of megabytes of data — how could that finish in milliseconds? The answer isn't that memory got faster; it's that this step doesn't copy content at all.
What the kernel does is copy mappings, not data. It builds a new set of page tables for the child process, pointing the physical pages in them at the same batch of memory the parent is already using, while changing both sides' permissions on those pages to read-only and adding a reference count to each physical page. So the parent and child see two virtual address spaces, but behind them is the same physical memory. The return is fast because the work changes from moving bytes to registering relationships.
The actual copying happens at the first write. If either side tries to modify these shared pages, the processor triggers an exception because of the read-only protection, and the kernel steps in: it confirms the page really is shared by multiple parties, allocates a new physical page, copies the original page's contents over, updates the writing side's page table and restores write permission. Whoever writes first pays the copy cost for that page. This mechanism — deferring on demand and splitting only at write time — is copy-on-write.
An everyday analogy: two people first look at the same document together; whoever wants to modify it makes a copy first and then writes, and the original in the other person's hands is unaffected. The difference is that the operating system works page by page, with a granularity usually of a few KB per page, not the whole document; and the copying is done by the kernel behind the scenes, with the program itself only feeling a brief pause.
This also explains a common contrast: some programs call exec right after fork to load a new program, so the child process barely touches the parent's old memory, those pages never need to split, and the whole startup seems very light. Other programs keep running in the child after fork and heavily rewrite inherited data structures, so they trigger copies page after page, and also bear the overhead of exception handling, page table updates, and address-translation cache invalidation — which shows up as a fast start followed by a slower stretch.
There are quite a few limitations to spell out. Copy-on-write is an implementation choice of a specific kernel; different systems and different versions differ in page table management, reference counting, and exception handling. With huge pages enabled, a single split involves more bytes, and a single pause may be more noticeable. When memory is tight, shared pages may also be swapped out or reclaimed, and the cost shifts elsewhere. In multithreaded programs, synchronizing the reference counts themselves also has a cost. So "fork is fast" can't be taken as a universal conclusion; it holds only under the premise that there is little writing afterward.
The same idea appears elsewhere: filesystem snapshots, virtual machine memory snapshots, and the layering of some container images all tend to share first and split later. Their common premise is many reads and few writes; once the write proportion rises, the latency is exposed all at once.
From an engineering perspective, the value of this principle is in asking the question correctly: don't just ask how long one call took, but also ask where the cost was deferred to and who bears it. The copying hasn't disappeared; it just moved from creation time to the time of the first write. Understanding this means that when you see "instant creation, mid-run jitter," you won't mistake it for a random performance fault, but will go check the write pattern on shared pages.