]> git.kaiwu.me - nginx.git/commitdiff
directio_alignment
authorIgor Sysoev <igor@sysoev.ru>
Fri, 28 Aug 2009 08:15:55 +0000 (08:15 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 28 Aug 2009 08:15:55 +0000 (08:15 +0000)
src/core/ngx_buf.h
src/core/ngx_output_chain.c
src/http/ngx_http_copy_filter_module.c
src/http/ngx_http_core_module.c
src/http/ngx_http_core_module.h
src/http/ngx_http_upstream.c

index b455270adbc0093f28d398ac1e4edfee5c5e0d0c..ba48544895cc905398bb7c54b7fe01c60bc88fac 100644 (file)
@@ -90,6 +90,8 @@ struct ngx_output_chain_ctx_s {
     unsigned                     need_in_memory:1;
     unsigned                     need_in_temp:1;
 
+    off_t                        alignment;
+
     ngx_pool_t                  *pool;
     ngx_int_t                    allocated;
     ngx_bufs_t                   bufs;
index 99e0a9434f3b67757d75bb059effeb8f0f9f31e0..592f14aaff0fe108754ac90dcc99f2897c190e87 100644 (file)
 /*
  * When DIRECTIO is enabled FreeBSD, Solaris, and MacOSX read directly
  * to an application memory from a device if parameters are aligned
- * to device sector boundary(512 bytes).  They fallback to usual read
+ * to device sector boundary (512 bytes).  They fallback to usual read
  * operation if the parameters are not aligned.
  * Linux allows DIRECTIO only if the parameters are aligned to a filesystem
  * sector boundary, otherwise it returns EINVAL.  The sector size is
  * usually 512 bytes, however, on XFS it may be 4096 bytes.
  */
-#define NGX_DIRECTIO_BLOCK  4096
-
 
 #define NGX_NONE            1
 
@@ -337,7 +335,7 @@ ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx, off_t bsize)
 
     ctx->directio = 1;
 
-    size = (size_t) (in->file_pos - (in->file_pos & ~(NGX_DIRECTIO_BLOCK - 1)));
+    size = (size_t) (in->file_pos - (in->file_pos & ~(ctx->alignment - 1)));
 
     if (size == 0) {
 
@@ -348,7 +346,7 @@ ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx, off_t bsize)
         size = (size_t) bsize;
 
     } else {
-        size = NGX_DIRECTIO_BLOCK - size;
+        size = ctx->alignment - size;
 
         if ((off_t) size > bsize) {
             size = (size_t) bsize;
@@ -423,7 +421,7 @@ ngx_output_chain_get_buf(ngx_output_chain_ctx_t *ctx, off_t bsize)
          * userland buffer direct usage conjunctly with directio
          */
 
-        b->start = ngx_pmemalign(ctx->pool, size, NGX_DIRECTIO_BLOCK);
+        b->start = ngx_pmemalign(ctx->pool, size, ctx->alignment);
         if (b->start == NULL) {
             return NGX_ERROR;
         }
index 411e731f339cc12cb607ee7e245d05b76852058f..5587ba447b014cd638b5247bda77f34d8d3e5344 100644 (file)
@@ -94,8 +94,6 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
     ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module);
 
     if (ctx == NULL) {
-        conf = ngx_http_get_module_loc_conf(r, ngx_http_copy_filter_module);
-
         ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
         if (ctx == NULL) {
             return NGX_ERROR;
@@ -103,11 +101,16 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
 
         ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module);
 
+        conf = ngx_http_get_module_loc_conf(r, ngx_http_copy_filter_module);
+        clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
         ctx->sendfile = c->sendfile;
         ctx->need_in_memory = r->main_filter_need_in_memory
                               || r->filter_need_in_memory;
         ctx->need_in_temp = r->filter_need_temporary;
 
+        ctx->alignment = clcf->directio_alignment;
+
         ctx->pool = r->pool;
         ctx->bufs = conf->bufs;
         ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module;
@@ -116,7 +119,6 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
         ctx->filter_ctx = r;
 
 #if (NGX_HAVE_FILE_AIO)
-        clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
         if (clcf->aio) {
             ctx->aio = ngx_http_copy_aio_handler;
         }
index da91ee66abd5a11b90e2d253fcce9d2e3421de26..b9eb0608c00ab6ccbdcfd6b22a1fcaef989de0ae 100644 (file)
@@ -401,6 +401,13 @@ static ngx_command_t  ngx_http_core_commands[] = {
       0,
       NULL },
 
+    { ngx_string("directio_alignment"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_off_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_core_loc_conf_t, directio_alignment),
+      NULL },
+
     { ngx_string("tcp_nopush"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
       ngx_conf_set_flag_slot,
@@ -2931,6 +2938,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
     lcf->aio = NGX_CONF_UNSET;
 #endif
     lcf->directio = NGX_CONF_UNSET;
+    lcf->directio_alignment = NGX_CONF_UNSET;
     lcf->tcp_nopush = NGX_CONF_UNSET;
     lcf->tcp_nodelay = NGX_CONF_UNSET;
     lcf->send_timeout = NGX_CONF_UNSET_MSEC;
@@ -3132,6 +3140,8 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
 #endif
     ngx_conf_merge_off_value(conf->directio, prev->directio,
                               NGX_MAX_OFF_T_VALUE);
+    ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment,
+                              512);
     ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);
     ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1);
 
index 522509b411af86759185ef0a8778e63c68247a99..826b403d66193422aaeca7b7624ac38c65149b51 100644 (file)
@@ -319,6 +319,7 @@ struct ngx_http_core_loc_conf_s {
 
     off_t         client_max_body_size;    /* client_max_body_size */
     off_t         directio;                /* directio */
+    off_t         directio_alignment;      /* directio_alignment */
 
     size_t        client_body_buffer_size; /* client_body_buffer_size */
     size_t        send_lowat;              /* send_lowat */
index a864fb16d07cdac306107a0268e3cc400d4ca95e..11a2cc6d4d721b129b0ba9c13c4e27da2fc01d50 100644 (file)
@@ -474,6 +474,7 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
 
     clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
+    u->output.alignment = clcf->directio_alignment;
     u->output.pool = r->pool;
     u->output.bufs.num = 1;
     u->output.bufs.size = clcf->client_body_buffer_size;