]> git.kaiwu.me - nginx.git/commitdiff
API change: ngx_chain_update_chains() now requires pool.
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 15 Sep 2011 16:03:17 +0000 (16:03 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 15 Sep 2011 16:03:17 +0000 (16:03 +0000)
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.

src/core/ngx_buf.c
src/core/ngx_buf.h
src/core/ngx_output_chain.c
src/event/ngx_event_pipe.c
src/http/modules/ngx_http_chunked_filter_module.c
src/http/modules/ngx_http_gzip_filter_module.c
src/http/ngx_http_upstream.c

index 2f2c4372185d0f549ef5254be4418491777589fa..53cd50cea02514132d8ecec6ed1f980d90f4cb61 100644 (file)
@@ -180,7 +180,7 @@ 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_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 **free, ngx_chain_t **busy,
     *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;
index 847eaad05d6654a3a0d705dfe4a8de6ba51ae94c..a6bf39ff3e08be85d08883ad685191ea969468a0 100644 (file)
@@ -154,8 +154,8 @@ ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in);
 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_ */
index 4f100a81837ec1370101de4748b2eb848f887ec4..e45f0342d358b4858586c3b2830c240449181a25 100644 (file)
@@ -208,7 +208,8 @@ ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)
             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;
     }
 }
index 53d738f0a81eaa7de4a5c24b2b02aaefc331ead3..6f068fe8accd74d6855c294c3731f95c4304b0d7 100644 (file)
@@ -638,7 +638,7 @@ ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
             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) {
 
index ee152288c893c63a07d2e8479e7670c8a7c24a62..e42f3b526f220c35d6dc6d1abf72413d16b7e1c7 100644 (file)
@@ -221,7 +221,7 @@ ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 
     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;
index d624e36ff84534b9431f7306c156d2151544db5d..18824059adf831ceaf2a17f7fc81b26035f3175f 100644 (file)
@@ -378,7 +378,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 
         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_request_t *r, ngx_chain_t *in)
 
         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;
 
index 29432dc14a3985d2d9e9aefa87082a2bff337cfc..f698833af7a3d14054fa5c0056a544e7b0cf7743 100644 (file)
@@ -2382,7 +2382,7 @@ ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *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);
             }