[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#247300: libc6: malloc() never fails on 2.4 kernels, making processes crash



severity 247300 normal
thanks

At Tue, 4 May 2004 14:41:22 +0200,
Vincent Lefevre wrote:
> I've set the overcommit to 0, and the malloc() function never fails,
> even when there isn't enough memory left, making processes crash when
> they need memory they have already allocated.

"never" is actually not true.  Change ONEMB larger.  malloc() should
become to be failed.

> I'm not sure whether this is a libc6 or a kernel bug. I'm not familiar
> with the glibc source, but could this be due to the following code?

IIRC, this kind of OOM (Out Of Memory) situation has been discussed at
linux kernel related lists for a long time.  Your sample code repeats
to issue mmap() and to fill the acquired pages until it got problem.
So kernel needs to detect the phisycal memory exhaustion before
allocating virtual memory.  Please imagine how to do it (to deal with
vairous types of memories like mmap)?  Yeah, welcome to VM world.

AFAIK, in kernel 2.6, there is strictly overcommit mode
(/proc/sys/vm/overcommit_memory = 2) to prevent from getting sigkill
by OOM killer and so on.  It helps you that malloc() should be return
with the limit (see /proc/sys/vm/overcommit_ratio).

Rik van Riel and et al released various MM improvement patches.
Please check them if you keep to use kernel 2.4.

> malloc/arena.c:
> 
>   /* A memory region aligned to a multiple of HEAP_MAX_SIZE is needed.
>      No swap space needs to be reserved for the following large
>      mapping (on Linux, this is the case for all non-writable mappings
>      anyway). */
>   p1 = (char *)MMAP(0, HEAP_MAX_SIZE<<1, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE);
>                                                                 ^^^^^^^^^^^^^

Use strace.


I don't think it's glibc bug.  It's linux specification.  I would like
to close this bug, ok?  If you want to discuss about this issue more,
I recommend you lists: linux-kernel/linux-mm/kernelnewbies that are
good place.

Regards,
-- gotom



Reply to: