You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Marco Spinetti <m....@pisa.iol.it> on 2005/12/23 08:17:35 UTC

[Fwd: APR_POOL_DEBUG??]

Any advice?
I compiled apr with enable pool debug = verbose.
Now in the error log I have a lot of information.
How can I discover apr memory problems by these information?
Because of apr is so much powerful I suppose that there is some way to 
debug it.....

Thanks

--Marco


-------- Original Message --------
Subject: 	APR_POOL_DEBUG??
Date: 	Thu, 22 Dec 2005 14:49:50 +0100
From: 	Marco Spinetti <m....@pisa.iol.it>
To: 	dev@apr.apache.org



Hi all,
I'm writing a dso 1.3 apache module which uses apr.
Checking my module with a stress test (1440 reqs/min) I'm observing , 
with top, that SIZE and RSS of httpd processes are growing.
So I'm supposing that my module can have some memory allocation leak.
It's strange because I use apr for all my allocation, but it's clear 
that it has some problems.
My system is RHAS 3 on Linux.
I have a global pool which I use for allocating some global structs, and 
then every childs has a pool which at the end they destroy with 
apr_pool_destroy.
How can I debug my apr memory allocation?
I was thinking to start my apache with -X and then I'd like that apr 
writes all informations on stderr (---> error_log of apache).
Any advices?

Cheers

--Marco





Re: apr_pool memory usage (Re: [Fwd: APR_POOL_DEBUG??])

Posted by jacky <nb...@gmail.com>.
INOUE Seiichiro <inoue <at> ariel-networks.com> writes:

> 
> Hi, 
> 
> > Checking my module with a stress test (1440 reqs/min) I'm observing , 
> > with top, that SIZE and RSS of httpd processes are growing.
> 
> I recommend you to check apr_allocator_max_free_set().
> 
> The following sample code shows the effect.
> Without calling apr_allocator_max_free_set(), you can find the memory usage 
is growing rapidly.
> 
> ///////////////// sample code starts
> /* memory pool leak test.
>  *  <at> remark No error checks */
> #include <stdio.h>
> #include <apr_general.h>
> 
> int main(int argc, char **argv)
> {
>     apr_pool_t *mp;
>     int i;
> 	
>     apr_initialize();
>     apr_pool_create(&mp, NULL);
> 
>     /* XXX Without this setting, memory usage is growing more than expected 
*/
> #define MY_POOL_MAX_FREE_SIZE	32
>     {
>         apr_allocator_t *pa = apr_pool_allocator_get(mp);
>         if (pa) {
>             apr_allocator_max_free_set(pa, MY_POOL_MAX_FREE_SIZE);
>         }
>     }
> 
> #define BASE_ALLOC_SIZE    (8*1024)
>     i = 0;
>     while (1) {
>         apr_palloc(mp, BASE_ALLOC_SIZE + i);
>         i++;
>         if (i % 10000 == 0) {
>             puts("press enter key (please check memory usage)");
>             getchar();
>         }
>         apr_pool_clear(mp);
>     }
>     apr_terminate();
>     return 0;
> }
> ///////////////// sample code ends
> 
> - INOUE Seiichiro <inoue <at> ariel-networks.com>
> 
> 
there would be memory leak, it seems that there is no-effect by calling 
apr_allocator_max_free_set.

#define SIZE (10*1024*1024)

apr_pool_t *p;
apr_initialize();
atexit(apr_terminate);

