v1 2026-10-05

zram 压缩上下文重构瘦身 · v1

重构 zcomp 压缩上下文,把读写上下文分离以缓解抢占式 zram 的优先级反转,并精简各压缩后端,按上下文/CPU 省数十至数百 KB 内存。

原始补丁链接

子 Patch(10)

1/10
zram: prefix backends printk-s
把 zram 各压缩后端的 printk 前缀改为带 zram:,例如 zram:zstd:,使日志能明确标识来自 zram 后端,避免被误认为独立子系统。
2/10
zram: remove debugfs entry on init failure
Do not leak the debugfs entry when zram_init() fails to register the block device. Fixes: c0265342bff4 (“zram: introduce zram memory tracking”) Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium
3/10
zram: zstd: do not allocate empty C/D-dictionaries
Do not zstd_create_cdict_byreference() / zstd_create_ddict_byreference() C/D dictionaries when no dictionary was provided in the first place, because zstd still allocates internal memory for such call
4/10
zram: lz4hc: pre-initialize dictionary stream in setup_params
Pre-initialize the dictionary stream once in lz4hc_setup_params(), store it in params->drv_data, and memcpy() it into the per-CPU stream before LZ4_compress_HC_continue(), matching backend_lz4. This
5/10
zram: lz4: use LZ4_decompress_safe_usingDict()
Use LZ4_decompress_safe_usingDict() in lz4_decompress() and drop the per-CPU dstrm allocation. Store the compression workspace directly in ctx->context. Using vmalloc(LZ4_MEM_COMPRESS) instead of kz
6/10
zram: lz4hc: use LZ4_decompress_safe_usingDict()
Use LZ4_decompress_safe_usingDict() in lz4hc_decompress() to avoid needing a per-CPU LZ4_streamDecode_t structure. Drop struct lz4hc_ctx as well and store the compression workspace directly in ctx->c
7/10
zram: zstd: do not use kvzalloc() for zstd allocations
When a dictionary is configured, zstd allocates all of its memory (C/D dictionaries, compression and decompression contexts and compression workspaces) via zstd_custom_alloc(). zstd_custom_alloc() us
8/10
zram: reset writeback state in zram_reset_device()
Reset all writeback state to its initial defaults on device reset. We used to keep writeback related data in zram->stats, which zram_reset_device() clears, but commit 1d69a3f8ae77 (“zram: idle writeba
9/10
zram: split zcomp into separate R/W streams
Split struct zcomp_strm into separate compression (Write zcomp_cstrm) and decompression (Read zcomp_dstrm) streams, and split zcomp_ops context creation/destruction into create_cctx/destroy_cctx and o
10/10
zram: use a singleton compression context for recompression
Secondary compressors are only used by recompress_store(), which is serialized under zram->dev_lock, so we only ever use one secondary compressor at a time, yet we still allocate them on each CPU, whi