Welcome! Log In Create A New Profile

Advanced

[PATCH 2 of 2] API change: ngx_chain_update_chains() now requires pool

Maxim Dounin
September 09, 2011 07:10AM
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1315564280 -14400
# Node ID 75a67f1c7e4d8affb16d3f4f029757a8e0d3b455
# Parent b667ed67c0b9046b94291fa6f52e850006011718
API change: ngx_chain_update_chains() now requires pool.

The ngx_chain_update_chains() needs pool to free chain links used for buffers
with non-matching tags. Providing one helps to reduce memory consumption
for long-lived requests.

diff --git a/src/core/ngx_buf.c b/src/core/ngx_buf.c
--- a/src/core/ngx_buf.c
+++ b/src/core/ngx_buf.c
@@ -180,7 +180,7 @@ ngx_chain_get_free_buf(ngx_pool_t *p, ng


void
-ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
+ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, ngx_chain_t **busy,
ngx_chain_t **out, ngx_buf_tag_t tag)
{
ngx_chain_t *cl;
@@ -197,19 +197,21 @@ ngx_chain_update_chains(ngx_chain_t **fr
*out = NULL;

while (*busy) {
- if (ngx_buf_size((*busy)->buf) != 0) {
+ cl = *busy;
+
+ if (ngx_buf_size(cl->buf) != 0) {
break;
}

- if ((*busy)->buf->tag != tag) {
- *busy = (*busy)->next;
+ if (cl->buf->tag != tag) {
+ *busy = cl->next;
+ ngx_free_chain(p, cl);
continue;
}

- (*busy)->buf->pos = (*busy)->buf->start;
- (*busy)->buf->last = (*busy)->buf->start;
+ cl->buf->pos = cl->buf->start;
+ cl->buf->last = cl->buf->start;

- cl = *busy;
*busy = cl->next;
cl->next = *free;
*free = cl;
diff --git a/src/core/ngx_buf.h b/src/core/ngx_buf.h
--- a/src/core/ngx_buf.h
+++ b/src/core/ngx_buf.h
@@ -154,8 +154,8 @@ ngx_int_t ngx_chain_writer(void *ctx, ng
ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
ngx_chain_t *in);
ngx_chain_t *ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free);
-void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
- ngx_chain_t **out, ngx_buf_tag_t tag);
+void ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free,
+ ngx_chain_t **busy, ngx_chain_t **out, ngx_buf_tag_t tag);


#endif /* _NGX_BUF_H_INCLUDED_ */
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -208,7 +208,8 @@ ngx_output_chain(ngx_output_chain_ctx_t
return last;
}

- ngx_chain_update_chains(&ctx->free, &ctx->busy, &out, ctx->tag);
+ ngx_chain_update_chains(ctx->pool, &ctx->free, &ctx->busy, &out,
+ ctx->tag);
last_out = &out;
}
}
diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c
--- a/src/event/ngx_event_pipe.c
+++ b/src/event/ngx_event_pipe.c
@@ -638,7 +638,7 @@ ngx_event_pipe_write_to_downstream(ngx_e
return ngx_event_pipe_drain_chains(p);
}

- ngx_chain_update_chains(&p->free, &p->busy, &out, p->tag);
+ ngx_chain_update_chains(p->pool, &p->free, &p->busy, &out, p->tag);

for (cl = p->free; cl; cl = cl->next) {

diff --git a/src/http/modules/ngx_http_chunked_filter_module.c b/src/http/modules/ngx_http_chunked_filter_module.c
--- a/src/http/modules/ngx_http_chunked_filter_module.c
+++ b/src/http/modules/ngx_http_chunked_filter_module.c
@@ -221,7 +221,7 @@ ngx_http_chunked_body_filter(ngx_http_re

rc = ngx_http_next_body_filter(r, out);

- ngx_chain_update_chains(&ctx->free, &ctx->busy, &out,
+ ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &out,
(ngx_buf_tag_t) &ngx_http_chunked_filter_module);

return rc;
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -378,7 +378,7 @@ ngx_http_gzip_body_filter(ngx_http_reque

cl = NULL;

- ngx_chain_update_chains(&ctx->free, &ctx->busy, &cl,
+ ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &cl,
(ngx_buf_tag_t) &ngx_http_gzip_filter_module);
ctx->nomem = 0;
}
@@ -448,7 +448,7 @@ ngx_http_gzip_body_filter(ngx_http_reque

ngx_http_gzip_filter_free_copy_buf(r, ctx);

- ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out,
+ ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &ctx->out,
(ngx_buf_tag_t) &ngx_http_gzip_filter_module);
ctx->last_out = &ctx->out;

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2382,7 +2382,7 @@ ngx_http_upstream_process_non_buffered_r
return;
}

- ngx_chain_update_chains(&u->free_bufs, &u->busy_bufs,
+ ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs,
&u->out_bufs, u->output.tag);
}


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 0 of 2] reduce memory footprint for long-lived requests

Maxim Dounin 1856 September 09, 2011 07:10AM

[PATCH 1 of 2] Buffers reuse in chunked filter

Maxim Dounin 725 September 09, 2011 07:10AM

Re: [PATCH 1 of 2] Buffers reuse in chunked filter

splitice 958 September 09, 2011 08:02AM

Re: [PATCH 1 of 2] Buffers reuse in chunked filter

Kornél Schadl 728 September 09, 2011 08:38AM

Re: [PATCH 1 of 2] Buffers reuse in chunked filter

Maxim Dounin 908 September 09, 2011 08:44AM

[PATCH 2 of 2] API change: ngx_chain_update_chains() now requires pool

Maxim Dounin 765 September 09, 2011 07:10AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 286
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready