8000 Support for sendfile(SF_NOCACHE). · nginx/nginx@1f01183 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f01183

Browse files
committed
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.
1 parent 2a00e61 commit 1f01183

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/core/ngx_output_chain.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf)
256256
}
257257
#endif
258258

259-
if (buf->in_file && buf->file->directio) {
260-
return 0;
261-
}
262-
263259
sendfile = ctx->sendfile;
264260

10000
265261
#if (NGX_SENDFILE_LIMIT)
@@ -268,6 +264,19 @@ ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf)
268264
sendfile = 0;
269265
}
270266

267+
#endif
268+
269+
#if !(NGX_HAVE_SENDFILE_NODISKIO)
270+
271+
/*
272+
* With DIRECTIO, disable sendfile() unless sendfile(SF_NOCACHE)
273+
* is available.
274+
*/
275+
276+
if (buf->in_file && buf->file->directio) {
277+
sendfile = 0;
278+
}
279+
271280
#endif
272281

273282
if (!sendfile) {

src/event/ngx_event_openssl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,7 +2955,13 @@ ngx_ssl_sendfile(ngx_connection_t *c, ngx_buf_t *file, size_t size)
29552955
ngx_set_errno(0);
29562956

29572957
#if (NGX_HAVE_SENDFILE_NODISKIO)
2958+
29582959
flags = (c->busy_count <= 2) ? SF_NODISKIO : 0;
2960+
2961+
if (file->file->directio) {
2962+
flags |= SF_NOCACHE;
2963+
}
2964+
29592965
#else
29602966
flags = 0;
29612967
#endif

src/os/unix/ngx_freebsd_sendfile_chain.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
174174
sent = 0;
175175

176176
#if (NGX_HAVE_SENDFILE_NODISKIO)
177+
177178
flags = (c->busy_count <= 2) ? SF_NODISKIO : 0;
179+
180+
if (file->file->directio) {
181+
flags |= SF_NOCACHE;
182+
}
183+
178184
#endif
179185

180186
rc = sendfile(file->file->fd, c->fd, file->file_pos,

0 commit comments

Comments
 (0)
0