Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sharing address space versus duplicating the page table entries

  1. Before copy on write (COW), when it says that the parent and child process share the same address space, it means that they share the same code segment, data segment, heap and stack right?

  2. If the parent and child process share the same address space before COW, what does the page table entries are copied from parent process to child process mean?

  3. Does duplicating the page table entries mean duplicating the address space?

like image 473
nitin_cherian Avatar asked Dec 28 '22 19:12

nitin_cherian


1 Answers

lets say your process is got var name X that have a virtual address 100 and physical address 200. the PTE is holding a mapping of addresses from virtual 100 to physical 200.

after the fork, each process (parent and child) will have his private PTE. at this point both PTEs will map virtual 100 to physical 200.

as long as both process just read from there they both will read from physical address 200.

when the first one will try to write there, the data from physical address will be copy to a new physical space, lets say 300, and his (and only his) PTE will be update so virtual 100 will be mapped to physical 300. that way it's transparent to the process because he is still using the same (virtual) address.

*Note: this is just an abstract, and the real thing is happening in page resolution.

like image 76
Roee Gavirel Avatar answered Jan 03 '23 05:01

Roee Gavirel