Closed GoogleCodeExporter closed 9 years ago
It looks like there are several places still lurking in tcmalloc, where we
crash when
we don't have memory for internal data structures, rather than just returning
NULL
from malloc or realloc or whatever. :-( I'll look to find them all and squash
them
before the next release.
Original comment by csilv...@gmail.com
on 30 Mar 2009 at 11:28
Original comment by csilv...@gmail.com
on 31 Mar 2009 at 7:13
Looking into this, I'm trying to balance the complexity of the code being added
to
handle these out-of-memory situations, with the benefit that we get from it.
These
crashes that you're seeing is because we're out of memory, and fail to allocate
some
internal data structures we need to satisfy a malloc call. Even if we changed
the
code to handle this case correctly (so we raise an out-of-memory exception, in
this
case), what would the benefit be? If you don't catch the exception, and the
program
just dies anyway, maybe that's not much better, and all we should do is print a
more
informative error message. Or if you catch it and die anyway, same thing
perhaps.
So, I guess my question is: what behavior are you hoping for here? What would
you do
if we fixed the code to raise an exception?
Original comment by csilv...@gmail.com
on 3 Apr 2009 at 1:51
Throwing an exception is always clean, probably an error can be logged by
application and it can choose to gracefully exit. There are applications who
use
critical resources and crashing just would be an overkill.
Original comment by I.am.sum...@gmail.com
on 3 Apr 2009 at 1:58
Throwing an exception is clean from the user's point of view, but
implementation-wise, it's difficult because we may be in an internally
inconsistent
state when the out-of-memory exception is thrown, and we'll need to clean all
that up
on the way out. It's much easier for us to just die. That's why I want to
understand how *you're* behaving in the OOM situation, in *your* application.
I understand apps can do arbitrarily interesting things when they get an OOM
exception (or malloc returns NULL), but I don't know of any that actually does
so.
But that doesn't mean they don't exist. What would your app, that triggered
this
issue, do in that situation?
Original comment by csilv...@gmail.com
on 3 Apr 2009 at 3:53
An app does the right thing on OOM when the user code and all of the library
code
does the right thing on OOM. That is much harder to guarantee. There is some
code in
mysqld that does the right thing on OOM. The majority of it does not. I have no
idea
how library code (SSL, zlib, libc) on which it depends behaves.
I would rather have the server die on OOM than run on and possibly corrupt
internal
state.
Original comment by mdcal...@gmail.com
on 3 Apr 2009 at 4:03
I think that's probably a pretty typical attitude. I'm thinking if we make
tcmalloc
malloc return NULL if we can't allocate the bytes the user asked for, but crash
if we
can't allocate the bytes we need internally, it will probably serve the needs of
malloc users just fine.
Given that, I'm tempted to close this bug WillNotFix. What I'd probably really
do is
change from an assert to a more user-decipherable error message. Would that
fit your
needs?
Original comment by csilv...@gmail.com
on 3 Apr 2009 at 5:18
Usually we handle OOM and continue after cleanup. If tcmalloc can not guarantee
to
work properly if it could not allocate internal data structures, then it does
not
make sense to continue anyway.
I guess it's ok to have some error message telling that tcmalloc dies. But still
tcmalloc needs to return NULL if the allocation asked for by the user fails.
So to answer you question: Yes, that would fit my needs.
Original comment by mirko....@web.de
on 15 Apr 2009 at 8:52
OK, I've changed the code to better document failures involving internal data
structures. As always, if we can't allocate because the user is asking too much
memory, we'll return NULL. We'll only crash when the machine is *almost* out of
memory, and the user's request is small enough to fit in the remaining memory,
but
the user's request + the overhead needed by tcmalloc to satisfy the request,
isn't
small enough. I expect that to be quite rare in normal usage.
Original comment by csilv...@gmail.com
on 18 Apr 2009 at 12:13
I'm a tcmalloc user and I highly relay on its ability to return NULL instead of
crashing. I hope that as a library aiming at rock-solid industry standards, this
property will not be loosen. IMO it should be strengthen to be a total
guarantee,
that tcmalloc will never crash.
Original comment by gall.c...@gmail.com
on 2 Feb 2010 at 2:44
PS. Why not preallocate 500 bytes of memory right after tcmalloc start, just to
have
that memory around in case of described situation, when the assert is
activated? This
way tcmalloc would be able to guarantee, that it will always return NULL, and
never
crash.
Original comment by gall.c...@gmail.com
on 3 Feb 2010 at 5:13
Have you actually run into this problem in practice, or are you just concerned
about
it in theory? The situations where it triggers are very specific, and it's
hard for
me to imagine a program working well in that situation in any case. If you're
that
close to being out of memory, you can't depend on anything to really work.
(Note
that just making a really big allocation isn't enough to cause tcmalloc to die.)
There's a real cost, in terms of complexity and performance, in making tcmalloc
behave better in these very unlikely scenarios, and I'd want to understand how
and
why these scenarios arise before deciding how to handle them.
} PS. Why not preallocate 500 bytes of memory right after tcmalloc start, just
to
} have that memory around in case of described situation, when the assert is
activated?
That would work the first time the situation arose, but if you did another
malloc
after that, you'd be back in the same trouble again.
Original comment by csilv...@google.com
on 3 Feb 2010 at 9:33
I run into such situation. I'm pre-allocating a block of memory myself in order
to
free it after first failed allocation reported by malloc(), and then immediately
shutdown the program smoothly. If tcmalloc did the same thing, the shutdown
mechanism
would be guaranteed to be stable. Now, there is a randomness in it.
Original comment by gall.c...@gmail.com
on 17 Feb 2010 at 4:41
Have you ever seen tcmalloc crash because of an out of memory situation? This
is the
kind of problem that is, I believe, more theoretical than actual. If you are
having
specific problems caused by this behavior, let's look at the specifics of it,
and
figure out the best way forward.
Original comment by csilv...@gmail.com
on 17 Feb 2010 at 8:02
Original issue reported on code.google.com by
mirko....@web.de
on 30 Mar 2009 at 7:30