You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Bill Moseley <mo...@hank.org> on 2001/02/07 14:43:42 UTC

[OT] Freeing Memory with of C extensions under Solaris

Hi,

Sorry for the OT, and I'm sure this is common knowledge.

I'm using some C extensions in my mod_perl application.  IIRC, memory used
by perl is never given back to the system.  Does this apply also to
malloc() and free()ed memory in my C extension?  Or is that OS dependent?
Can Apache ever shrink?

I ask because I'm using some C extensions that do a lot of memory
allocating and freeing of somewhat large structures.

I'm running under Linux and Solaris 2.6.

Another memory issue: I'm using File::Cache with a cron job that runs every
ten minutes to limit the amount of space used in /tmp/File::Cache -- it
seemed better than using an Apache child to do that clean up work.  But on
Solaris /tmp is carved out of swap.  Do you think it's risky to use /tmp
this way (since full /tmp could use up all swap)?

Thanks very much,



Bill Moseley
mailto:moseley@hank.org

Re: [OT] Freeing Memory with of C extensions under Solaris

Posted by "G.W. Haywood" <ge...@www.jubileegroup.co.uk>.
Hi Bill,

On Wed, 7 Feb 2001, Bill Moseley wrote:

> I'm using some C extensions in my mod_perl application.  IIRC, memory used
> by perl is never given back to the system.  Does this apply also to
> malloc() and free()ed memory in my C extension?  Or is that OS dependent?

It's not clear from your post whethere you're using C to extend Apache
or Perl.  If it's Apache you should be using pools for efficiency's
sake.  There are two sorts of pools (at least:) - those which live for
the lifetime of the parent and those which live for the lifetime of
the child.

If you're using XS then you probably should be using the New(), Newc()
etc. interface to malloc().  See 'perldoc perlapi', 'perldoc perlguts'
and 'perldoc perlxs'.  I guess you already have?

If hacking Perl then you can probably do what you like.

Quote from perldoc perlguts:

       It is suggested that you enable the version of malloc that
       is distributed with Perl.  It keeps pools of various sizes
       of unallocated memory in order to satisfy allocation
       requests more quickly.  However, on some platforms, it may
       cause spurious malloc or free errors.

Eeek!

If you use plain old C malloc() then unless it's been replaced by the
Perl version (which I think they'd like) you'll get your memory back
OK.  Simple enough to check with 'top'.

> Can Apache ever shrink?

If you use plain malloc, yes.  You free some of the the Apache and
Perl pools when a child dies.

See also apache/htdocs/manual/new_features_1_3.html - look for "ALLOC_DEBUG".

HTH

73,
Ged.