Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

zram: add 842 compression backend support

Add s/w 842 compression support.

Link: https://lkml.kernel.org/r/20240902105656.1383858-12-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nick Terrell <terrelln@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Sergey Senozhatsky and committed by
Andrew Morton
1d3100cf 84112e31

+94
+11
drivers/block/zram/Kconfig
··· 44 44 select ZLIB_DEFLATE 45 45 select ZLIB_INFLATE 46 46 47 + config ZRAM_BACKEND_842 48 + bool "842 compression support" 49 + depends on ZRAM 50 + select 842_COMPRESS 51 + select 842_DECOMPRESS 52 + 47 53 choice 48 54 prompt "Default zram compressor" 49 55 default ZRAM_DEF_COMP_LZORLE ··· 79 73 bool "deflate" 80 74 depends on ZRAM_BACKEND_DEFLATE 81 75 76 + config ZRAM_DEF_COMP_842 77 + bool "842" 78 + depends on ZRAM_BACKEND_842 79 + 82 80 endchoice 83 81 84 82 config ZRAM_DEF_COMP ··· 93 83 default "lz4hc" if ZRAM_DEF_COMP_LZ4HC 94 84 default "zstd" if ZRAM_DEF_COMP_ZSTD 95 85 default "deflate" if ZRAM_DEF_COMP_DEFLATE 86 + default "842" if ZRAM_DEF_COMP_842 96 87 default "unset-value" 97 88 98 89 config ZRAM_WRITEBACK
+1
drivers/block/zram/Makefile
··· 7 7 zram-$(CONFIG_ZRAM_BACKEND_LZ4HC) += backend_lz4hc.o 8 8 zram-$(CONFIG_ZRAM_BACKEND_ZSTD) += backend_zstd.o 9 9 zram-$(CONFIG_ZRAM_BACKEND_DEFLATE) += backend_deflate.o 10 + zram-$(CONFIG_ZRAM_BACKEND_842) += backend_842.o 10 11 11 12 obj-$(CONFIG_ZRAM) += zram.o
+68
drivers/block/zram/backend_842.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/kernel.h> 4 + #include <linux/slab.h> 5 + #include <linux/sw842.h> 6 + #include <linux/vmalloc.h> 7 + 8 + #include "backend_842.h" 9 + 10 + struct sw842_ctx { 11 + void *mem; 12 + }; 13 + 14 + static void destroy_842(void *ctx) 15 + { 16 + struct sw842_ctx *zctx = ctx; 17 + 18 + kfree(zctx->mem); 19 + kfree(zctx); 20 + } 21 + 22 + static void *create_842(void) 23 + { 24 + struct sw842_ctx *ctx; 25 + 26 + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 27 + if (!ctx) 28 + return NULL; 29 + 30 + ctx->mem = kmalloc(SW842_MEM_COMPRESS, GFP_KERNEL); 31 + if (!ctx->mem) 32 + goto error; 33 + 34 + return ctx; 35 + 36 + error: 37 + destroy_842(ctx); 38 + return NULL; 39 + } 40 + 41 + static int compress_842(void *ctx, const unsigned char *src, size_t src_len, 42 + unsigned char *dst, size_t *dst_len) 43 + { 44 + struct sw842_ctx *zctx = ctx; 45 + unsigned int dlen = *dst_len; 46 + int ret; 47 + 48 + ret = sw842_compress(src, src_len, dst, &dlen, zctx->mem); 49 + if (ret == 0) 50 + *dst_len = dlen; 51 + return ret; 52 + } 53 + 54 + static int decompress_842(void *ctx, const unsigned char *src, size_t src_len, 55 + unsigned char *dst, size_t dst_len) 56 + { 57 + unsigned int dlen = dst_len; 58 + 59 + return sw842_decompress(src, src_len, dst, &dlen); 60 + } 61 + 62 + const struct zcomp_ops backend_842 = { 63 + .compress = compress_842, 64 + .decompress = decompress_842, 65 + .create_ctx = create_842, 66 + .destroy_ctx = destroy_842, 67 + .name = "842", 68 + };
+10
drivers/block/zram/backend_842.h
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #ifndef __BACKEND_842_H__ 4 + #define __BACKEND_842_H__ 5 + 6 + #include "zcomp.h" 7 + 8 + extern const struct zcomp_ops backend_842; 9 + 10 + #endif /* __BACKEND_842_H__ */
+4
drivers/block/zram/zcomp.c
··· 18 18 #include "backend_lz4hc.h" 19 19 #include "backend_zstd.h" 20 20 #include "backend_deflate.h" 21 + #include "backend_842.h" 21 22 22 23 static const struct zcomp_ops *backends[] = { 23 24 #if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZO) ··· 36 35 #endif 37 36 #if IS_ENABLED(CONFIG_ZRAM_BACKEND_DEFLATE) 38 37 &backend_deflate, 38 + #endif 39 + #if IS_ENABLED(CONFIG_ZRAM_BACKEND_842) 40 + &backend_842, 39 41 #endif 40 42 NULL 41 43 };