Welcome! Log In Create A New Profile

Advanced

[nginx] Support for sendfile(SF_NOCACHE).

Maxim Dounin
December 27, 2021 01:50PM
details: https://hg.nginx.org/nginx/rev/b002ad258f1d
branches:
changeset: 7987:b002ad258f1d
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon Dec 27 19:49:26 2021 +0300
description:
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.

diffstat:

src/core/ngx_output_chain.c | 17 +++++++++++++----
src/event/ngx_event_openssl.c | 6 ++++++
src/os/unix/ngx_freebsd_sendfile_chain.c | 6 ++++++
3 files changed, 25 insertions(+), 4 deletions(-)

diffs (68 lines):

diff -r f1fcb0fe6975 -r b002ad258f1d src/core/ngx_output_chain.c
--- a/src/core/ngx_output_chain.c Mon Dec 27 19:48:42 2021 +0300
+++ b/src/core/ngx_output_chain.c Mon Dec 27 19:49:26 2021 +0300
@@ -256,10 +256,6 @@ ngx_output_chain_as_is(ngx_output_chain_
}
#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_

#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 -r f1fcb0fe6975 -r b002ad258f1d src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c Mon Dec 27 19:48:42 2021 +0300
+++ b/src/event/ngx_event_openssl.c Mon Dec 27 19:49:26 2021 +0300
@@ -2955,7 +2955,13 @@ ngx_ssl_sendfile(ngx_connection_t *c, ng
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 -r f1fcb0fe6975 -r b002ad258f1d src/os/unix/ngx_freebsd_sendfile_chain.c
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c Mon Dec 27 19:48:42 2021 +0300
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c Mon Dec 27 19:49:26 2021 +0300
@@ -174,7 +174,13 @@ ngx_freebsd_sendfile_chain(ngx_connectio
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,
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Support for sendfile(SF_NOCACHE).

Maxim Dounin 277 December 27, 2021 01:50PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 82
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready