Finding memory leaks in httpd and httpd modules

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Finding memory leaks in httpd and httpd modules

Kevac Marko-2
Hello.

What is the best way for finding memory leaks in httpd and httpd modules?

Are there any howtos?

I'v tried valgrind a little, but few obstacles appeared:

1. Valgrind expects for binary to exit normally. I have managed to do
that with MaxRequestsPerChild and -X parameter.
2. Valgrind reports about lots of stuff, probably connected with apr
pools, but nothing useful.

OS: Linux

--
Marko Kevac
Sent from Moscow, Mow, Russia
Reply | Threaded
Open this post in threaded view
|

Re: Finding memory leaks in httpd and httpd modules

Brian McQueen
I have done a lot of c module development. I have found the same problem and wound up simply running the module under load while keeping an eye on memory usage.

Use the pools. They are great and will keep you safe. Any other use of memory allocation should be very carefully considered.

------Original Message------
From: Kevac Marko
To: [hidden email]
To: [hidden email]
ReplyTo: [hidden email]
Subject: Finding memory leaks in httpd and httpd modules
Sent: Feb 16, 2010 12:09 AM

Hello.

What is the best way for finding memory leaks in httpd and httpd modules?

Are there any howtos?

I'v tried valgrind a little, but few obstacles appeared:

1. Valgrind expects for binary to exit normally. I have managed to do
that with MaxRequestsPerChild and -X parameter.
2. Valgrind reports about lots of stuff, probably connected with apr
pools, but nothing useful.

OS: Linux

--
Marko Kevac
Sent from Moscow, Mow, Russia


Sent via BlackBerry by AT&T
Reply | Threaded
Open this post in threaded view
|

Re: Finding memory leaks in httpd and httpd modules

Kevac Marko-2
On Tue, Feb 16, 2010 at 10:12 PM,  <[hidden email]> wrote:
> I have done a lot of c module development. I have found the same problem and wound up simply running the module under load while keeping an eye on memory usage.
>
> Use the pools. They are great and will keep you safe. Any other use of memory allocation should be very carefully considered.
>

Of course I am using pools, but using pools is not panacea, especially
when non request pool is used :-)

--
Marko Kevac
Reply | Threaded
Open this post in threaded view
|

Re: Finding memory leaks in httpd and httpd modules

Sam Carleton
On Tue, Feb 16, 2010 at 2:35 PM, Kevac Marko <[hidden email]> wrote:

> On Tue, Feb 16, 2010 at 10:12 PM,  <[hidden email]> wrote:
> > I have done a lot of c module development. I have found the same problem
> and wound up simply running the module under load while keeping an eye on
> memory usage.
> >
> > Use the pools. They are great and will keep you safe. Any other use of
> memory allocation should be very carefully considered.
> >
>
> Of course I am using pools, but using pools is not panacea, especially
> when non request pool is used :-)
>

I am in agreement with mcqueenorama.  I have not done a ton of module
programming, but what I have done is HEAVILY used by my app and core to the
whole thing.  My best advise is don't use the pools other then the request
pool unless you REALLY need to, even when the module is initializing there
is a temp pool which Apache clears after initialization.

I did run into a memory leak once that I found by simply checking all the
pool usages, it turned out I was using a server pool rather then a request
pool.

I NEVER use anything other then a pool for memory allocation.  The only
exception is 3rd party lib's that allocate memory, such as my usage of
SQLite, which I am sure allocates lots of memory, but I rely on it to clean
up that memory, assuming I manage the resource correctly.  To date, all runs
well!

Sam
Reply | Threaded
Open this post in threaded view
|

Re: Finding memory leaks in httpd and httpd modules

Kevac Marko-2
On Wed, Feb 17, 2010 at 12:49 AM, Sam Carleton <[hidden email]> wrote:
> I am in agreement with mcqueenorama.  I have not done a ton of module
> programming, but what I have done is HEAVILY used by my app and core to the
> whole thing.  My best advise is don't use the pools other then the request
> pool unless you REALLY need to, even when the module is initializing there
> is a temp pool which Apache clears after initialization.

Thank you.
Yes, I really need to use pools that live longer than request and
sometimes I make mistakes which are causing leaks.
Using --enable-pool-debug=all is probably best advice by now. I will
try that shortly.

> I did run into a memory leak once that I found by simply checking all the
> pool usages, it turned out I was using a server pool rather then a request
> pool.

Something that automatizes that checking is what I am looking for :-)

> I NEVER use anything other then a pool for memory allocation.  The only
> exception is 3rd party lib's that allocate memory, such as my usage of
> SQLite, which I am sure allocates lots of memory, but I rely on it to clean
> up that memory, assuming I manage the resource correctly.  To date, all runs
> well!

I am using such libraries too. libmemcached for example.
Registering free() function to exec when some pool will be cleaned is
very useful apr lib feature.

--
Marko Kevac
Sent from Moscow, Mow, Russia