nginx module memory problem

chen cw crk_world at yahoo.com.cn
Tue Oct 9 03:00:49 UTC 2012


It is suspicious that your problem is caused by ngx_pcalloc().

When you allocated a large size of memory, nginx does not allocate it in
pool, instead, it uses standard malloc() in C, because the size is larger
than the pool size. When a block is allocated by malloc(), it may not be
returned to OS even if it has been freed by free(). Why? GCC memory
management layer can cache the blocks in process for future allocation.

I don't understand why you must copy the input chain of client. In fact, if
you can reap the buffers-chain together, you can directly write each part
into log file separately. Moreover, first create a hole in file, then fill
the log into a hole will get rid of interlace among different log records.

On Fri, Oct 5, 2012 at 12:20 AM, Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Thu, Oct 04, 2012 at 02:13:17PM +0900, 김영진 wrote:
>
> > hi, i am web server(nginx) module developer.
> > my nginx modules has a major problem.
> > maybe... this problem is seem to nginx core bug.
> > i hope this is my module problem. Because, i wish the problem to be
> settled
> > soon.
> >
> > *my module function:*
> > large post data logging from specified file(nginx.conf setting :
> > /home1/test_access.log)
> > *problem:*
> > constant use of memory(nginx-1.2.2 , same situation)
> > [image: 본문 이미지 1]
>
> [...]
>
> > rc_post = ngx_http_read_client_request_body(r,
> > ngx_testmodule_post_read_request_body);
> >
> > ngx_testmodule_resheader(r);
> > ...
> > return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_text_type, &cv);
> > }
> >
> >
> > i have tested my nginx module. but... i don't know.. difficult problem..
> > i am turning to you for help.
>
> One obvious problem in your code is that you use
> ngx_http_read_client_request_body() incorrectly.
>
> After a call to ngx_http_read_client_request_body() you _must_
> follow the pattern
>
>     rc = ngx_http_read_client_request_body(r, ...);
>
>     if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
>         return rc;
>     }
>
>     return NGX_DONE;
>
> See e.g. ngx_http_proxy_module.c for an example.  Failing to do so
> will likely result in request hangs/socket leaks.
>
> --
> Maxim Dounin
> http://nginx.com/support.html
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>



-- 

--

Charles Chen

Software Engineer

Server Platforms Team at Taobao.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20121009/f8a55427/attachment.html>


More information about the nginx-devel mailing list