2009-03-10 10:27:54 Heap memory alloc failure crash
Hari Prasad (INDIA)
Message: 70701
Hi,
In uClinux, suppose a malloc call fails for the requested memory size, kernel crashes instead of returning a NULL pointer. Because of this, we are not able to ensure the stability of our application. Could you please let us know if there is anything to be changed in the kernel config by which kernel doesn't crash but just returns NULL if the malloc fails. If there is no kernel config, is there any other way to handle this problem.
QuoteReplyEditDelete
2009-03-10 12:53:44 Re: Heap memory alloc failure crash
Robin Getz (UNITED STATES)
Message: 70710
Hari:
This is not uClinux specific - this is the same way that it works on your desktop. It is just your desktop has lots more memory before it becomes "full".
The kernel memory allocator doesn't know if the request is coming from the kernel, or from userspace - so it kills something.
-Robin
QuoteReplyEditDelete
2009-03-11 09:17:08 Re: Heap memory alloc failure crash
Hari Prasad (INDIA)
Message: 70773
Hi Robin,
Thanks for the reply. I would like to know if there is any way that we can program the kernel to gracefully exit rather than to crash as it brings in a lot of indeterminism in our application if the kernel can crash anytime.
QuoteReplyEditDelete
2009-03-11 09:37:48 Re: Heap memory alloc failure crash
Mike Frysinger (UNITED STATES)
Message: 70775
the kernel isnt crashing, nor does the kernel "exit". your application ran out of memory and so it was killed.
there is discussion on lkml about adding a "low memory" notification system, but that isnt implemented yet
QuoteReplyEditDelete
2009-03-11 12:50:04 Re: Heap memory alloc failure crash
Marco Rohleder (GERMANY)
Message: 70786
What he just wanted to ask is:
if malloc() fails, because of not enough memory left, you see a stack trace instead of malloc() just returning NULL
Why ?
QuoteReplyEditDelete
2009-03-11 12:59:36 Re: Heap memory alloc failure crash
Mike Frysinger (UNITED STATES)
Message: 70787
Robin already explained why
QuoteReplyEditDelete
2009-03-12 02:05:50 Re: Heap memory alloc failure crash
Hari Prasad (INDIA)
Message: 70813
Robin and Mike,
If our application asks for memory and is not available, we have routines to safely exit the app incase malloc fails. Isnt it dangerous from the app perspective when you say "so it kills something"?
QuoteReplyEditDelete
2009-03-12 02:29:43 Re: Heap memory alloc failure crash
Mike Frysinger (UNITED STATES)
Message: 70820
that is how it works
you can wait for the aforementioned "low mem" system to be developed, or you can try to write your own in the meantime