summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2021-12-27 19:49:26 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2021-12-27 19:49:26 +0300
commit1f01183b9e6658749934313fd72f7f16c1918b54 (patch)
tree70456837095468405c238636c3e1aa1e63373110
parent2a00e6141f154d77a835e53b6527a1b3225f6f74 (diff)
Support for sendfile(SF_NOCACHE).
The SF_NOCACHE flag, introduced in FreeBSD 11 along with the new non-blocking sendfile() implementation by glebius@, makes it possible to use sendfile() along with the "directio" directive.
-rw-r--r--src/core/ngx_output_chain.c17
-rw-r--r--src/event/ngx_event_openssl.c6
-rw-r--r--src/os/unix/ngx_freebsd_sendfile_chain.c6
3 files changed, 25 insertions, 4 deletions
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index 41267eeff..857074253 100644
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -256,10 +256,6 @@ ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf)
}
#endif
- if (buf->in_file && buf->file->directio) {
- return 0;
- }
-
sendfile = ctx->sendfile;
#if (NGX_SENDFILE_LIMIT)
@@ -270,6 +266,19 @@ ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf)
#endif
+#if !(NGX_HAVE_SENDFILE_NODISKIO)
+
+ /*
+ * With DIRECTIO, disable sendfile() unless sendfile(SF_NOCACHE)
+ * is available.
+ */
+
+ if (buf->in_file && buf->file->directio) {
+ sendfile = 0;
+ }
+
+#endif
+
if (!sendfile) {
if (!ngx_buf_in_memory(buf)) {
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
index 57e2d44ca..33977af61 100644
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -2955,7 +2955,13 @@ ngx_ssl_sendfile(ngx_connection_t *c, ngx_buf_t *file, size_t size)
ngx_set_errno(0);
#if (NGX_HAVE_SENDFILE_NODISKIO)
+
flags = (c->busy_count <= 2) ? SF_NODISKIO : 0;
+
+ if (file->file->directio) {
+ flags |= SF_NOCACHE;
+ }
+
#else
flags = 0;
#endif
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index c939f6ad6..5c6a830d8 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -174,7 +174,13 @@ ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
sent = 0;
#if (NGX_HAVE_SENDFILE_NODISKIO)
+
flags = (c->busy_count <= 2) ? SF_NODISKIO : 0;
+
+ if (file->file->directio) {
+ flags |= SF_NOCACHE;
+ }
+
#endif
rc = sendfile(file->file->fd, c->fd, file->file_pos,