In the parent process, the pointer has address p. After fork, the child process sees the same bytes at the same virtual address. From this phrase it is easy to draw two opposite and equally hasty conclusions: either all RAM is immediately copied, or both processes are now freely changing one common array. For an ordinary private mapping, Linux is not required to do either of these things. The same initial content is supported by shared physical storage with deferred separation on write – copy-on-write, COW.
The qualification “private” here defines the entire meaning of the next line. We are considering a hypothetical program fragment, rather than a test or a universal description of all mappings. The parent filled the array in regular anonymous memory, then called fork. We will first observe the reading, then the change of one element. We are interested in when individual physical copies occur and what the RAM counters show. The values for addresses and volumes are made up; system calls on the production server for the article were not launched.
p = private_anonymous_array()
fill(p)
child = fork()
if child == 0:
p[index] = new_value
In the margins near fork()
The fork reference describes creating a separate process and using COW in Linux. Parent and child get their own virtual spaces. Some physical pages may serve both spaces, but this does not turn an ordinary private write by one process into a permitted change to the memory of another. The result is important for the program: after p[index] is changed by the child process, the parent continues to see its value. Physical-storage savings must preserve these semantics.
For implementation, the kernel manages page tables and write permissions. As long as the content is allowed to be shared read-only, both parties can read the shared physical backing. A write attempt results in a corresponding page fault. This fault does not necessarily mean there is no data on the drive or a RAM fault. This may be a normal mechanism for asking the kernel to prepare a separate writable representation of the page. After processing, the program continues the store as private memory requires, and not as random physical proximity would allow.
If the page does remain shared with another live mapping, a separate copy is required. But promising a physical copy for every future write is also wrong. If the other side has already been removed and the page can safely be used exclusively, the kernel is able to restore write permission without pointlessly duplicating bytes. COW sets a condition for maintaining independence, and not a mandatory memcpy ceremony at each store. The details of the optimizations vary; application code should depend on private semantics, and not on the number of internal copies calculated in advance.
This shows why fork is not free even before the first write. The child process needs its own structures, space definitions, and page table maintenance. The size of the virtual area is not equal to the number of pages already in RAM, and the number of these pages does not fully describe the cost of cloning mappings. A huge sparse space and a dense array can behave differently. The phrase “the data has not yet been copied” saves one significant amount of work, but does not prove zero time and memory costs for creating the process.
Note on one assignment
In the analytical example, let the array occupy 256 pages of 4096 bytes and be completely resident. We will not take into account page tables and other process memory for now. If the child only reads the array, its contents can continue to occupy 1 MiB of physical RAM shared between the two processes. If it changes one byte on one shared page, independence usually requires a separate page for that side. The added volume is related to the granularity of the page, not the size of the modified byte. This is a calculation of a simplified model, not a utility reading.
In this model, writing one byte on each page can separate an entire megabyte, although there will only be 256 user-modified bytes. Conversely, multiple assignments within an already private page do not create as many copies of the page. Therefore, the number of updated objects is a poor predictor of COW consumption without knowledge of placement. Two arrays of the same size and the same number of stores can produce different additional RAM if the writes are grouped or scattered across different pages. The meaningful geometry lies below the program data structure.
The selected 4096 bytes cannot be taken as a universal constant for all systems. Architecture and mapping mode matter; large pages add their own ways of division and maintenance. Not every change to a large mapping inevitably requires copying an entire huge page: various solutions are possible, including splitting. Therefore, the arithmetic of the example refers to the explicitly adopted base page model. Transferring it to an accurate forecast for transparent huge pages without checking the configuration and behavior of the kernel would be a substitution of prerequisites.
The initiator of the separation may be a parent. The name copy-on-write sometimes makes one imagine that the parent has an unchanged original, with only the child receiving a copy. In fact, any of the participants is able to be the first to write in their private area. Who gets the new physical page is determined by state and implementation, not by the process’s ancestry. Independent behavior is required on both sides. Even if the child is only busy reading the snapshot, an active parent is able to gradually turn the shared physical content into two sets of pages.
Changes can come from less noticeable code: the allocator updates bookkeeping fields, reference counters change when working with objects, the library writes state. The application task appears to be almost entirely read-only, but the process is still writing. Promising that all the savings will persist just by reading a large user array is not enough. It is required to take into account the actual modified pages of the entire relevant space. This is not a reason to consider COW useless; this explains why the initial array size and subsequent RAM growth need not have a simple linear relationship.

