From b7e17bb7995fdd588ff8fec71d05402a40120763 Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Sat, 2 Dec 2000 07:08:12 +0000 Subject: [PATCH] MPMs that require multiple segments of shared memory now just use two shared memory blocks to ensure that all of the memory is available. This removes the hack that added 80 bytes to each shared memory block. We end up needing two apr_shmem_t variables, because it is difficult to determine exactly how much memory will be needed. MM automatically tries to align the shared memory allocations, so we either need to pad the shared memory segments, or just use two different segments. This also changes APR and MM to take into account whatever memory those packages need to allocate when creating a shared memory segment. Any memory that APR and MM need is automatically added to the size requested by the program. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87153 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/dexter/scoreboard.c | 2 +- server/mpm/mpmt_pthread/scoreboard.c | 15 +++++++++++++-- server/mpm/perchild/scoreboard.c | 2 +- server/mpm/prefork/prefork.c | 21 ++++++++++++++++----- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/server/mpm/dexter/scoreboard.c b/server/mpm/dexter/scoreboard.c index d640741684..3bf4869a64 100644 --- a/server/mpm/dexter/scoreboard.c +++ b/server/mpm/dexter/scoreboard.c @@ -102,7 +102,7 @@ static void setup_shared_mem(apr_pool_t *p) const char *fname; fname = ap_server_root_relative(p, ap_scoreboard_fname); - if (apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE + 80, fname, p) != APR_SUCCESS) { + if (apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p) != APR_SUCCESS) { apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard", ap_server_argv0); perror(buf); diff --git a/server/mpm/mpmt_pthread/scoreboard.c b/server/mpm/mpmt_pthread/scoreboard.c index 9692d9bc66..a2c1905049 100644 --- a/server/mpm/mpmt_pthread/scoreboard.c +++ b/server/mpm/mpmt_pthread/scoreboard.c @@ -89,12 +89,16 @@ static int maintain_connection_status = 1; #include "apr_shmem.h" static apr_shmem_t *scoreboard_shm = NULL; +static apr_shmem_t *status_shm = NULL; apr_status_t ap_cleanup_shared_mem(void *d) { apr_shm_free(scoreboard_shm, ap_scoreboard_image); + apr_shm_free(status_shm, ap_new_scoreboard_image); ap_scoreboard_image = NULL; + ap_new_scoreboard_image = NULL; apr_shm_destroy(scoreboard_shm); + apr_shm_destroy(status_shm); return APR_SUCCESS; } @@ -105,19 +109,26 @@ static void setup_shared_mem(apr_pool_t *p) const char *fname; fname = ap_server_root_relative(p, ap_scoreboard_fname); - if (apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE + NEW_SCOREBOARD_SIZE + 80, fname, p) != APR_SUCCESS) { + if (apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p) != APR_SUCCESS) { apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard", ap_server_argv0); perror(buf); exit(APEXIT_INIT); } ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE); - ap_new_scoreboard_image = apr_shm_malloc(scoreboard_shm, NEW_SCOREBOARD_SIZE); + if (apr_shm_init(&status_shm, NEW_SCOREBOARD_SIZE, fname, p) != APR_SUCCESS) { + apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard", + ap_server_argv0); + perror(buf); + exit(APEXIT_INIT); + } + ap_new_scoreboard_image = apr_shm_malloc(status_shm, NEW_SCOREBOARD_SIZE); if (ap_scoreboard_image == NULL || ap_new_scoreboard_image == NULL) { apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard", ap_server_argv0); perror(buf); apr_shm_destroy(scoreboard_shm); + apr_shm_destroy(status_shm); exit(APEXIT_INIT); } apr_register_cleanup(p, NULL, ap_cleanup_shared_mem, apr_null_cleanup); diff --git a/server/mpm/perchild/scoreboard.c b/server/mpm/perchild/scoreboard.c index a956eda0e6..10b0730ad4 100644 --- a/server/mpm/perchild/scoreboard.c +++ b/server/mpm/perchild/scoreboard.c @@ -102,7 +102,7 @@ static void setup_shared_mem(apr_pool_t *p) const char *fname; fname = ap_server_root_relative(p, ap_scoreboard_fname); - if (apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE + 80, fname, p) != APR_SUCCESS) { + if (apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p) != APR_SUCCESS) { apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard", ap_server_argv0); perror(buf); diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 0ee89c94f1..2e92927ab7 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -321,12 +321,16 @@ static void accept_mutex_off(void) #include "apr_shmem.h" static apr_shmem_t *scoreboard_shm = NULL; +static apr_shmem_t *status_shm = NULL; static apr_status_t cleanup_shared_mem(void *d) { apr_shm_free(scoreboard_shm, ap_scoreboard_image); + apr_shm_free(status_shm, ap_new_scoreboard_image); ap_scoreboard_image = NULL; + ap_new_scoreboard_image = NULL; apr_shm_destroy(scoreboard_shm); + apr_shm_destroy(status_shm); return APR_SUCCESS; } @@ -336,21 +340,28 @@ static void setup_shared_mem(apr_pool_t *p) const char *fname; fname = ap_server_root_relative(p, ap_scoreboard_fname); - if (apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE + NEW_SCOREBOARD_SIZE + 80, fname, p) != APR_SUCCESS) { + if (apr_shm_init(&scoreboard_shm, SCOREBOARD_SIZE, fname, p) != APR_SUCCESS) { apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard", ap_server_argv0); perror(buf); exit(APEXIT_INIT); } ap_scoreboard_image = apr_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE); - ap_new_scoreboard_image = apr_shm_malloc(scoreboard_shm, NEW_SCOREBOARD_SIZE); - if (ap_scoreboard_image == NULL) { - apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard", + if (apr_shm_init(&status_shm, NEW_SCOREBOARD_SIZE, fname, p) != APR_SUCCESS) { + apr_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard", ap_server_argv0); perror(buf); - apr_shm_destroy(scoreboard_shm); exit(APEXIT_INIT); } + ap_new_scoreboard_image = apr_shm_malloc(status_shm, NEW_SCOREBOARD_SIZE); + if (ap_scoreboard_image == NULL || ap_new_scoreboard_image == NULL) { + apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard", + ap_server_argv0); + perror(buf); + apr_shm_destroy(scoreboard_shm); + apr_shm_destroy(status_shm); + exit(APEXIT_INIT); + } apr_register_cleanup(p, NULL, cleanup_shared_mem, apr_null_cleanup); ap_scoreboard_image->global.running_generation = 0; } -- 2.40.0