magick++ copy-on-write forking
Posted: 2014-04-09T07:09:21-07:00
I have a linux server with 32gb ram, a C++-application implementing imagemagick and a PDF-file.
If I malloc 16gb of ram when starting the application, imagemagick Magick::Image is unable to convert the pdf-file with ghostscript due to clone() and ENOMEM error.
A normal fork would share the memory (copy-on-write) when forking. It shouldn't actually allocate and copy 16gb of ram from the parent.
If I just call fork() 3 times after allocating 16gb of ram, the process would still only use 16gb ram.
[pid 17708] clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1284de49d0) = -1 ENOMEM (Cannot allocate memory)
[pid 17708] rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, = 0
[pid 17708] rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, = 0
[pid 17708] rt_sigprocmask(SIG_BLOCK, [CHLD], [], = 0
[pid 17708] clone(child_stack=0, flags=CLONE_PARENT_SETTID|SIGCHLD, parent_tidptr=0x7f1284dd495c) = -1 ENOMEM (Cannot allocate memory)
If I malloc 16gb of ram when starting the application, imagemagick Magick::Image is unable to convert the pdf-file with ghostscript due to clone() and ENOMEM error.
A normal fork would share the memory (copy-on-write) when forking. It shouldn't actually allocate and copy 16gb of ram from the parent.
If I just call fork() 3 times after allocating 16gb of ram, the process would still only use 16gb ram.
[pid 17708] clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f1284de49d0) = -1 ENOMEM (Cannot allocate memory)
[pid 17708] rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, = 0
[pid 17708] rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, = 0
[pid 17708] rt_sigprocmask(SIG_BLOCK, [CHLD], [], = 0
[pid 17708] clone(child_stack=0, flags=CLONE_PARENT_SETTID|SIGCHLD, parent_tidptr=0x7f1284dd495c) = -1 ENOMEM (Cannot allocate memory)