A note beside RSS
After the fork, the monitor can show almost the same RSS for the parent and child. Adding up these numbers as the number of different physical bytes is erroneous: the shared resident page is counted in each process that maps it. Proc_pid_smaps description distinguishes between resident volume and PSS, proportional set size. PSS distributes the cost of a shared page among the processes using it. In our example, two processes can each see a megabyte of array RSS with a significantly smaller amount of unique physical storage.
But the word “private” in diagnostics also needs to be read from the document. Shared/private accounting is not a simple copy of the MAP_SHARED/MAP_PRIVATE flag. A semantically private page of mapping can still be physically shared between processes, and a subsequent write will make it separate. Proc filesystem documentation also explains the details of large allocations and the approximate nature of some counters. A correct analysis relates the reported values to the mechanism without assigning an intuitive, constant meaning to every English word.
Two sequential smaps reads are not a perfectly simultaneous snapshot of the entire machine. While one process is being read, another may have time to change pages or exit. For the hypothetical calculation, it is convenient to freeze the state; for real monitoring, this is a separate observation condition. Therefore, a small discrepancy in amounts does not in itself disprove COW. It requires checking time, the mappings covered and accounting rules. In this article, we use PSS to explain proportional memory cost rather than passing off fictitious proc lines as a measurement.
An exception that changes the original line
mmap reference separates MAP_PRIVATE from MAP_SHARED. A shared mapping is intended for changes in the corresponding area that are visible to other participants. If p in our pseudocode comes from such a mapping, the previous promise of a private array no longer applies. Writing to a shared object requires its own synchronization rules. The fork itself does not turn all inherited mappings into private ones and does not replace inter-process locks. The name of the process creation method does not determine the semantics of each section of its memory.
With a private file mapping, changes also do not have to go back to the original file. Once written, the corresponding range can rely on the anonymous private page, maintaining a logical mapping relationship with the file range. Therefore, it is impossible to see the file name in the mapping description and decide that all its bytes are still shared through the file cache. The physical fate of individual pages varies within an area. This is another example of a mismatch between a convenient large line in the interface and the details of RAM placement.
The program can change the inheritance of individual ranges in advance. madvise describes MADV_DONTFORK, which excludes the region from inheritance, and MADV_WIPEONFORK, which gives the child zero-filled contents of the supported private anonymous region. These are different promises: a missing mapping and a present zero-filled mapping are not interchangeable. Features appeared in historical versions of Linux, they are not news on October 26th. Their presence shows why the short “child gets all the memory of the parent” needs qualifications even before calculating the COW.
Memory does not exhaust process inheritance. Open file descriptors can refer to common open file descriptions, and therefore share the file offset. Array privacy does not mean complete independence of all external resources. This is important to the reader as a boundary to our model: two separate address spaces are not two completely isolated copies of the world. Conversely, the shared file offset does not prove that the ordinary private pointer p has now become a means of exchanging mutable bytes between processes.
After fork of a multi-threaded program, only the calling thread remains in the child, while memory may contain the lock states of other threads. The documentation restricts the calls permitted before execve according to async-signal-safety. Therefore, our short hypothetical program cannot be inserted without changes into an arbitrary multi-threaded service and called a ready-made architecture. The page-saving mechanism does not fix an abandoned mutex hold by a thread that has disappeared. This is a separate property of fork, which directly affects which program continuation is generally correct to discuss.
A normal subsequent execve replaces the userspace with a new image. If the child quickly proceeds to execve, many common pages of the previous image will not require separate content. If both processes live for a long time and actively change previous data, the deferred cost becomes significant. There is no one constant "fork saving percentage": the result is determined by the life of the mappings after creation. The application’s behavior completes the choice that the kernel wisely deferred when it did not yet know whether separate copies would be needed.
Let’s go back to p[index]. The virtual address did not change, but the physical ownership could change just to preserve the semantics of the write. The parent kept reading its old value, the child obtained the new value, and sharing the storage before the write avoided doing the copying in advance. Sources verified October 26, 2026. The point of COW is in this next store and the pages it touches, not in a promise to permanently double or permanently not double visible gigabytes.



