Commit 1a3215aa authored by Ryan Bloom's avatar Ryan Bloom
Browse files

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
parent 78953a77
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+13 −2
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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);
+16 −5
Original line number Diff line number Diff line
@@ -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,19 +340,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 (ap_scoreboard_image == NULL) {
    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, cleanup_shared_mem, apr_null_cleanup);