Failures of the pitchfork: memory cannot be allocated

I have a program running on a Linux machine. He deploys the process of sending mail and often logs messages about plug failures, stating that he cannot allocate memory.

When I check the size of the resident memory, it is about 12 GB (swap is set to 1 GB on this computer).

Is there a way that I can be sure that this huge chunk of memory is not a leak, but simply memory growth?

Also, is there a system limit that can be configured so that I don't get fork failures?

+4
source share
2 answers

To check for memory leaks, you can run the program under Valgrind: http://valgrind.org


To get / set restrictions from the console / shell, the ulimit command is available.

Inside the program, the system calls getrlimit() / setrlimit() provide this functionality.


Another workaround for situations where memory might become hard due to fork() ing would be to use vfork() immediately after calling a member of the exec*() family of functions.

From man vfork :

vfork () is a special case of clone (2) . It is used to create new processes without copying the page tables of the parent process. It can be useful in applications with a high degree of sensitivity, where a child is created, which then immediately issues execve (2) .

vfork () differs from fork (2) in that the parent object is paused until the child completes (either fine by calling _exit (2) or abnormally after sending a fatal signal), or it calls execve (2) . Prior to this point, the child shares all memory with its parent, including the stack. The child should not return from the current function or call exit (3) , but can call _exit (2) .

+3
source

I got it now on an embedded system. There were no restrictions and there was enough free RAM for a small df process, so that confused me. Then I remembered that fork() works via copy-on-write, so it is likely that in the near future the child process may need as much RAM as the parent process. You just need to keep in mind if you see that the machine is supposed to have a lot of free RAM - does it have at least as much free RAM as the process calling fork() uses?

+1
source

Source: https://habr.com/ru/post/1498331/


All Articles