malloc failure where memory seems available

Under what circumstances can malloc fail even when
there is enough memory availble to satisfy a request?

To explain:

I am experiencing malloc failures with ENOMEM in
Apache. With the application in gdb at the point
of failure, there appears to be 19MB available
(according to sin info) and sin mem shows the process
as:

httpd … 1305K 384K 20K 516K 34

I don’t know what each field represents here, but none
looks unreasonably large.

Malloc fails a request for just 43 bytes. If I continue
the application, it starts four or more additional processes
and continues happily, except that php does ot work. I am
running 6.2.1; under 6.2.0, I believe this does not occur.

Regards
William Morris

Malloc fails a request for just 43 bytes. If I continue
the application, it starts four or more additional processes
and continues happily, except that php does ot work. I am
running 6.2.1; under 6.2.0, I believe this does not occur.

It isn’t malloc that is failing with the php module, it is something
internal to the dl*() calls. It is actually able to load all of the
shared libs and then it fails on a dlsym() lookup (as far as I can tell).
The ENOMEM does not always mean a pure malloc() failure.

chris


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

“Chris McKillop” <cdm@qnx.com> wrote in message
news:badkej$bcu$2@nntp.qnx.com

It isn’t malloc that is failing with the php module, it is something
internal to the dl*() calls. It is actually able to load all of the
shared libs and then it fails on a dlsym() lookup (as far as I can tell).
The ENOMEM does not always mean a pure malloc() failure.

What about when it comes straight out of a malloc call? I trapped
a failing pemalloc() call in PHP’s zend_hash_add_or_update(). The
pemalloc() is a macro which resolves (in this case) to malloc. This
seems to be what is causing PHP initialisation to fail to load functions
into its hash tables.

Maybe you are looking at another problem? My Apache/php are
(from memory) 1.3.23 and 4.2.1 (not too sure of that one - I’m not
at work now).

Thanks for the reply Chris
William

What about when it comes straight out of a malloc call? I trapped
a failing pemalloc() call in PHP’s zend_hash_add_or_update(). The
pemalloc() is a macro which resolves (in this case) to malloc. This
seems to be what is causing PHP initialisation to fail to load functions
into its hash tables.

That is a neat one, and I don’t think my Apache issue is getting that far. :wink:

Maybe you are looking at another problem? My Apache/php are
(from memory) 1.3.23 and 4.2.1 (not too sure of that one - I’m not
at work now).

What are you getting in your /var/log/error_log? I am getting a very odd
output of…

Cannot load /opt/lib/apache/mod_vhost_alias.so into server: Not enough memory

Which occurs after the php module is loaded. So perhaps they are the same
issue?

chris


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

What are you getting in your /var/log/error_log? I am getting a very odd
output of…

Cannot load /opt/lib/apache/mod_vhost_alias.so into server: Not enough
memory

That comes from load_module() or load_file() in response to a LoadModule or
LoadFile directive in httpd.conf (see src/modules/standard/mod_so.c).

So three questions:
Do you want virtual hosting?
Do you have such a directive in your conf file?
If so, does this problem disappear if you remove them?

As to my error, I get:
“PHP Warnning: standard: unable to register functions, unable to load
Unknown on line 0.”

I think the ‘Unknown’ can be ignored; php would put a file name here if the
error came from a file, but in this case it is loading an inbuilt function
into its hash tables.

Assuming that the memory is somehow insufficient, where did my 19MB go?
If I replace the expansion of pemalloc with a wm_malloc() function to trap
memory allocation, I see only a few hundred Kb allocated. There are other
ways it could have allocated memory, I know, but would they not show up in
‘sin mem’?

Do you have any suggestions on how to list all memory allocations from
whatever method used. And how to get apache/php to use them without busting
my brain on their makefiles?

As an aside, when I ran ‘spin’ to get another view of memory usage, it
hung.

William

That comes from load_module() or load_file() in response to a LoadModule or
LoadFile directive in httpd.conf (see src/modules/standard/mod_so.c).

So three questions:
Do you want virtual hosting?
Do you have such a directive in your conf file?
If so, does this problem disappear if you remove them?

Oh, I know all of that. And it doesn’t matter what DSO’s I add. Apache
always reports that the first one in the list cannot be loaded (even though
it HAS been loaded already, shown via pidin mem).

chris


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/

On 21 May 2003 08:04:13 GMT, Chris McKillop <cdm@qnx.com> wrote:

Oh, I know all of that.

Sorry. You mentioned an “odd output” without indicating why you thought it
odd; its not so odd if you are actually trying to load mod_vhost_alias.so.
I was just trying to hep :slight_smile:

And it doesn’t matter what DSO’s I add. Apache
always reports that the first one in the list cannot be loaded (even
though it HAS been loaded already, shown via pidin mem).

What happens if you remove all DSO entries in the conf file?

William

My Apache/php are
(from memory) 1.3.23 and 4.2.1 (not too sure of that one - I’m not
at work now).

Actually it is PHP 4.1.2
William

What happens if you remove all DSO entries in the conf file?

If I just remove php it works fine. :slight_smile: That is the trouble.

chris


Chris McKillop <cdm@qnx.com> “The faster I go, the behinder I get.”
Software Engineer, QSSL – Lewis Carroll –
http://qnx.wox.org/