disable directio for unaligned reads in Linux
Igor Sysoev
13 years ago
181 | 181 |
. auto/feature
|
182 | 182 |
|
183 | 183 |
|
|
184 |
if [ $ngx_found = yes -a "$NGX_SYSTEM" = "Linux" ]; then
|
|
185 |
have=NGX_HAVE_ALIGNED_DIRECTIO . auto/have
|
|
186 |
fi
|
|
187 |
|
184 | 188 |
ngx_feature="F_NOCACHE"
|
185 | 189 |
ngx_feature_name="NGX_HAVE_F_NOCACHE"
|
186 | 190 |
ngx_feature_run=no
|
78 | 78 |
|
79 | 79 |
unsigned sendfile;
|
80 | 80 |
unsigned directio;
|
|
81 |
#if (NGX_HAVE_ALIGNED_DIRECTIO)
|
|
82 |
unsigned unaligned;
|
|
83 |
#endif
|
81 | 84 |
unsigned need_in_memory;
|
82 | 85 |
unsigned need_in_temp;
|
83 | 86 |
|
354 | 354 |
* to reuse the buf via ctx->free list
|
355 | 355 |
*/
|
356 | 356 |
|
|
357 |
#if (NGX_HAVE_ALIGNED_DIRECTIO)
|
|
358 |
ctx->unaligned = 1;
|
|
359 |
#endif
|
|
360 |
|
357 | 361 |
return NGX_OK;
|
358 | 362 |
}
|
359 | 363 |
|
|
490 | 494 |
}
|
491 | 495 |
|
492 | 496 |
} else {
|
|
497 |
|
|
498 |
#if (NGX_HAVE_ALIGNED_DIRECTIO)
|
|
499 |
|
|
500 |
if (ctx->unaligned) {
|
|
501 |
if (ngx_directio_off(src->file->fd) == -1) {
|
|
502 |
ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno,
|
|
503 |
ngx_directio_off_n " \"%s\" failed",
|
|
504 |
src->file->name.data);
|
|
505 |
}
|
|
506 |
}
|
|
507 |
|
|
508 |
#endif
|
|
509 |
|
493 | 510 |
n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos);
|
|
511 |
|
|
512 |
#if (NGX_HAVE_ALIGNED_DIRECTIO)
|
|
513 |
|
|
514 |
if (ctx->unaligned) {
|
|
515 |
ngx_err_t err;
|
|
516 |
|
|
517 |
err = ngx_errno;
|
|
518 |
|
|
519 |
if (ngx_directio_on(src->file->fd) == -1) {
|
|
520 |
ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, ngx_errno,
|
|
521 |
ngx_directio_on_n " \"%s\" failed",
|
|
522 |
src->file->name.data);
|
|
523 |
}
|
|
524 |
|
|
525 |
ngx_set_errno(err);
|
|
526 |
|
|
527 |
ctx->unaligned = 0;
|
|
528 |
}
|
|
529 |
|
|
530 |
#endif
|
494 | 531 |
|
495 | 532 |
if (n == NGX_ERROR) {
|
496 | 533 |
return (ngx_int_t) n;
|
221 | 221 |
|
222 | 222 |
#if (NGX_HAVE_O_DIRECT)
|
223 | 223 |
|
224 | |
ngx_int_t ngx_directio(ngx_fd_t fd);
|
225 | |
#define ngx_directio_n "fcntl(O_DIRECT)"
|
|
224 |
ngx_int_t ngx_directio_on(ngx_fd_t fd);
|
|
225 |
#define ngx_directio_on_n "fcntl(O_DIRECT)"
|
|
226 |
|
|
227 |
ngx_int_t ngx_directio_off(ngx_fd_t fd);
|
|
228 |
#define ngx_directio_off_n "fcntl(!O_DIRECT)"
|
226 | 229 |
|
227 | 230 |
#elif (NGX_HAVE_F_NOCACHE)
|
228 | 231 |
|
229 | |
#define ngx_directio(fd) fcntl(fd, F_NOCACHE, 1)
|
230 | |
#define ngx_directio_n "fcntl(F_NOCACHE)"
|
|
232 |
#define ngx_directio_on(fd) fcntl(fd, F_NOCACHE, 1)
|
|
233 |
#define ngx_directio_on_n "fcntl(F_NOCACHE, 1)"
|
231 | 234 |
|
232 | 235 |
#elif (NGX_HAVE_DIRECTIO)
|
233 | 236 |
|
234 | |
#define ngx_directio(fd) directio(fd, DIRECTIO_ON)
|
235 | |
#define ngx_directio_n "directio(DIRECTIO_ON)"
|
236 | |
|
237 | |
#else
|
238 | |
|
239 | |
#define ngx_directio(fd) 0
|
240 | |
#define ngx_directio_n "ngx_directio_n"
|
|
237 |
#define ngx_directio_on(fd) directio(fd, DIRECTIO_ON)
|
|
238 |
#define ngx_directio_on_n "directio(DIRECTIO_ON)"
|
|
239 |
|
|
240 |
#else
|
|
241 |
|
|
242 |
#define ngx_directio_on(fd) 0
|
|
243 |
#define ngx_directio_on_n "ngx_directio_on_n"
|
241 | 244 |
|
242 | 245 |
#endif
|
243 | 246 |
|
231 | 231 |
off_t offset, ngx_pool_t *pool);
|
232 | 232 |
|
233 | 233 |
|
234 | |
ngx_int_t ngx_directio(ngx_fd_t fd);
|
235 | |
#define ngx_directio_n "ngx_directio_n"
|
|
234 |
ngx_int_t ngx_directio_on(ngx_fd_t fd);
|
|
235 |
#define ngx_directio_on_n "ngx_directio_on_n"
|
|
236 |
|
|
237 |
ngx_int_t ngx_directio_off(ngx_fd_t fd);
|
|
238 |
#define ngx_directio_off_n "ngx_directio_off_n"
|
236 | 239 |
|
237 | 240 |
|
238 | 241 |
#endif /* _NGX_FILES_H_INCLUDED_ */
|