diff options
| author | Valentin Bartenev <vbart@nginx.com> | 2015-02-11 17:52:15 +0300 |
|---|---|---|
| committer | Valentin Bartenev <vbart@nginx.com> | 2015-02-11 17:52:15 +0300 |
| commit | 2b8d6ad805a0132844cfbc1cf1c6988dfe8c9973 (patch) | |
| tree | 0cfe79e6cd5bd968c04ec176383c1fd0efc86757 /src/core | |
| parent | 2b7e167dbb59a6d1152c644080e21782b8b675e3 (diff) | |
| download | nginx-2b8d6ad805a0132844cfbc1cf1c6988dfe8c9973.tar.gz nginx-2b8d6ad805a0132844cfbc1cf1c6988dfe8c9973.tar.bz2 | |
Refactored sendfile() AIO preload.
This reduces layering violation and simplifies the logic of AIO preread, since
it's now triggered by the send chain function itself without falling back to
the copy filter. The context of AIO operation is now stored per file buffer,
which makes it possible to properly handle cases when multiple buffers come
from different locations, each with its own configuration.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/ngx_buf.h | 3 | ||||
| -rw-r--r-- | src/core/ngx_connection.h | 2 | ||||
| -rw-r--r-- | src/core/ngx_output_chain.c | 32 |
3 files changed, 35 insertions, 2 deletions
diff --git a/src/core/ngx_buf.h b/src/core/ngx_buf.h index 13536a69a..219894ffc 100644 --- a/src/core/ngx_buf.h +++ b/src/core/ngx_buf.h @@ -94,6 +94,9 @@ struct ngx_output_chain_ctx_s { unsigned aio:1; ngx_output_chain_aio_pt aio_handler; +#if (NGX_HAVE_FILE_AIO) + ssize_t (*aio_preload)(ngx_buf_t *file); +#endif #endif off_t alignment; diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index ed14e6023..143cab7b3 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -181,9 +181,7 @@ struct ngx_connection_s { #endif #if (NGX_HAVE_AIO_SENDFILE) - unsigned aio_sendfile:1; unsigned busy_count:2; - ngx_buf_t *busy_sendfile; #endif #if (NGX_THREADS) diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c index 9d7a8460f..ca390e254 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -29,6 +29,10 @@ static ngx_inline ngx_int_t ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf); +#if (NGX_HAVE_AIO_SENDFILE) +static ngx_int_t ngx_output_chain_aio_setup(ngx_output_chain_ctx_t *ctx, + ngx_file_t *file); +#endif static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in); static ngx_int_t ngx_output_chain_align_file_buf(ngx_output_chain_ctx_t *ctx, @@ -252,6 +256,12 @@ ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf) buf->in_file = 0; } +#if (NGX_HAVE_AIO_SENDFILE) + if (ctx->aio_preload && buf->in_file) { + (void) ngx_output_chain_aio_setup(ctx, buf->file); + } +#endif + if (ctx->need_in_memory && !ngx_buf_in_memory(buf)) { return 0; } @@ -264,6 +274,28 @@ ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf) } +#if (NGX_HAVE_AIO_SENDFILE) + +static ngx_int_t +ngx_output_chain_aio_setup(ngx_output_chain_ctx_t *ctx, ngx_file_t *file) +{ + ngx_event_aio_t *aio; + + if (file->aio == NULL && ngx_file_aio_init(file, ctx->pool) != NGX_OK) { + return NGX_ERROR; + } + + aio = file->aio; + + aio->data = ctx->filter_ctx; + aio->preload_handler = ctx->aio_preload; + + return NGX_OK; +} + +#endif + + static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in) |
