Commit d874c6a2 authored by Brian Pane's avatar Brian Pane
Browse files

Added EnableMMAP directive to allow the server administrator to

prevent mmap of file buckets upon read.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@95040 13f79535-47bb-0310-9956-ffa450edef68
parent a91b4078
Loading
Loading
Loading
Loading
+4 −0
Changes for CHANGES: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
Changes with Apache 2.0.37
  *) Added EnableMMAP config directive to enable the server
     administrator to disable memory-mapping of delivered files
     on a per-directory basis.  [Brian Pane]
  *) Performance enhancements for mod_setenvif  [Brian Pane]
  *) Fix a mod_ssl build problem on OS/390.  [Jeff Trawick]
+9 −0
Changes for include/http_core.h: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -515,6 +515,15 @@ typedef struct {
    etag_components_t etag_bits;
    etag_components_t etag_add;
    etag_components_t etag_remove;

    /*
     * Run-time performance tuning
     */
#define ENABLE_MMAP_OFF    (0)
#define ENABLE_MMAP_ON     (1)
#define ENABLE_MMAP_UNSET  (2)
    int enable_mmap;  /* whether files in this dir can be mmap'ed */

} core_dir_config;

/* Per-server core configuration */
+36 −0
Changes for server/core.c: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -180,6 +180,8 @@ static void *create_core_dir_config(apr_pool_t *a, char *dir)
    conf->etag_add = ETAG_UNSET;
    conf->etag_remove = ETAG_UNSET;

    conf->enable_mmap = ENABLE_MMAP_UNSET;

    return (void *)conf;
}

@@ -441,6 +443,10 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
        conf->etag_bits &= (~ ETAG_NONE);
    }

    if (new->enable_mmap != ENABLE_MMAP_UNSET) {
        conf->enable_mmap = new->enable_mmap;
    }

    return (void*)conf;
}

@@ -1422,6 +1428,29 @@ static const char *set_etag_bits(cmd_parms *cmd, void *mconfig,
    return NULL;
}

static const char *set_enable_mmap(cmd_parms *cmd, void *d_,
                                   const char *arg)
{
    core_dir_config *d = d_;
    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);

    if (err != NULL) {
        return err;
    }

    if (strcasecmp(arg, "on") == 0) {
        d->enable_mmap = ENABLE_MMAP_ON;
    }
    else if (strcasecmp(arg, "off") == 0) {
        d->enable_mmap = ENABLE_MMAP_OFF;
    }
    else {
        return "parameter must be 'on' or 'off'";
    }

    return NULL;
}

static const char *satisfy(cmd_parms *cmd, void *c_, const char *arg)
{
    core_dir_config *c = c_;
@@ -2871,6 +2900,8 @@ AP_INIT_TAKE1("DefaultType", ap_set_string_slot,
  OR_FILEINFO, "the default MIME type for untypable files"),
AP_INIT_RAW_ARGS("FileETag", set_etag_bits, NULL, OR_FILEINFO,
  "Specify components used to construct a file's ETag"),
AP_INIT_TAKE1("EnableMMAP", set_enable_mmap, NULL, OR_FILEINFO,
  "Controls whether memory-mapping may be used to read files"),

/* Old server config file commands */

@@ -3230,6 +3261,11 @@ static int default_handler(request_rec *r)
            e = apr_bucket_file_create(fd, 0, (apr_size_t)r->finfo.size,
                                       r->pool, c->bucket_alloc);

#if APR_HAS_MMAP
        if (d->enable_mmap == ENABLE_MMAP_OFF) {
            (void)apr_bucket_file_enable_mmap(e, 0);
        }
#endif
        APR_BRIGADE_INSERT_TAIL(bb, e);
        e = apr_bucket_eos_create(c->bucket_alloc);
        APR_BRIGADE_INSERT_TAIL(bb, e);