bug-glibc
[Top][All Lists]
Advanced

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

Malloc can not allocate memory


From: Roman Fleysher
Subject: Malloc can not allocate memory
Date: Sun, 19 Jan 2003 00:10:56 -0500

Hello,

I have a problem, where malloc() can not allocate memory, while I know it
is physically available on the system (I consume about 780 MB out of 2GB).
This is reported by both NULL pointer and errno variable.

Let me give more details of the problem and what I did to try to identify
it. Starting from the end:

1. I have set the environmental variable MALLOC_CHECK_= 1, no diagnostic
was printed out at stderr which would indicate an error.

2. I used mtrace() to see if I malloc/free corresponding pairs. Then used
a perl script mtrace to process the log. Nothing (as far as I can tell,
the output is huge, may be I overlooked something).

3. Used -lmcheck when linking. Nothing new.

More details about the program. As far as malloc/free is concerned, the
program consists of two parts: read data file, where some malloc()/free
happens in order do decompress the events (data), and the processing part,
where huge buffers are allocated to analyze the events. (The compressor is
home made.) The buffer size to analyze these events is expected to be
around 2GB, allocated graduatelly as events are read. The system has 2GB of
physical memory and 1GB of swap space which should be enough. When the
program runs, the malloc fails, when the memory consumptions is about
780MB. If I switch off the analysis part, which means just scan through
the data, the program completes, suggesting that the decompressor itself
is OK (I have also other reasons to think it is OK).

I have made a further test, where I substituted the data read part, by a
simulation code, which simulates the events, and does not use malloc/free
in it. This would provide the check for buffers. In this configuration,
the program runs to the end and consumes the expected amount of memory.
Thus, I conclude that the buffer (analysis) part is also OK and that the
operating system is able to "give" the needed space.

Conclusion: There are only two parts of the code that use malloc/free,
both parts seem to work properly, but malloc() can not allocate memory
after about 780 MB is taken out of 3GB available. Here, 780MB is the size
of the arena reported by mallinfo() after the failed malloc. "Usual"
checks of internal malloc() bookkeeping did not results in catching the
problem. (Tables look fine?)

Does anyone have an idea what may be wrong and how to identify the cause?
What additional tests I may try?

Thank you for your help,

Roman





reply via email to

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