https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70732

--- Comment #2 from Krzysztof MaƂysa <krzyk240 at gmail dot com> ---
I read some code from unwind-dw2-fde.c and it makes sense.

In the code above, stack unwinding happens in low memory conditions which
causes unsuccessful memory allocations and because of deep recursion, there are
so many of them.

But maybe it is reasonable to make an optimization to not flood system with
many, many unsuccessful syscalls (brk() and mmap2()). It's important to note
that stack unwinding happens at the bottom of recursion (so it's unlikely that
there will be more memory available - see
https://github.com/gcc-mirror/gcc/blob/master/libgcc/unwind-dw2-fde.c#L957),
also look at these syscalls which malloc makes:
brk(0xcad8000) = 0xcab4000
mmap2(NULL, 1048576, ...) = -1
It tries to expand stack (which is not successful due to deep recursion that
was made) and to map 1MB of memory, what is very much compared to what is
needed, so it will almost always result in malloc() returning NULL. That is why
it doesn't make much sense to call malloc() all the time if there is no memory
available while we're freeing only small chunks of memory.

All in all, I agree that there is no bug, but I think that it's a good
opportunity to make an optimization here.

Reply via email to