Because COW works on the grounds that the page is read-only, so we need a copy of the page table that is read-only. When a new process is written somewhere, the page error is taken as a result of writing to a read-only page. The error handler of the page looks at the status of the page, determines whether it should be written (if not, segfault, just as if you were writing only for reading in the original process) and copies the corresponding source page to the new process.
The original page table is a read and write for some records, so at least you need to copy them. I really believe that the entire page table is copied (because it makes the other code simpler, and the entry in the page table is not very large - four or eight bytes per page [plus one entry for 4096 KB, plus one for every 4009 * 4096 KB , etc. up the hierarchy].
There are also some interesting aspects if, for example, we have code that does:
char *ptr = malloc(big_number); // Fill ptr[...] with some data. if(!fork()) { // child process works on ptr data. ... } else { free(ptr); }
Now the entries in the page table in the parent process will be deleted. If we will share them with a child process, we need to know that these entries in the page table are shared.
Many other similar problems arise when receiving / sending data over the network, writing to disk, entering and exiting pages, etc.
source share