[PATCH 4 of 4] Support for sendfile(SF_NOCACHE)

Sergey Kandaurov pluknet at nginx.com
Tue Nov 30 12:15:50 UTC 2021


On Thu, Nov 11, 2021 at 07:21:12AM +0300, Maxim Dounin wrote:
> # HG changeset patch
> # User Maxim Dounin <mdounin at mdounin.ru>
> # Date 1636603897 -10800
> #      Thu Nov 11 07:11:37 2021 +0300
> # Node ID 10f96e74ae73e1c53a3fd08e7e1c26754c8969ed
> # Parent  98d3beb63f32cbb68d1cdcec385614d32129cad0
> 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.
> 
> diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
> --- a/src/core/ngx_output_chain.c
> +++ b/src/core/ngx_output_chain.c
> @@ -256,9 +256,11 @@ ngx_output_chain_as_is(ngx_output_chain_
>      }
>  #endif
>  
> +#if !(NGX_HAVE_SENDFILE_NODISKIO)
>      if (buf->in_file && buf->file->directio) {
>          return 0;
>      }
> +#endif

This probably deserves a comment, why it depends on such a macro test.
Though, it should be pretty clear from the commit log.

>  
>      sendfile = ctx->sendfile;
>  
> diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
> --- 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, 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 --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
> --- 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_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,
> 

Otherwise, looks good.


More information about the nginx-devel mailing list