lkml.org 
[lkml]   [2004]   [May]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [2.4.26] overcommit_memory documentation clarification
On Sun, 9 May 2004, Vincent Lefevre wrote:

> Hi,
>
> The documentation of overcommit_memory in Documentation/sysctl/vm.txt
> should be clarified, as with the following simple program, malloc()
> never returns 0 on an official 2.4.26 kernel, even if overcommit_memory
> has been set to 0. Running it has the effect of having random processes
> killed, and eventually this process itself.

What made you think that malloc would return 0 if the system
was "out of memory??" Malloc will return NULL, which is not 0 BTW,
if you are out of address-space or have corrupted it by writing
past a previous allocation. Malloc's return value is a void *. It
should be compared against NULL, not zero.

When malloc() needs new "memory". It just asks the kernel to
set the new break address or, in the case of mmap() mallocs, asks
to extend a mapped region. Until somebody actually uses those
regions, you haven't used any memory. So there is no way for
malloc() to "know" ahead of time.

If you run a malloc() bomb from the root account you should
end up killing off a lot of processes. If you run it from
a normal user account, and you have set the user's resource
quotas properly, only the user should get into trouble.


Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5557.45 BogoMips).
Note 96.31% of all statistics are fiction.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:03    [from the cache]
©2003-2011 Jasper Spaans