From: Willy Tarreau Date: Sun, 1 Nov 2026 20:23:40 +0000 (+0100) Subject: BUG/MINOR: compression: pass the configured level to slz X-Git-Tag: v3.5-dev11~60 X-Git-Url: https://git.kaiwu.me/$%7BGITURL%7D$%7Bcid%7D?a=commitdiff_plain;h=7fe515c3dd6bfb2e72ae840f2da43048bf48e5df;p=haproxy.git BUG/MINOR: compression: pass the configured level to slz 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. --- diff --git a/src/compression.c b/src/compression.c index d0fceb15d..1d98cb759 100644 --- a/src/compression.c +++ b/src/compression.c @@ -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; }