bug-glibc
[Top][All Lists]
Advanced

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

Re: Problem with malloc on very large blocks of memory


From: Petr Vandrovec
Subject: Re: Problem with malloc on very large blocks of memory
Date: Mon, 24 Mar 2003 17:18:25 +0100

On 24 Mar 03 at 9:20, Dan Klebanov wrote:
> >What else do you expect? You also have error message in the kernel
> >log saying that system run out of memory and killed biggest memory
> >
> >  
> >
> 
> What I expect is that malloc should behave according to spec.  In other 
> words, if there's not enough memory left in the system,  then it should 
> return NULL.  Otherwise, what's the point of checking for NULL?  The way 
> it works now is that it hands you the memory, but barfs as soon as you 
> try to use it.  

Then set /proc/sys/vm/overcommit_memory to "2" to disable overcommit.
If there is "1", it means that you can allocate any amount of memory,
and you'll get SIGBUS or SIGKILL if you'll try to use it (SIGBUS if
you are not biggest offender, SIGKILL if system decides that you are not
behaving nice).

> > hog to stay alive. Just do not do that - disable memory overcommit
> > if your working set may be larger than available memory and you cannot
> > accept killing process.
> >                                                Petr Vandrovec
> >                                                address@hidden
>                                                 
> 
> Isn't it  the operating system's job to tell me when I'm out of memory?

Yes. It told to you that there is not enough memory. malloc returining
NULL is only one way to inform you about not enough memory. You should
be prepared for SIGBUS when you touch memory, or even for SIGKILL (but
if you got SIGKILL, it really means that you allocated way too much...)
                                                                Petr
                                                                





reply via email to

[Prev in Thread] Current Thread [Next in Thread]