From: Sander Striker Date: Thu, 4 Jul 2002 15:20:54 +0000 (+0000) Subject: Add a new directive: MaxMemFree. MaxMemFree makes it possible X-Git-Tag: 2.0.40~320 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62faca71e775e4b06c78946fd035bc7bc705bfe6;p=thirdparty%2Fapache%2Fhttpd.git Add a new directive: MaxMemFree. MaxMemFree makes it possible to configure the maximum amount of memory the allocators will hold on to for reuse. Anything over the MaxMemFree threshold will be free()d. This directive is usefull when uncommon large peaks occur in memory usage. It should _not_ be used to mask defective modules' memory use. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@95954 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index bbd634304c8..4248b56dc40 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,10 @@ Changes with Apache 2.0.40 + *) Add a new directive: MaxMemFree. MaxMemFree makes it possible + to configure the maximum amount of memory the allocators will + hold on to for reuse. Anything over the MaxMemFree threshold + will be free()d. This directive is usefull when uncommon large + peaks occur in memory usage. It should _not_ be used to mask + defective modules' memory use. [Sander Striker] *) Fixed the Content-Length filter so that HTTP/1.0 requests to CGI scripts would not result in a truncated response. diff --git a/server/core.c b/server/core.c index c2f23aeb5a3..c223220246b 100644 --- a/server/core.c +++ b/server/core.c @@ -3043,6 +3043,10 @@ AP_INIT_TAKE1("CoreDumpDirectory", ap_mpm_set_coredumpdir, NULL, RSRC_CONF, \ AP_INIT_TAKE1("AcceptMutex", ap_mpm_set_accept_lock_mech, NULL, RSRC_CONF, \ ap_valid_accept_mutex_string), #endif +#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE +AP_INIT_TAKE1("MaxMemFree", ap_mpm_set_max_mem_free, NULL, RSRC_CONF,\ + "Maximum number of 1k blocks a particular childs allocator may hold."), +#endif { NULL } }; diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index bf4807ebb65..3aaa1e3859d 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -383,6 +383,7 @@ static int32 worker_thread(void * dummy) sigprocmask(SIG_BLOCK, &sig_mask, NULL); apr_allocator_create(&allocator); + apr_allocator_max_free_set(allocator, ap_max_mem_free); apr_pool_create_ex(&ptrans, tpool, NULL, allocator); apr_allocator_owner_set(allocator, ptrans); diff --git a/server/mpm/beos/mpm.h b/server/mpm/beos/mpm.h index 37f1b22055c..cb84cf3f277 100644 --- a/server/mpm/beos/mpm.h +++ b/server/mpm/beos/mpm.h @@ -73,6 +73,7 @@ #define AP_MPM_WANT_SET_SCOREBOARD #define AP_MPM_WANT_SET_MAX_REQUESTS #define AP_MPM_WANT_SET_COREDUMPDIR +#define AP_MPM_WANT_SET_MAX_MEM_FREE extern int ap_max_child_assigned; extern server_rec *ap_server_conf; diff --git a/server/mpm/experimental/leader/leader.c b/server/mpm/experimental/leader/leader.c index 661b0fce667..02d55a1204c 100644 --- a/server/mpm/experimental/leader/leader.c +++ b/server/mpm/experimental/leader/leader.c @@ -821,6 +821,7 @@ static void *worker_thread(apr_thread_t *thd, void * dummy) free(ti); apr_allocator_create(&allocator); + apr_allocator_max_free_set(allocator, ap_max_mem_free); apr_pool_create_ex(&ptrans, NULL, NULL, allocator); apr_allocator_owner_set(allocator, ptrans); bucket_alloc = apr_bucket_alloc_create(tpool); diff --git a/server/mpm/experimental/leader/mpm.h b/server/mpm/experimental/leader/mpm.h index 5e7afa8fde8..6214e4509da 100644 --- a/server/mpm/experimental/leader/mpm.h +++ b/server/mpm/experimental/leader/mpm.h @@ -74,6 +74,7 @@ #define AP_MPM_WANT_SET_MAX_REQUESTS #define AP_MPM_WANT_SET_COREDUMPDIR #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH +#define AP_MPM_WANT_SET_MAX_MEM_FREE #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK #define AP_MPM_USES_POD 1 diff --git a/server/mpm/experimental/threadpool/mpm.h b/server/mpm/experimental/threadpool/mpm.h index f94288d90ab..68adde9b176 100644 --- a/server/mpm/experimental/threadpool/mpm.h +++ b/server/mpm/experimental/threadpool/mpm.h @@ -75,6 +75,7 @@ #define AP_MPM_WANT_SET_COREDUMPDIR #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH #define AP_MPM_WANT_SIGNAL_SERVER +#define AP_MPM_WANT_SET_MAX_MEM_FREE #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid) diff --git a/server/mpm/experimental/threadpool/threadpool.c b/server/mpm/experimental/threadpool/threadpool.c index dffd4634f9a..79e18ec4142 100644 --- a/server/mpm/experimental/threadpool/threadpool.c +++ b/server/mpm/experimental/threadpool/threadpool.c @@ -1045,6 +1045,7 @@ static void * APR_THREAD_FUNC worker_thread(apr_thread_t *thd, void * dummy) ap_update_child_status_from_indexes(process_slot, thread_slot, SERVER_STARTING, NULL); apr_allocator_create(&allocator); + apr_allocator_max_free_set(allocator, ap_max_mem_free); apr_pool_create_ex(&ptrans, NULL, NULL, allocator); apr_allocator_owner_set(allocator, ptrans); diff --git a/server/mpm/netware/mpm.h b/server/mpm/netware/mpm.h index 74a5f55194b..f53125944b8 100644 --- a/server/mpm/netware/mpm.h +++ b/server/mpm/netware/mpm.h @@ -72,6 +72,7 @@ #define AP_MPM_WANT_SET_LOCKFILE */ #define AP_MPM_WANT_SET_MAX_REQUESTS +#define AP_MPM_WANT_SET_MAX_MEM_FREE #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK /*#define AP_MPM_WANT_SET_COREDUMPDIR #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH diff --git a/server/mpm/netware/mpm_netware.c b/server/mpm/netware/mpm_netware.c index 621d470963e..59abe965172 100644 --- a/server/mpm/netware/mpm_netware.c +++ b/server/mpm/netware/mpm_netware.c @@ -373,6 +373,7 @@ void worker_main(void *arg) tv.tv_usec = 0; apr_allocator_create(&allocator); + apr_allocator_max_free_set(allocator, ap_max_mem_free); apr_pool_create_ex(&ptrans, NULL, NULL, allocator); apr_allocator_owner_set(allocator, ptrans); apr_pool_tag(ptrans, "transaction"); diff --git a/server/mpm/prefork/mpm.h b/server/mpm/prefork/mpm.h index fc2ff771c51..0c14b0c8e57 100644 --- a/server/mpm/prefork/mpm.h +++ b/server/mpm/prefork/mpm.h @@ -78,6 +78,7 @@ #define AP_MPM_WANT_SET_COREDUMPDIR #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH #define AP_MPM_WANT_SIGNAL_SERVER +#define AP_MPM_WANT_SET_MAX_MEM_FREE #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK #define AP_MPM_USES_POD 1 diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 3d13b13638c..ec12fd83768 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -558,6 +558,7 @@ static void child_main(int child_num_arg) * we can have cleanups occur when the child exits. */ apr_allocator_create(&allocator); + apr_allocator_max_free_set(allocator, ap_max_mem_free); apr_pool_create_ex(&pchild, pconf, NULL, allocator); apr_allocator_owner_set(allocator, pchild); diff --git a/server/mpm/worker/mpm.h b/server/mpm/worker/mpm.h index a22c8f0686e..1c34a10feb2 100644 --- a/server/mpm/worker/mpm.h +++ b/server/mpm/worker/mpm.h @@ -75,6 +75,7 @@ #define AP_MPM_WANT_SET_COREDUMPDIR #define AP_MPM_WANT_SET_ACCEPT_LOCK_MECH #define AP_MPM_WANT_SIGNAL_SERVER +#define AP_MPM_WANT_SET_MAX_MEM_FREE #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid) diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 98820915512..8d8575db7bb 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -796,6 +796,7 @@ static void *listener_thread(apr_thread_t *thd, void * dummy) apr_allocator_t *allocator; apr_allocator_create(&allocator); + apr_allocator_max_free_set(allocator, ap_max_mem_free); apr_pool_create_ex(&ptrans, NULL, NULL, allocator); apr_allocator_owner_set(allocator, ptrans); } diff --git a/server/mpm_common.c b/server/mpm_common.c index 98f482dd63c..ec6485da644 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -880,3 +880,26 @@ void ap_mpm_rewrite_args(process_rec *process) #endif /* AP_MPM_WANT_SIGNAL_SERVER */ +#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE +apr_uint32_t ap_max_mem_free = 0; + +const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy, + const char *arg) +{ + long value; + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + + value = strtol(arg, NULL, 0); + if (value < 0 || errno == ERANGE) + return apr_pstrcat(cmd->pool, "Invalid MaxMemFree value: ", + arg, NULL); + + ap_max_mem_free = (apr_uint32_t)value * 1024; + + return NULL; +} + +#endif /* AP_MPM_WANT_SET_MAX_MEM_FREE */