Re: malloc under linux
- From: "J. J. Farrell" <jjf@xxxxxxxxxx>
- Date: Wed, 03 Oct 2007 19:23:51 -0700
On Oct 3, 6:58 pm, jacob navia <ja...@xxxxxxxxxx> wrote:
Eric Sosman wrote:
jacob navia wrote On 10/03/07 12:39,:
Hi
I was working under linux today when I discovered this:
man malloc
<quote>
[snip pages]
BUGS
By default, Linux follows an optimistic memory allocation strategy.
This means that when malloc() returns non-NULL there is no guarantee
that the memory really is available. This is a really bad bug.
In case it turns out that the system is out of memory, one or more
processes will be killed by the infamous OOM killer. In case Linux is
employed under circumstances where it would be less desirable to
suddenly lose some randomly picked processes, and moreover the kernel
version is sufficiently recent, one can switch off this
overcommitting behavior using a command like
# echo 2 > /proc/sys/vm/overcommit_memory
<end quote>
I just can't believe my eyes.
Old news. In fact, it's Question 7.14 in the FAQ.
See also <http://lwn.net/Articles/104179/>.
The question 7.14 is
--------------------------------
.14: I've heard that some operating systems don't actually allocate
malloc'ed memory until the program tries to use it. Is this
legal?
A: It's hard to say.
-----------------------------------
????????
Why not say "linux" instead of "some operating systems" or at least
"some operating systems like linux for instance"
Perhaps that text was written before Linux was created, or perhaps the
author wasn't aware that Linux worked this way. Why should it
expicitly mention one particular OS?
And the answer is REALLY clear: "It's hard to say"...
I never thought you were speaking about linux.
It is clear that:
<quote>
The malloc function allocates space for an object whose size is
specified by "size" and whose value is indeterminate.
Returns
3 The malloc function returns either a null pointer or a pointer to the
allocated space.
<end quote>
NULL means failure, and non NULL means that an object space is
allocated.
Malloc operates in the process's virtual memory space; if there's
allocatable space available in the part of the process's virtual
memory which malloc controls, it will return that virtual range. If
the OS can't find any physical memory to implement part of the
process's virtual memory when the process tries to write to it, the OS
will kill the process. Malloc works as advertised, but the OS can
randomly kill the process at any time.
.
- Follow-Ups:
- Re: malloc under linux
- From: Richard Heathfield
- Re: malloc under linux
- From: Walter Roberson
- Re: malloc under linux
- References:
- malloc under linux
- From: jacob navia
- Re: malloc under linux
- From: Eric Sosman
- Re: malloc under linux
- From: jacob navia
- malloc under linux
- Prev by Date: Re: malloc under linux
- Next by Date: Re: User Input issue
- Previous by thread: Re: malloc under linux
- Next by thread: Re: malloc under linux
- Index(es):
Relevant Pages
|
|