Re: [PATCH v3 13/18] zram: lz4hc: compress levels above 9 as level 9

From: Michal Wilczynski

Date: Thu Dec 03 2026 - 09:26:06 EST




On 12/3/26 03:26, Sergey Senozhatsky wrote:
> On (26/12/02 18:32), Michal Wilczynski wrote:
> [..]
>> +++ b/drivers/block/zram/backend_lz4hc.c
>> @@ -36,6 +36,16 @@ static int lz4hc_setup_params(struct zcomp_params *params)
>> */
>> pr_err("invalid compression level %d\n", params->level);
>> return -EINVAL;
>> + } else if (params->level >= LZ4HC_OPT_MIN_CLEVEL) {
>> + /*
>> + * These levels select LZ4's optimal parser, which on a page
>> + * compresses 2-5 times slower than level 9 for well under
>> + * 1% smaller output. It suits data compressed once and
>> + * read many times, not swap.
>> + */
>> + pr_info("level %d compresses as level %d\n", params->level,
>> + LZ4HC_OPT_MIN_CLEVEL - 1);
>> + params->level = LZ4HC_OPT_MIN_CLEVEL - 1;
>> }
>
> My preference would be to just return an error. We should not correct
> "bad" user input.
>

Levels 10 - 12 aren't bad input today. Zram accepts them and they compress
within 0.05% of level 9. With the vendored lz4 they select the optimal
parser, which on 4K pages makes the output at most ~0.25% smaller
while compressing 2-4x slower.

The clamp is there to keep existing settings as fast as they are now.
-EINVAL would instead break them on a kernel update.

If you're fine with that, I'll return -EINVAL in v4. Or I can drop the
patch and pass the levels through unchanged.

Best regards,
--
Michal Wilczynski <m.wilczynski@xxxxxxxxxxx>