From 7f346368c7c3eeaf295c1194dbc0b7ab7be1c1c8 Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Mon, 14 Sep 2009 19:46:36 +0000 Subject: [PATCH] * Lower memory usage by reusing the brigade instead of constantly recerating one. Submitted by: Stefan Fritsch Reviewed by: rpluem git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@814807 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ include/ap_mmn.h | 4 +++- include/httpd.h | 1 + server/core_filters.c | 10 ++++++++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 3762ea7d13..854d4af323 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.3.3 + *) core: Lower memory usage of core output filter. + [Stefan Fritsch ] + *) mod_mime: Detect invalid use of MultiviewsMatch inside Location and LocationMatch sections. PR47754. [Dan Poirier] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index e23b71a4a7..5a655e460d 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -194,6 +194,8 @@ * ap_my_generation, etc. ap_mpm_query() can't be called * until after the register-hooks phase. * 20090401.1 (2.3.3-dev) Protected log.c internals, http_log.h changes + * 20090401.2 (2.3.3-dev) Added tmp_flush_bb to core_output_filter_ctx_t + * */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ @@ -201,7 +203,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20090401 #endif -#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/httpd.h b/include/httpd.h index a7a7025ca8..cd47b11132 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -1241,6 +1241,7 @@ typedef struct core_output_filter_ctx { apr_bucket_brigade *buffered_bb; apr_size_t bytes_in; apr_size_t bytes_written; + apr_bucket_brigade *tmp_flush_bb; } core_output_filter_ctx_t; typedef struct core_filter_ctx { diff --git a/server/core_filters.c b/server/core_filters.c index d9b6eb00ba..9a54d42b06 100644 --- a/server/core_filters.c +++ b/server/core_filters.c @@ -396,6 +396,12 @@ apr_status_t ap_core_output_filter(ap_filter_t *f, apr_bucket_brigade *new_bb) if (rv != APR_SUCCESS) { return rv; } + /* + * Need to create tmp brigade with correct lifetime. Passing + * NULL to apr_brigade_split_ex would result in a brigade + * allocated from bb->pool which might be wrong. + */ + ctx->tmp_flush_bb = apr_brigade_create(c->pool, c->bucket_alloc); } if (new_bb != NULL) { @@ -468,7 +474,7 @@ apr_status_t ap_core_output_filter(ap_filter_t *f, apr_bucket_brigade *new_bb) bucket = next) { next = APR_BUCKET_NEXT(bucket); if (APR_BUCKET_IS_FLUSH(bucket)) { - apr_bucket_brigade *remainder = apr_brigade_split(bb, next); + ctx->tmp_flush_bb = apr_brigade_split_ex(bb, next, ctx->tmp_flush_bb); apr_status_t rv = send_brigade_blocking(net->client_socket, bb, &(ctx->bytes_written), c); if (rv != APR_SUCCESS) { @@ -476,7 +482,7 @@ apr_status_t ap_core_output_filter(ap_filter_t *f, apr_bucket_brigade *new_bb) c->aborted = 1; return rv; } - bb = remainder; + APR_BRIGADE_CONCAT(bb, ctx->tmp_flush_bb); next = APR_BRIGADE_FIRST(bb); bytes_in_brigade = 0; non_file_bytes_in_brigade = 0; -- 2.40.0