apr_allocator_t *my_allocator_ptr = NULL;
	apr_pool_t *system_pool = NULL;
	if( apr_allocator_create(&my_allocator_ptr) == APR_SUCCESS ){
		printf("created my_allocator_ptr success\n");
		apr_allocator_max_free_set(my_allocator_ptr, SIZE);
		printf("set max free size for my_allocator_ptr to %d\n", SIZE);
	}
	apr_pool_create(&system_pool, NULL);
	apr_pool_create_ex(&p, system_pool, (apr_abortfunc_t)
failed_to_allocate, my_allocator_ptr);
	apr_allocator_owner_set(my_allocator_ptr, p);

	apr_allocator_t *pa = apr_pool_allocator_get(p);
	printf("pa %x my_allocator_ptr %x\n\n", pa, my_allocator_ptr);

	int chunk_size;
	void *ptr = NULL;
	chunk_size = 1024*1024;
	ptr = apr_pcalloc(p, chunk_size);
	for(int i = 1; ptr != NULL; i++){
		ptr = apr_pcalloc(p, chunk_size);
		if( ptr != NULL ){
			printf("pass %3.3d: allocated %d bytes\n", i, 
chunk_size);
		}
		else{
			printf("pass %3.3d: ***failed to allocate %d bytes\n", 
i, chunk_size);
		}
	}




apr_pool memory usage (Re: [Fwd: APR_POOL_DEBUG??])

Posted by INOUE Seiichiro <in...@ariel-networks.com>.
Hi, 

> Checking my module with a stress test (1440 reqs/min) I'm observing , 
> with top, that SIZE and RSS of httpd processes are growing.

I recommend you to check apr_allocator_max_free_set().

The following sample code shows the effect.
Without calling apr_allocator_max_free_set(), you can find the memory usage is growing rapidly.


///////////////// sample code starts
/* memory pool leak test.
 * @remark No error checks */
#include <stdio.h>
#include <apr_general.h>

int main(int argc, char **argv)
{
    apr_pool_t *mp;
    int i;
	
    apr_initialize();
    apr_pool_create(&mp, NULL);

    /* XXX Without this setting, memory usage is growing more than expected */
#define MY_POOL_MAX_FREE_SIZE	32
    {
        apr_allocator_t *pa = apr_pool_allocator_get(mp);
        if (pa) {
            apr_allocator_max_free_set(pa, MY_POOL_MAX_FREE_SIZE);
        }
    }

#define BASE_ALLOC_SIZE    (8*1024)
    i = 0;
    while (1) {
        apr_palloc(mp, BASE_ALLOC_SIZE + i);
        i++;
        if (i % 10000 == 0) {
            puts("press enter key (please check memory usage)");
            getchar();
        }
        apr_pool_clear(mp);
    }
    apr_terminate();
    return 0;
}
///////////////// sample code ends


- INOUE Seiichiro <in...@ariel-networks.com>

Re: [Fwd: APR_POOL_DEBUG??]

Posted by Paul Querna <ch...@force-elite.com>.
Garrett Rooney wrote:
> On 12/22/05, Marco Spinetti <m....@pisa.iol.it> wrote:
>> Any advice?
>> I compiled apr with enable pool debug = verbose.
>> Now in the error log I have a lot of information.
>> How can I discover apr memory problems by these information?
>> Because of apr is so much powerful I suppose that there is some way to
>> debug it.....
> 
> There are some instructions on
> http://subversion.tigris.org/hacking.html#tracing-memory-leaks that
> explain how we've tracked down pool allocation problems in Subversion.
>  Perhaps they'll be helpful for your problem.

I also wrote some scripts to graph them:
http://paul.querna.org/journal/articles/2005/02/23/apr-memory-pools-rock

But, I don't know if they even work anymore.  I wish I had time to make 
them.. better.

-Paul


Re: [Fwd: APR_POOL_DEBUG??]

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 12/22/05, Marco Spinetti <m....@pisa.iol.it> wrote:
> Any advice?
> I compiled apr with enable pool debug = verbose.
> Now in the error log I have a lot of information.
> How can I discover apr memory problems by these information?
> Because of apr is so much powerful I suppose that there is some way to
> debug it.....

There are some instructions on
http://subversion.tigris.org/hacking.html#tracing-memory-leaks that
explain how we've tracked down pool allocation problems in Subversion.
 Perhaps they'll be helpful for your problem.

-garrett