]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: compression: pass the configured level to slz
authorWilly Tarreau <w@1wt.eu>
Sun, 1 Nov 2026 20:23:40 +0000 (21:23 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 3 Nov 2026 08:33:40 +0000 (09:33 +0100)
Since its integration in 1.6 with commit 418b8c0c4 ("MAJOR: compression:
integrate support for libslz"), the slz backend only knew levels 0 and 1,
so the init functions forced the level to 0 or 1 using !!level, and the
rate limiting code only raised the level back up to 1. Since slz 1.4-dev3
was imported in commit 32582812a ("IMPORT: slz: update slz to version
1.4-dev3"), slz supports levels 1 to 3 (higher ones behave as 3), but
tune.comp.maxlevel was still capped to 1.

Let's pass the configured level to slz's init functions, and let the rate
limiting code raise the level back up to tune.comp.maxlevel.

Note that configurations with tune.comp.maxlevel above 1 will now use the
higher slz levels, which compress better but consume more CPU.

This must be backported wherever commit 32582812a is backported.

src/compression.c

index d0fceb15ddc087205b8e64b5d04527cf4decbae8..1d98cb7599717bbb58ac04c9b1753dfbde05a593 100644 (file)
@@ -339,8 +339,8 @@ static int comp_rfc1952_init(struct comp_ctx **comp_ctx, int level)
        if (init_comp_ctx(comp_ctx) < 0)
                return -1;
 
-       (*comp_ctx)->cur_lvl = !!level;
-       return slz_rfc1952_init(&(*comp_ctx)->strm, !!level);
+       (*comp_ctx)->cur_lvl = level;
+       return slz_rfc1952_init(&(*comp_ctx)->strm, level);
 }
 
 /* SLZ's raw deflate format (RFC1951). Returns < 0 on error. */
@@ -349,8 +349,8 @@ static int comp_rfc1951_init(struct comp_ctx **comp_ctx, int level)
        if (init_comp_ctx(comp_ctx) < 0)
                return -1;
 
-       (*comp_ctx)->cur_lvl = !!level;
-       return slz_rfc1951_init(&(*comp_ctx)->strm, !!level);
+       (*comp_ctx)->cur_lvl = level;
+       return slz_rfc1951_init(&(*comp_ctx)->strm, level);
 }
 
 /* SLZ's zlib format (RFC1950). Returns < 0 on error. */
@@ -359,8 +359,8 @@ static int comp_rfc1950_init(struct comp_ctx **comp_ctx, int level)
        if (init_comp_ctx(comp_ctx) < 0)
                return -1;
 
-       (*comp_ctx)->cur_lvl = !!level;
-       return slz_rfc1950_init(&(*comp_ctx)->strm, !!level);
+       (*comp_ctx)->cur_lvl = level;
+       return slz_rfc1950_init(&(*comp_ctx)->strm, level);
 }
 
 /* Return the size of consumed data. The caller is responsible for guaranteeing
@@ -407,7 +407,7 @@ static int comp_rfc195x_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer
                if (comp_ctx->cur_lvl > 0)
                        strm->level = --comp_ctx->cur_lvl;
        }
-       else if (comp_ctx->cur_lvl < global.tune.comp_maxlevel && comp_ctx->cur_lvl < 1) {
+       else if (comp_ctx->cur_lvl < global.tune.comp_maxlevel) {
                strm->level = ++comp_ctx->cur_lvl;
        }