Re: [PATCH v3 04/18] zram: lz4/lz4hc: size the streams by the library's constants

From: Sergey Senozhatsky

Date: Wed Dec 02 2026 - 21:41:24 EST


On (26/12/02 18:32), Michal Wilczynski wrote:
> <linux/lz4.h> gives the size of a compression stream as
> LZ4_MEM_COMPRESS and LZ4HC_MEM_COMPRESS, and lz4_create() and
> lz4hc_create() allocate by them. The dictionary streams and the per-page
> memcpy() use sizeof() instead, and BUILD_BUG_ON()s tie the two together.
>
> Use the constants throughout. The vendored library that replaces the
> fork later in this series declares LZ4_stream_t and LZ4_streamHC_t as
> incomplete types, as upstream does, so sizeof() stops compiling; the
> library asserts the constants against upstream's layout at build time
> instead.
>
> lz4hc allocates its streams by lz4hc_mem_compress(params->level): with
> the vendored library, levels 10 and up need a workspace after the state.
> The per-page memcpy() keeps copying LZ4HC_MEM_COMPRESS bytes, the state
> alone, since the workspace holds nothing between calls.
>
> Signed-off-by: Michal Wilczynski <m.wilczynski@xxxxxxxxxxx>

Reviewed-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>