From 587f2b7cf25ff8799b5d0f07a27d087adb47d6d1 Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Tue, 27 Jun 2023 15:50:03 +0000 Subject: [PATCH] EX-7683 utils: always try to use our own lz4/lz4hc lz4/lz4hc provided by the kernel do not grok a compression level. The built-in lz4/lz4hc do, so always build them as dedicated kernel modules llz4.ko and llz4hc.ko, with the same .cra_name but with a slightly higher .cra_priority = 110, so that they are preferred over the in-kernel modules if any. And try to manually load the llz4/llz4hc kernel modules when a file requires compression with the corresponding alg. This is a "one-shot" try that allows us to prefer our modules that has level support, but continues to at least compress/decompress files even if our own modules are not available. Signed-off-by: Sebastien Buisson Change-Id: I0bdf267f998e21df81e460250a653aed34e3215d Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51474 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- config/lustre-build.m4 | 2 -- debian/dkms.conf.in | 4 ++-- lustre/autoconf/lustre-core.m4 | 34 ---------------------------------- lustre/include/lustre_crypto.h | 2 ++ lustre/lz4/Makefile.in | 16 ++++++++-------- lustre/lz4/autoMakefile.am | 8 +------- lustre/lz4/{llz4.c => lz4.c} | 6 +++--- lustre/lz4/{llz4hc.c => lz4hc.c} | 6 +++--- lustre/osc/osc_compress.c | 19 +++++++++++++------ lustre/scripts/dkms.mkconf | 4 ++-- lustre/scripts/lustre_rmmod | 2 +- lustre/tests/kernel/kcompr.c | 14 +++++++++----- 12 files changed, 44 insertions(+), 73 deletions(-) rename lustre/lz4/{llz4.c => lz4.c} (98%) rename lustre/lz4/{llz4hc.c => lz4hc.c} (97%) diff --git a/config/lustre-build.m4 b/config/lustre-build.m4 index 2f7488a..640c979 100644 --- a/config/lustre-build.m4 +++ b/config/lustre-build.m4 @@ -749,8 +749,6 @@ LC_CONFIG_CLIENT LB_CONFIG_MPITESTS LB_CONFIG_SERVERS LC_CONFIG_CRYPTO -LC_CONFIG_LZ4 -LC_CONFIG_LZ4HC LC_GLIBC_SUPPORT_COPY_FILE_RANGE LC_OPENSSL_SSK diff --git a/debian/dkms.conf.in b/debian/dkms.conf.in index fb45a8c..b081187 100644 --- a/debian/dkms.conf.in +++ b/debian/dkms.conf.in @@ -21,8 +21,8 @@ BUILT_MODULE_NAME[2]="lgzip" BUILT_MODULE_NAME[3]="lmv" BUILT_MODULE_NAME[4]="lov" BUILT_MODULE_NAME[5]="lustre" -BUILT_MODULE_NAME[6]="lz4" -BUILT_MODULE_NAME[7]="lz4hc" +BUILT_MODULE_NAME[6]="llz4" +BUILT_MODULE_NAME[7]="llz4hc" BUILT_MODULE_NAME[8]="mdc" BUILT_MODULE_NAME[9]="mgc" BUILT_MODULE_NAME[10]="obdclass" diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 4235c05..eb6417a 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -3859,38 +3859,6 @@ AC_MSG_RESULT([$enable_crypto]) ]) # LC_CONFIG_CRYPTO # -# LC_CONFIG_LZ4 -# -# Check whether to build our own LZ4 kernel module. -# Always embed on SLES, as kernel config might not be reliable. -# -AC_DEFUN([LC_CONFIG_LZ4], [ -AS_IF([test x$SUSE_KERNEL = xyes], [enable_lz4=yes], [ -LB_CHECK_CONFIG_IM([CRYPTO_LZ4],[ - enable_lz4=no],[ - enable_lz4=yes -]) -]) -AC_MSG_RESULT([Embed lz4 $enable_lz4]) -]) # LC_CONFIG_LZ4 - -# -# LC_CONFIG_LZ4HC -# -# Check whether to build our own LZ4HC kernel module. -# Always embed on SLES, as kernel config might not be reliable. -# -AC_DEFUN([LC_CONFIG_LZ4HC], [ -AS_IF([test x$SUSE_KERNEL = xyes], [enable_lz4hc=yes], [ -LB_CHECK_CONFIG_IM([CRYPTO_LZ4HC],[ - enable_lz4hc=no],[ - enable_lz4hc=yes -]) -]) -AC_MSG_RESULT([Embed lz4hc $enable_lz4hc]) -]) # LC_CONFIG_LZ4HC - -# # LC_CONFIGURE # # other configure checks @@ -4085,8 +4053,6 @@ AM_CONDITIONAL(SELINUX, test "$SELINUX" = "-lselinux") AM_CONDITIONAL(GETSEPOL, test x$enable_getsepol = xyes) AM_CONDITIONAL(LLCRYPT, test x$enable_llcrypt = xyes) AM_CONDITIONAL(LIBAIO, test x$enable_libaio = xyes) -AM_CONDITIONAL(LZ4, test x$enable_lz4 = xyes) -AM_CONDITIONAL(LZ4HC, test x$enable_lz4hc = xyes) ]) # LC_CONDITIONALS # diff --git a/lustre/include/lustre_crypto.h b/lustre/include/lustre_crypto.h index 536a90e..5c3093a 100644 --- a/lustre/include/lustre_crypto.h +++ b/lustre/include/lustre_crypto.h @@ -50,6 +50,8 @@ void ll_sbi_set_name_encrypt(struct ll_sb_info *sbi, bool set); */ #define COMPR_LEVEL_SHIFT 28 #define COMPR_LEVEL_MASK (~((1 << COMPR_LEVEL_SHIFT) - 1)) +#define LLZ4FAST_MOD_NAME "crypto-llz4" +#define LLZ4HC_MOD_NAME "crypto-llz4hc" #define LGZIP_MOD_NAME "crypto-lgzip" #include diff --git a/lustre/lz4/Makefile.in b/lustre/lz4/Makefile.in index 74c6975..21b4eea 100644 --- a/lustre/lz4/Makefile.in +++ b/lustre/lz4/Makefile.in @@ -1,12 +1,12 @@ -MODULES := -EXTRA_DIST := +MODULES := +EXTRA_DIST := -@LZ4_TRUE@MODULES += lz4 -@LZ4_TRUE@lz4-objs := lz4_decompress.o lz4_compress.o llz4.o -@LZ4_TRUE@EXTRA_DIST += $(lz4-objs:.o=.c) lz4defs.h lz4.h scompress.h +MODULES += llz4 +llz4-objs := lz4_decompress.o lz4_compress.o lz4.o +EXTRA_DIST += $(llz4-objs:.o=.c) lz4defs.h lz4.h scompress.h -@LZ4HC_TRUE@MODULES += lz4hc -@LZ4HC_TRUE@lz4hc-objs := lz4_decompress.o lz4hc_compress.o llz4hc.o -@LZ4HC_TRUE@EXTRA_DIST += $(lz4hc-objs:.o=.c) lz4defs.h lz4.h scompress.h +MODULES += llz4hc +llz4hc-objs := lz4_decompress.o lz4hc_compress.o lz4hc.o +EXTRA_DIST += $(llz4hc-objs:.o=.c) lz4defs.h lz4.h scompress.h @INCLUDE_RULES@ diff --git a/lustre/lz4/autoMakefile.am b/lustre/lz4/autoMakefile.am index cfd9253..de4bd21 100644 --- a/lustre/lz4/autoMakefile.am +++ b/lustre/lz4/autoMakefile.am @@ -25,13 +25,7 @@ # if MODULES -modulefs_DATA := -if LZ4 -modulefs_DATA += lz4$(KMODEXT) -endif -if LZ4HC -modulefs_DATA += lz4hc$(KMODEXT) -endif +modulefs_DATA := llz4$(KMODEXT) llz4hc$(KMODEXT) endif MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ diff --git a/lustre/lz4/llz4.c b/lustre/lz4/lz4.c similarity index 98% rename from lustre/lz4/llz4.c rename to lustre/lz4/lz4.c index 3670003..1f0c0d4 100644 --- a/lustre/lz4/llz4.c +++ b/lustre/lz4/lz4.c @@ -120,7 +120,7 @@ static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src, static struct crypto_alg alg_lz4 = { .cra_name = "lz4", .cra_driver_name = "lz4-lustre-generic", - .cra_priority = 1, + .cra_priority = 110, .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, .cra_ctxsize = sizeof(struct lz4_ctx), .cra_module = THIS_MODULE, @@ -139,7 +139,7 @@ static struct scomp_alg scomp = { .base = { .cra_name = "lz4", .cra_driver_name = "lz4-lustre-scomp", - .cra_priority = 1, + .cra_priority = 110, .cra_module = THIS_MODULE, } }; @@ -172,4 +172,4 @@ module_exit(lz4_mod_fini); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("LZ4 Compression Algorithm"); -MODULE_ALIAS_CRYPTO("lz4"); +MODULE_ALIAS_CRYPTO("llz4"); diff --git a/lustre/lz4/llz4hc.c b/lustre/lz4/lz4hc.c similarity index 97% rename from lustre/lz4/llz4hc.c rename to lustre/lz4/lz4hc.c index 540bf2c..fb09e63 100644 --- a/lustre/lz4/llz4hc.c +++ b/lustre/lz4/lz4hc.c @@ -117,7 +117,7 @@ static int lz4hc_decompress_crypto(struct crypto_tfm *tfm, const u8 *src, static struct crypto_alg alg_lz4hc = { .cra_name = "lz4hc", .cra_driver_name = "lz4hc-lustre-generic", - .cra_priority = 1, + .cra_priority = 110, .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, .cra_ctxsize = sizeof(struct lz4hc_ctx), .cra_module = THIS_MODULE, @@ -136,7 +136,7 @@ static struct scomp_alg scomp = { .base = { .cra_name = "lz4hc", .cra_driver_name = "lz4hc-lustre-scomp", - .cra_priority = 1, + .cra_priority = 110, .cra_module = THIS_MODULE, } }; @@ -169,4 +169,4 @@ module_exit(lz4hc_mod_fini); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("LZ4HC Compression Algorithm"); -MODULE_ALIAS_CRYPTO("lz4hc"); +MODULE_ALIAS_CRYPTO("llz4hc"); diff --git a/lustre/osc/osc_compress.c b/lustre/osc/osc_compress.c index 9bed139..1ee7ce6 100644 --- a/lustre/osc/osc_compress.c +++ b/lustre/osc/osc_compress.c @@ -31,9 +31,10 @@ #include "osc_internal.h" #include "osc_compress.h" -/* "one-shot" try to load our own "lgzip" module +/* "one-shot" try to load our own compression modules * the first time that a compressed file is accessed */ +static bool tried_llz4_load = false; static bool tried_lgzip_load = false; static void merge_chunk(struct brw_page **pga, int first, int count, @@ -105,11 +106,17 @@ static int alloc_comp(enum ll_compr_type *type, unsigned int lvl, else if (*type == LL_COMPR_TYPE_FAST) *type = LL_COMPR_TYPE_LZ4FAST; - /* for deflate, try to use our built-in lgzip module */ - if (*type == LL_COMPR_TYPE_GZIP && !tried_lgzip_load) { - /* do not check request_module ret code, this is best effort - * as it will fail back to kernel's deflate - */ + /* Always try to use our built-in modules. + * Do not check request_module ret code, this is best effort + * as it will fail back to kernel's modules. + */ + if ((*type == LL_COMPR_TYPE_LZ4FAST || *type == LL_COMPR_TYPE_LZ4HC) && + unlikely(!tried_llz4_load)) { + /* lz4 and lz4hc are siblings, treat them together */ + request_module(LLZ4FAST_MOD_NAME); + request_module(LLZ4HC_MOD_NAME); + tried_llz4_load = true; + } else if (*type == LL_COMPR_TYPE_GZIP && unlikely(!tried_lgzip_load)) { request_module(LGZIP_MOD_NAME); tried_lgzip_load = true; } diff --git a/lustre/scripts/dkms.mkconf b/lustre/scripts/dkms.mkconf index 575d992..58c19e9 100755 --- a/lustre/scripts/dkms.mkconf +++ b/lustre/scripts/dkms.mkconf @@ -97,10 +97,10 @@ DEST_MODULE_LOCATION[\${#DEST_MODULE_LOCATION[@]}]="/${kmoddir}/lustre/" BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="lustre" BUILT_MODULE_LOCATION[\${#BUILT_MODULE_LOCATION[@]}]="lustre/llite/" DEST_MODULE_LOCATION[\${#DEST_MODULE_LOCATION[@]}]="/${kmoddir}/lustre/" -BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="lz4" +BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="llz4" BUILT_MODULE_LOCATION[\${#BUILT_MODULE_LOCATION[@]}]="lustre/lz4/" DEST_MODULE_LOCATION[\${#DEST_MODULE_LOCATION[@]}]="/${kmoddir}/lustre/" -BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="lz4hc" +BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="llz4hc" BUILT_MODULE_LOCATION[\${#BUILT_MODULE_LOCATION[@]}]="lustre/lz4/" DEST_MODULE_LOCATION[\${#DEST_MODULE_LOCATION[@]}]="/${kmoddir}/lustre/" BUILT_MODULE_NAME[\${#BUILT_MODULE_NAME[@]}]="lgzip" diff --git a/lustre/scripts/lustre_rmmod b/lustre/scripts/lustre_rmmod index 45b7dd8..e739735 100755 --- a/lustre/scripts/lustre_rmmod +++ b/lustre/scripts/lustre_rmmod @@ -89,7 +89,7 @@ done # is given. It's ugly, but is needed to emulate the prior functionality if [ "${#modules[@]}" -eq 0 ] || [ "${modules[*]}" = "ldiskfs" ]; then unload_all=true - modules=('lnet_selftest' 'ldiskfs' 'libcfs' 'lz4' 'lz4hc' 'lgzip') + modules=('lnet_selftest' 'ldiskfs' 'libcfs' 'llz4' 'llz4hc' 'lgzip') else unload_all=false fi diff --git a/lustre/tests/kernel/kcompr.c b/lustre/tests/kernel/kcompr.c index 83e803c..b25c446 100644 --- a/lustre/tests/kernel/kcompr.c +++ b/lustre/tests/kernel/kcompr.c @@ -177,11 +177,15 @@ int test_comp_compress_decompress(struct page *in_page, unsigned int order, goto free; } - /* for deflate, try to use our built-in lgzip module */ - if (strcmp(compr_name, "deflate") == 0) - /* do not check request_module ret code, this is best effort - * as it will fail back to kernel's deflate - */ + /* For lz4/lz4hc and lgzip, try to use our built-in modules. + * Do not check request_module ret code, this is best effort + * as it will fail back to kernel's deflate. + */ + if (strcmp(compr_name, "lz4") == 0) + request_module(LLZ4FAST_MOD_NAME); + else if (strcmp(compr_name, "lz4hc") == 0) + request_module(LLZ4HC_MOD_NAME); + else if (strcmp(compr_name, "deflate") == 0) request_module(LGZIP_MOD_NAME); cc = crypto_alloc_comp(compr_name, 0, 0); if (IS_ERR(cc)) { -- 1.8.3.1