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

zram: add lzo and lzorle compression backends support

Add s/w lzo/lzorle compression support.

Link: https://lkml.kernel.org/r/20240902105656.1383858-6-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
2152247c 917a59e8

+140
+23
drivers/block/zram/Kconfig
··· 14 14 15 15 See Documentation/admin-guide/blockdev/zram.rst for more information. 16 16 17 + config ZRAM_BACKEND_LZO 18 + bool "lzo and lzo-rle compression support" 19 + depends on ZRAM 20 + select LZO_COMPRESS 21 + select LZO_DECOMPRESS 22 + 23 + choice 24 + prompt "Default zram compressor" 25 + default ZRAM_DEF_COMP_LZORLE 26 + depends on ZRAM 27 + 28 + config ZRAM_DEF_COMP_LZORLE 29 + bool "lzo-rle" 30 + depends on ZRAM_BACKEND_LZO 31 + 32 + config ZRAM_DEF_COMP_LZO 33 + bool "lzo" 34 + depends on ZRAM_BACKEND_LZO 35 + 36 + endchoice 37 + 17 38 config ZRAM_DEF_COMP 18 39 string 40 + default "lzo-rle" if ZRAM_DEF_COMP_LZORLE 41 + default "lzo" if ZRAM_DEF_COMP_LZO 19 42 default "unset-value" 20 43 21 44 config ZRAM_WRITEBACK
+3
drivers/block/zram/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 + 2 3 zram-y := zcomp.o zram_drv.o 4 + 5 + zram-$(CONFIG_ZRAM_BACKEND_LZO) += backend_lzorle.o backend_lzo.o 3 6 4 7 obj-$(CONFIG_ZRAM) += zram.o
+43
drivers/block/zram/backend_lzo.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/kernel.h> 4 + #include <linux/slab.h> 5 + #include <linux/lzo.h> 6 + 7 + #include "backend_lzo.h" 8 + 9 + static void *lzo_create(void) 10 + { 11 + return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 12 + } 13 + 14 + static void lzo_destroy(void *ctx) 15 + { 16 + kfree(ctx); 17 + } 18 + 19 + static int lzo_compress(void *ctx, const unsigned char *src, size_t src_len, 20 + unsigned char *dst, size_t *dst_len) 21 + { 22 + int ret; 23 + 24 + ret = lzo1x_1_compress(src, src_len, dst, dst_len, ctx); 25 + return ret == LZO_E_OK ? 0 : ret; 26 + } 27 + 28 + static int lzo_decompress(void *ctx, const unsigned char *src, size_t src_len, 29 + unsigned char *dst, size_t dst_len) 30 + { 31 + int ret; 32 + 33 + ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len); 34 + return ret == LZO_E_OK ? 0 : ret; 35 + } 36 + 37 + const struct zcomp_ops backend_lzo = { 38 + .compress = lzo_compress, 39 + .decompress = lzo_decompress, 40 + .create_ctx = lzo_create, 41 + .destroy_ctx = lzo_destroy, 42 + .name = "lzo", 43 + };
+10
drivers/block/zram/backend_lzo.h
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #ifndef __BACKEND_LZO_H__ 4 + #define __BACKEND_LZO_H__ 5 + 6 + #include "zcomp.h" 7 + 8 + extern const struct zcomp_ops backend_lzo; 9 + 10 + #endif /* __BACKEND_LZO_H__ */
+44
drivers/block/zram/backend_lzorle.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/kernel.h> 4 + #include <linux/slab.h> 5 + #include <linux/lzo.h> 6 + 7 + #include "backend_lzorle.h" 8 + 9 + static void *lzorle_create(void) 10 + { 11 + return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 12 + } 13 + 14 + static void lzorle_destroy(void *ctx) 15 + { 16 + kfree(ctx); 17 + } 18 + 19 + static int lzorle_compress(void *ctx, const unsigned char *src, size_t src_len, 20 + unsigned char *dst, size_t *dst_len) 21 + { 22 + int ret; 23 + 24 + ret = lzorle1x_1_compress(src, src_len, dst, dst_len, ctx); 25 + return ret == LZO_E_OK ? 0 : ret; 26 + } 27 + 28 + static int lzorle_decompress(void *ctx, const unsigned char *src, 29 + size_t src_len, unsigned char *dst, 30 + size_t dst_len) 31 + { 32 + int ret; 33 + 34 + ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len); 35 + return ret == LZO_E_OK ? 0 : ret; 36 + } 37 + 38 + const struct zcomp_ops backend_lzorle = { 39 + .compress = lzorle_compress, 40 + .decompress = lzorle_decompress, 41 + .create_ctx = lzorle_create, 42 + .destroy_ctx = lzorle_destroy, 43 + .name = "lzo-rle", 44 + };
+10
drivers/block/zram/backend_lzorle.h
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #ifndef __BACKEND_LZORLE_H__ 4 + #define __BACKEND_LZORLE_H__ 5 + 6 + #include "zcomp.h" 7 + 8 + extern const struct zcomp_ops backend_lzorle; 9 + 10 + #endif /* __BACKEND_LZORLE_H__ */
+7
drivers/block/zram/zcomp.c
··· 12 12 13 13 #include "zcomp.h" 14 14 15 + #include "backend_lzo.h" 16 + #include "backend_lzorle.h" 17 + 15 18 static const struct zcomp_ops *backends[] = { 19 + #if IS_ENABLED(CONFIG_ZRAM_BACKEND_LZO) 20 + &backend_lzorle, 21 + &backend_lzo, 22 + #endif 16 23 NULL 17 24 }; 18 25