Question on the current behaviour of malloc () on uClinux

David McCullough davidm at snapgear.com
Wed Dec 21 21:28:04 UTC 2005


Jivin Jie Zhang lays it down ...
> Hi,
> 
> Currently uClinux will call oom-killer if some process fails to
> allocate a block of memory by malloc (), which usually will kill that
> process. This behaviour can be observed by running a small test, which
> repeatedly call malloc (), on uClinux. This is not expected according
> to SuSv3. SuSv3 says:
> 
>   If the space cannot be allocated, a null pointer shall be returned.
> 
> So the application should be notified the failure of malloc () rather
> than being killed.
> 
> I traced this issue to __alloc_pages (). If there is not enough free
> pages for allocation, it will call try_to_free_pages () to reclaim
> page frames. If try_to_free_pages () cannot help, which usually occurs
> when run a fail-to-malloc application the second time, __alloc_pages
> () will call out_of_memory (), which in turn will kill something.
> 
> 
> Can we make __alloc_pages () not call out_of_memory () if the
> allocations request comes from malloc () and just return NULL?

The problem is under uClinux,  when an app cannot get memory,  the
kernel also cannot get memory,  and if the kernel is out of memory it
starts trying to make some.

Thats life on MMUless systems IMO.  Others may disagree,  but if the
system is completely out of memory (kernel and user) returning NULL just
isn't going to cut it,

Cheers,
Davidm

-- 
David McCullough, davidm at cyberguard.com.au, Custom Embedded Solutions + Security
Ph:+61 734352815 Fx:+61 738913630 http://www.uCdot.org http://www.cyberguard.com



More information about the uClibc mailing list