I have a linux server process that load big resources on startup. This processes will fork on request. The resources that are loaded on startup are the bigest stuff and will not change while runtime. The folked child processes use read/write control structures to handle requests to the constant resources.
How do I find out how much memory is shared between the processes and how many is uinque for every process? Or what pages are duplicated because of write access from any of the processes?
What fork() does is the following: It creates a new process which is a copy of the calling process. That means that it copies the caller's memory (code, globals, heap and stack), registers, and open files.
Address space copying latency: Traditional fork() creates a copy of the memory image of the calling process, potentially copying large amounts of memory to the child.
Answer: Only the shared memory segments are shared between the parent process and the newly forked child process. Copies of the stack and the heap are made for the newly created process.
When a fork() system call is issued, a copy of all the pages corresponding to the parent process is created, loaded into a separate memory location by the OS for the child process. But this is not needed in certain cases. Consider the case when a child executes an "exec" system call or exits very soon after the fork().
You can get this information from the /proc/$pid/pagemap
and /proc/kpagecount
and /proc/kpageflags
virtual files in the proc filesystem. Access to the latter requires root because it could leak privileged information about process memory mappings you don't own. Read Documentation/vm/pagemap.txt
from the kernel docs for details on the data format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With