I'm working on an application which forks itself up to 8 times for parallelism. Each fork has a full copy of the memory space from the original process at the time of the fork. The forks are quick because Linux shares the pages between the processes and only creates new ones when they are modified. The growth in memory consumption, in practice, seems to be about 3x for my application. Any suggestions for tools or techniques to use in identifying changes that will reduce that growth?
One thought is to look at the page fragmentation of the modified pages. There's also just the brute force examination of what's allocated in the forked processes. In either case, what techniques or tools can you recommend for performing that analysis?
Keep in mind that the program takes several hours to complete even with parallelism and has a memory footprint of up to 1TB so instrumentation options are limited.
The new allocation ensures that a change in the memory of one process is not visible in another's. The copy-on-write technique can be extended to support efficient memory allocation by having a page of physical memory filled with zeros.
Copy-on-write or CoW is a technique to efficiently copy data resources in a computer system. If a unit of data is copied but not modified, the "copy" can exist as a reference to the original data. Only when the copied data is modified is a copy created, and new bytes are actually written.
You can use vmstat
, systemtap
and or glibc
's malloc-hooks
to monitor consumption.
You can use perf
to see where faults are occurring in order to understand the actual impact of the consumption.
If your application faces TLB pressure when you use large memory pools (e.g. you are streaming through a very large volume of data), you can use huge/large pages to mitigate the overhead of 4k pages.
You can also use madvise
to tell the kernel from within your processes what you're probably going to do with the memory that was allocated.
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