Mercurial > hg > nginx
comparison src/http/modules/ngx_http_gzip_filter_module.c @ 7816:1f3d0d9f893f
Gzip: support for zlib-ng.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 05 Apr 2021 04:06:58 +0300 |
parents | 0ef2bc0ec9c9 |
children | c297c2c252d8 |
comparison
equal
deleted
inserted
replaced
7815:19799b290812 | 7816:1f3d0d9f893f |
---|---|
55 unsigned redo:1; | 55 unsigned redo:1; |
56 unsigned done:1; | 56 unsigned done:1; |
57 unsigned nomem:1; | 57 unsigned nomem:1; |
58 unsigned buffering:1; | 58 unsigned buffering:1; |
59 unsigned intel:1; | 59 unsigned intel:1; |
60 unsigned zlib_ng:1; | |
60 | 61 |
61 size_t zin; | 62 size_t zin; |
62 size_t zout; | 63 size_t zout; |
63 | 64 |
64 z_stream zstream; | 65 z_stream zstream; |
212 | 213 |
213 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | 214 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
214 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | 215 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; |
215 | 216 |
216 static ngx_uint_t ngx_http_gzip_assume_intel; | 217 static ngx_uint_t ngx_http_gzip_assume_intel; |
218 static ngx_uint_t ngx_http_gzip_assume_zlib_ng; | |
217 | 219 |
218 | 220 |
219 static ngx_int_t | 221 static ngx_int_t |
220 ngx_http_gzip_header_filter(ngx_http_request_t *r) | 222 ngx_http_gzip_header_filter(ngx_http_request_t *r) |
221 { | 223 { |
504 */ | 506 */ |
505 | 507 |
506 if (!ngx_http_gzip_assume_intel) { | 508 if (!ngx_http_gzip_assume_intel) { |
507 ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9)); | 509 ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9)); |
508 | 510 |
509 } else { | 511 } else if (!ngx_http_gzip_assume_zlib_ng) { |
510 /* | 512 /* |
511 * A zlib variant from Intel, https://github.com/jtkukunas/zlib. | 513 * A zlib variant from Intel, https://github.com/jtkukunas/zlib. |
512 * It can force window bits to 13 for fast compression level, | 514 * It can force window bits to 13 for fast compression level, |
513 * on processors with SSE 4.2 it uses 64K hash instead of scaling | 515 * on processors with SSE 4.2 it uses 64K hash instead of scaling |
514 * it from the specified memory level, and also introduces | 516 * it from the specified memory level, and also introduces |
521 | 523 |
522 ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) | 524 ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) |
523 + (1 << (ngx_max(memlevel, 8) + 8)) | 525 + (1 << (ngx_max(memlevel, 8) + 8)) |
524 + (1 << (memlevel + 8)); | 526 + (1 << (memlevel + 8)); |
525 ctx->intel = 1; | 527 ctx->intel = 1; |
528 | |
529 } else { | |
530 /* | |
531 * Another zlib variant, https://github.com/zlib-ng/zlib-ng. | |
532 * Similar to Intel's variant, though uses 128K hash. | |
533 */ | |
534 | |
535 if (conf->level == 1) { | |
536 wbits = ngx_max(wbits, 13); | |
537 } | |
538 | |
539 ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) | |
540 + 131072 + (1 << (memlevel + 8)); | |
541 ctx->zlib_ng = 1; | |
526 } | 542 } |
527 } | 543 } |
528 | 544 |
529 | 545 |
530 static ngx_int_t | 546 static ngx_int_t |
943 items, size, alloc, p); | 959 items, size, alloc, p); |
944 | 960 |
945 return p; | 961 return p; |
946 } | 962 } |
947 | 963 |
948 if (ctx->intel) { | 964 if (ctx->zlib_ng) { |
949 ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, | 965 ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, |
950 "gzip filter failed to use preallocated memory: " | 966 "gzip filter failed to use preallocated memory: " |
951 "%ud of %ui", items * size, ctx->allocated); | 967 "%ud of %ui", items * size, ctx->allocated); |
968 | |
969 } else if (ctx->intel) { | |
970 ngx_http_gzip_assume_zlib_ng = 1; | |
952 | 971 |
953 } else { | 972 } else { |
954 ngx_http_gzip_assume_intel = 1; | 973 ngx_http_gzip_assume_intel = 1; |
955 } | 974 } |
956 | 975 |