Maxim Dounin
April 05, 2021 09:02AM
details: https://hg.nginx.org/nginx/rev/c297c2c252d8
branches:
changeset: 7817:c297c2c252d8
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon Apr 05 04:07:17 2021 +0300
description:
Gzip: updated handling of zlib variant from Intel.

In current versions (all versions based on zlib 1.2.11, at least
since 2018) it no longer uses 64K hash and does not force window
bits to 13 if it is less than 13. That is, it needs just 16 bytes
more memory than normal zlib, so these bytes are simply added to
the normal size calculation.

diffstat:

src/http/modules/ngx_http_gzip_filter_module.c | 35 ++++++-------------------
1 files changed, 9 insertions(+), 26 deletions(-)

diffs (74 lines):

diff -r 1f3d0d9f893f -r c297c2c252d8 src/http/modules/ngx_http_gzip_filter_module.c
--- a/src/http/modules/ngx_http_gzip_filter_module.c Mon Apr 05 04:06:58 2021 +0300
+++ b/src/http/modules/ngx_http_gzip_filter_module.c Mon Apr 05 04:07:17 2021 +0300
@@ -56,7 +56,6 @@ typedef struct {
unsigned done:1;
unsigned nomem:1;
unsigned buffering:1;
- unsigned intel:1;
unsigned zlib_ng:1;

size_t zin;
@@ -214,7 +213,6 @@ static ngx_str_t ngx_http_gzip_ratio =
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;

-static ngx_uint_t ngx_http_gzip_assume_intel;
static ngx_uint_t ngx_http_gzip_assume_zlib_ng;


@@ -503,33 +501,21 @@ ngx_http_gzip_filter_memory(ngx_http_req
* 8K is for zlib deflate_state, it takes
* *) 5816 bytes on i386 and sparc64 (32-bit mode)
* *) 5920 bytes on amd64 and sparc64
+ *
+ * A zlib variant from Intel (https://github.com/jtkukunas/zlib)
+ * uses additional 16-byte padding in one of window-sized buffers.
*/

- if (!ngx_http_gzip_assume_intel) {
- ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
-
- } else if (!ngx_http_gzip_assume_zlib_ng) {
- /*
- * A zlib variant from Intel, https://github.com/jtkukunas/zlib.
- * It can force window bits to 13 for fast compression level,
- * on processors with SSE 4.2 it uses 64K hash instead of scaling
- * it from the specified memory level, and also introduces
- * 16-byte padding in one out of the two window-sized buffers.
- */
-
- if (conf->level == 1) {
- wbits = ngx_max(wbits, 13);
- }
-
+ if (!ngx_http_gzip_assume_zlib_ng) {
ctx->allocated = 8192 + 16 + (1 << (wbits + 2))
- + (1 << (ngx_max(memlevel, 8) + 8))
- + (1 << (memlevel + 8));
- ctx->intel = 1;
+ + (1 << (memlevel + 9));

} else {
/*
* Another zlib variant, https://github.com/zlib-ng/zlib-ng.
- * Similar to Intel's variant, though uses 128K hash.
+ * It forces window bits to 13 for fast compression level,
+ * uses 16-byte padding in one of window-sized buffers, and
+ * uses 128K hash.
*/

if (conf->level == 1) {
@@ -966,11 +952,8 @@ ngx_http_gzip_filter_alloc(void *opaque,
"gzip filter failed to use preallocated memory: "
"%ud of %ui", items * size, ctx->allocated);

- } else if (ctx->intel) {
+ } else {
ngx_http_gzip_assume_zlib_ng = 1;
-
- } else {
- ngx_http_gzip_assume_intel = 1;
}

p = ngx_palloc(ctx->request->pool, items * size);
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Gzip: updated handling of zlib variant from Intel.

Maxim Dounin 341 April 05, 2021 09:02AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 311
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready