]> git.kaiwu.me - nginx.git/commitdiff
Support for sendfile(SF_NOCACHE).
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 27 Dec 2021 16:49:26 +0000 (19:49 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 27 Dec 2021 16:49:26 +0000 (19:49 +0300)
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.

src/core/ngx_output_chain.c
src/event/ngx_event_openssl.c
src/os/unix/ngx_freebsd_sendfile_chain.c

index 41267eefff2bd7d3ee1c82696a81027455a805bb..857074253977970b89e6288dcf974deb0c3e51da 100644 (file)
@@ -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)
@@ -268,6 +264,19 @@ ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf)
         sendfile = 0;
     }
 
+#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) {
index 57e2d44cab2ee282a7d70beaf2963444fa641527..33977af613687fe1abf3bcb96493e798cfbef49f 100644 (file)
@@ -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
index c939f6ad62e143ac9f87b3de552e16b5d96216d6..5c6a830d8754639543139b7ed243aa1e8f70b791 100644 (file)
@@ -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,