From d74c4014ccbe2f99cbeef689d193b0ce4a381b55 Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Sat, 11 May 2002 23:24:29 +0000 Subject: [PATCH] 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 --- CHANGES | 4 ++++ include/http_core.h | 9 +++++++++ server/core.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/CHANGES b/CHANGES index d6beba0950..3f3cc97c18 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ 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] diff --git a/include/http_core.h b/include/http_core.h index 7bc555582e..63a5cfe36e 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -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 */ diff --git a/server/core.c b/server/core.c index ff60706c2f..776420b706 100644 --- a/server/core.c +++ b/server/core.c @@ -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); -- 2.50.1