Klaus Demo nginx / 3266171
read_ahead Igor Sysoev 12 years ago
15 changed file(s) with 79 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
169169 CRYPT_LIB="-lcrypt"
170170 fi
171171 fi
172
173
174 ngx_feature="F_READAHEAD"
175 ngx_feature_name="NGX_HAVE_F_READAHEAD"
176 ngx_feature_run=no
177 ngx_feature_incs="#include <fcntl.h>"
178 ngx_feature_path=
179 ngx_feature_libs=
180 ngx_feature_test="fcntl(0, F_READAHEAD, 1);"
181 . auto/feature
182
183
184 ngx_feature="posix_fadvise()"
185 ngx_feature_name="NGX_HAVE_POSIX_FADVISE"
186 ngx_feature_run=no
187 ngx_feature_incs="#include <fcntl.h>"
188 ngx_feature_path=
189 ngx_feature_libs=
190 ngx_feature_test="posix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL);"
191 . auto/feature
172192
173193
174194 ngx_feature="O_DIRECT"
1414 * directories stat() info;
1515 * files and directories errors: not found, access denied, etc.
1616 */
17
18
19 #define NGX_MIN_READ_AHEAD (128 * 1024)
1720
1821
1922 static void ngx_open_file_cache_cleanup(void *data);
523526 } else {
524527 of->fd = fd;
525528
529 if (of->read_ahead && ngx_file_size(&fi) > NGX_MIN_READ_AHEAD) {
530 if (ngx_read_ahead(fd, of->read_ahead) == NGX_ERROR) {
531 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
532 ngx_read_ahead_n " \"%s\" failed", name);
533 }
534 }
535
526536 if (of->directio <= ngx_file_size(&fi)) {
527537 if (ngx_directio_on(fd) == NGX_FILE_ERROR) {
528538 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
2020 time_t mtime;
2121 off_t size;
2222 off_t directio;
23 size_t read_ahead;
2324
2425 ngx_err_t err;
2526 char *failed;
105105
106106 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
107107
108 of.read_ahead = clcf->read_ahead;
108109 of.directio = clcf->directio;
109110 of.valid = clcf->open_file_cache_valid;
110111 of.min_uses = clcf->open_file_cache_min_uses;
123123
124124 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
125125
126 of.read_ahead = clcf->read_ahead;
126127 of.directio = clcf->directio;
127128 of.valid = clcf->open_file_cache_valid;
128129 of.min_uses = clcf->open_file_cache_min_uses;
204204
205205 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
206206
207 of.read_ahead = clcf->read_ahead;
207208 of.directio = clcf->directio;
208209 of.valid = clcf->open_file_cache_valid;
209210 of.min_uses = clcf->open_file_cache_min_uses;
9090
9191 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
9292
93 of.read_ahead = clcf->read_ahead;
9394 of.directio = clcf->directio;
9495 of.valid = clcf->open_file_cache_valid;
9596 of.min_uses = clcf->open_file_cache_min_uses;
647647
648648 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
649649
650 of.read_ahead = clcf->read_ahead;
650651 of.directio = clcf->directio;
651652 of.valid = clcf->open_file_cache_valid;
652653 of.min_uses = clcf->open_file_cache_min_uses;
407407
408408 #endif
409409
410 { ngx_string("read_ahead"),
411 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
412 ngx_conf_set_size_slot,
413 NGX_HTTP_LOC_CONF_OFFSET,
414 offsetof(ngx_http_core_loc_conf_t, read_ahead),
415 NULL },
416
410417 { ngx_string("directio"),
411418 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
412419 ngx_http_core_directio,
29562963 #if (NGX_HAVE_FILE_AIO)
29572964 lcf->aio = NGX_CONF_UNSET;
29582965 #endif
2966 lcf->read_ahead = NGX_CONF_UNSET_SIZE;
29592967 lcf->directio = NGX_CONF_UNSET;
29602968 lcf->directio_alignment = NGX_CONF_UNSET;
29612969 lcf->tcp_nopush = NGX_CONF_UNSET;
31573165 #if (NGX_HAVE_FILE_AIO)
31583166 ngx_conf_merge_value(conf->aio, prev->aio, 0);
31593167 #endif
3168 ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0);
31603169 ngx_conf_merge_off_value(conf->directio, prev->directio,
31613170 NGX_MAX_OFF_T_VALUE);
31623171 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment,
331331 size_t limit_rate; /* limit_rate */
332332 size_t limit_rate_after; /* limit_rate_after */
333333 size_t sendfile_max_chunk; /* sendfile_max_chunk */
334 size_t read_ahead; /* read_ahead */
334335
335336 ngx_msec_t client_body_timeout; /* client_body_timeout */
336337 ngx_msec_t send_timeout; /* send_timeout */
280280 of.min_uses = clcf->open_file_cache_min_uses;
281281 of.events = clcf->open_file_cache_events;
282282 of.directio = NGX_OPEN_FILE_DIRECTIO_OFF;
283 of.read_ahead = clcf->read_ahead;
283284
284285 if (ngx_open_cached_file(clcf->open_file_cache, &c->file.name, &of, r->pool)
285286 != NGX_OK)
14061406
14071407 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
14081408
1409 of.read_ahead = clcf->read_ahead;
14091410 of.directio = clcf->directio;
14101411 of.valid = clcf->open_file_cache_valid;
14111412 of.min_uses = clcf->open_file_cache_min_uses;
253253 #define ngx_unlock_fd_n "fcntl(F_SETLK, F_UNLCK)"
254254
255255
256 #if (NGX_HAVE_F_READAHEAD)
257
258 #define NGX_HAVE_READ_AHEAD 1
259
260 #define ngx_read_ahead(fd, n) fcntl(fd, F_READAHEAD, (int) n)
261 #define ngx_read_ahead_n "fcntl(fd, F_READAHEAD)"
262
263 #elif (NGX_HAVE_POSIX_FADVISE)
264
265 #define NGX_HAVE_READ_AHEAD 1
266
267 #define ngx_read_ahead(fd, n) posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL)
268 #define ngx_read_ahead_n "posix_fadvise(POSIX_FADV_SEQUENTIAL)"
269
270 #else
271
272 #define ngx_read_ahead(fd, n) 0
273 #define ngx_read_ahead_n "ngx_read_ahead_n"
274
275 #endif
276
277
256278 #if (NGX_HAVE_O_DIRECT)
257279
258280 ngx_int_t ngx_directio_on(ngx_fd_t fd);
476476
477477
478478 ngx_int_t
479 ngx_read_ahead(ngx_fd_t fd, size_t n)
480 {
481 return ~NGX_FILE_ERROR;
482 }
483
484
485 ngx_int_t
479486 ngx_directio_on(ngx_fd_t fd)
480487 {
481488 return ~NGX_FILE_ERROR;
231231 ssize_t ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *ce,
232232 off_t offset, ngx_pool_t *pool);
233233
234 ngx_int_t ngx_read_ahead(ngx_fd_t fd, size_t n);
235 #define ngx_read_ahead_n "ngx_read_ahead_n"
234236
235237 ngx_int_t ngx_directio_on(ngx_fd_t fd);
236238 #define ngx_directio_on_n "ngx_directio_on_n"