Sharing address space and duplicating entries in the page table

  • Before copy on write (COW) , when it says that the parent and child processes have the same address space, does it mean that they have the same code segment, data segment, heap and stack correctly?

  • If the parent and child processes have the same address space before COW, what does the page table entries are copied from parent process to child process ?

  • Does duplication of entries in the page table affect duplication of address space?

+4
source share
3 answers

lets say that your process got the name var X, which has a virtual address of 100 and a physical address of 200. PTE keeps mapping addresses from virtual 100 to physical 200.

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

as long as both processes are simply read from there, they will both read from physical address 200.

when the first one tries to write there, the data from the physical address will be copied to the new physical space, say 300, and its (and only it) PTE will be updated, so that the virtual 100 will be mapped to the physical 300. Thus, it is transparent to the process, therefore that he is still using the same (virtual) address.

* Note: this is just an abstraction, and the real thing happens in the resolution of the page.

+5
source

Page tables represent a data structure for each process that maps between linear addresses and physical addresses. Page table entries are copied from the parent to the child, which means that immediately after fork() both processes use the same page tables that map the same physical addresses to the same linear addresses in each process address space. However, after this, the page tables begin to diverge when each COW error occurs and other address space changes occur.

+2
source
  • Yes, the same physical memory is shared by processes (parent and child).

  • This means that each of them has its own PTE, which translates the virtual address space into a physical address space. immediately after the plug they are the same in general.

  • Yes, this means that after the plug has its own address space, which is identical at the beginning, but can and will be changed later. for example, on COW, malloc, for free, mainly for any change in memory usage in processes.

+2
source

All Articles