Mercurial > hg > nginx
comparison src/core/ngx_output_chain.c @ 3053:0d253659da12
directio_alignment
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 28 Aug 2009 08:15:55 +0000 |
parents | 6060225e9261 |
children | 5ea5a90000d5 |
comparison
equal
deleted
inserted
replaced
3052:6060225e9261 | 3053:0d253659da12 |
---|---|
14 #endif | 14 #endif |
15 | 15 |
16 /* | 16 /* |
17 * When DIRECTIO is enabled FreeBSD, Solaris, and MacOSX read directly | 17 * When DIRECTIO is enabled FreeBSD, Solaris, and MacOSX read directly |
18 * to an application memory from a device if parameters are aligned | 18 * to an application memory from a device if parameters are aligned |
19 * to device sector boundary(512 bytes). They fallback to usual read | 19 * to device sector boundary (512 bytes). They fallback to usual read |
20 * operation if the parameters are not aligned. | 20 * operation if the parameters are not aligned. |
21 * Linux allows DIRECTIO only if the parameters are aligned to a filesystem | 21 * Linux allows DIRECTIO only if the parameters are aligned to a filesystem |
22 * sector boundary, otherwise it returns EINVAL. The sector size is | 22 * sector boundary, otherwise it returns EINVAL. The sector size is |
23 * usually 512 bytes, however, on XFS it may be 4096 bytes. | 23 * usually 512 bytes, however, on XFS it may be 4096 bytes. |
24 */ | 24 */ |
25 #define NGX_DIRECTIO_BLOCK 4096 | |
26 | |
27 | 25 |
28 #define NGX_NONE 1 | 26 #define NGX_NONE 1 |
29 | 27 |
30 | 28 |
31 static ngx_inline ngx_int_t | 29 static ngx_inline ngx_int_t |
335 return NGX_DECLINED; | 333 return NGX_DECLINED; |
336 } | 334 } |
337 | 335 |
338 ctx->directio = 1; | 336 ctx->directio = 1; |
339 | 337 |
340 size = (size_t) (in->file_pos - (in->file_pos & ~(NGX_DIRECTIO_BLOCK - 1))); | 338 size = (size_t) (in->file_pos - (in->file_pos & ~(ctx->alignment - 1))); |
341 | 339 |
342 if (size == 0) { | 340 if (size == 0) { |
343 | 341 |
344 if (bsize >= (off_t) ctx->bufs.size) { | 342 if (bsize >= (off_t) ctx->bufs.size) { |
345 return NGX_DECLINED; | 343 return NGX_DECLINED; |
346 } | 344 } |
347 | 345 |
348 size = (size_t) bsize; | 346 size = (size_t) bsize; |
349 | 347 |
350 } else { | 348 } else { |
351 size = NGX_DIRECTIO_BLOCK - size; | 349 size = ctx->alignment - size; |
352 | 350 |
353 if ((off_t) size > bsize) { | 351 if ((off_t) size > bsize) { |
354 size = (size_t) bsize; | 352 size = (size_t) bsize; |
355 } | 353 } |
356 } | 354 } |
421 /* | 419 /* |
422 * allocate block aligned to a disk sector size to enable | 420 * allocate block aligned to a disk sector size to enable |
423 * userland buffer direct usage conjunctly with directio | 421 * userland buffer direct usage conjunctly with directio |
424 */ | 422 */ |
425 | 423 |
426 b->start = ngx_pmemalign(ctx->pool, size, NGX_DIRECTIO_BLOCK); | 424 b->start = ngx_pmemalign(ctx->pool, size, ctx->alignment); |
427 if (b->start == NULL) { | 425 if (b->start == NULL) { |
428 return NGX_ERROR; | 426 return NGX_ERROR; |
429 } | 427 } |
430 | 428 |
431 } else { | 429 } else { |