From 4b56f941f86786c072686043716177836020b4d3 Mon Sep 17 00:00:00 2001 From: Patrick Farrell Date: Tue, 9 Jan 2024 18:20:05 -0500 Subject: [PATCH] EX-6269 obd: add 'lvl' for best and fast 'best' and 'fast' compression types must also set a level, because not all levels are supported by all algorithms. Rather than trying to be clever, just use simple universally supported values, except for lz4fast, where we special case this, because otherwise '0' is the slowest setting (and lz4fast is likely to remain our default fastest). Signed-off-by: Patrick Farrell Change-Id: I7c29659d4f027af2e44285ae38e4c9d91e35509a Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53600 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Sebastien Buisson Reviewed-by: Andreas Dilger --- lustre/include/lustre_compr.h | 2 +- lustre/include/uapi/linux/lustre/lustre_user.h | 2 ++ lustre/obdclass/lustre_compr.c | 25 ++++++++++++++++++------- lustre/ofd/ofd_compress.c | 2 +- lustre/osc/osc_compress.c | 4 ++-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lustre/include/lustre_compr.h b/lustre/include/lustre_compr.h index 962ea74..3ccd308 100644 --- a/lustre/include/lustre_compr.h +++ b/lustre/include/lustre_compr.h @@ -29,7 +29,7 @@ #include int alloc_compr(const char *obd_name, enum ll_compr_type *type, - unsigned int lvl, struct crypto_comp **cc, bool decompress); + unsigned int *lvl, struct crypto_comp **cc, bool decompress); int compress_chunk(const char *obd_name, struct crypto_comp *cc, const unsigned char *in, unsigned int in_len, diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index e667dd4..be5c9da 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -2972,6 +2972,8 @@ enum ll_compr_type { LL_COMPR_TYPE_MAX, LL_COMPR_TYPE_UNCHANGED = 255 }; +/* lz4 levels go up to 27, but level is a 4 bit field, so we have a mapping */ +#define LL_LZ4FAST_MAX_LEVEL 15 #define COMPR_CHUNK_MIN_BITS 16 #define COMPR_GET_CHUNK_SIZE(log_bits) (1 << (log_bits + COMPR_CHUNK_MIN_BITS)) diff --git a/lustre/obdclass/lustre_compr.c b/lustre/obdclass/lustre_compr.c index b922e48..606eca5 100644 --- a/lustre/obdclass/lustre_compr.c +++ b/lustre/obdclass/lustre_compr.c @@ -174,7 +174,7 @@ void load_crypto_module(enum ll_compr_type type) #define compr_type_best LL_COMPR_TYPE_GZIP int alloc_compr(const char *obd_name, enum ll_compr_type *type, - unsigned int lvl, struct crypto_comp **cc, bool decompress) + unsigned int *lvl, struct crypto_comp **cc, bool decompress) { int ret = 0; @@ -190,15 +190,26 @@ int alloc_compr(const char *obd_name, enum ll_compr_type *type, LASSERT(ergo(decompress, *type != LL_COMPR_TYPE_BEST && *type != LL_COMPR_TYPE_FAST)); - if (*type == LL_COMPR_TYPE_BEST) + if (*type == LL_COMPR_TYPE_BEST) { *type = compr_type_best; - else if (*type == LL_COMPR_TYPE_FAST) + /* all compression types support a level 9 */ + *lvl = 9; + } else if (*type == LL_COMPR_TYPE_FAST) { *type = compr_type_fast; + /* lz4fast - our usual 'fast' interprets level as an + * acceleration factor, so special case that + */ + if (*type == LL_COMPR_TYPE_LZ4FAST) + *lvl = LL_LZ4FAST_MAX_LEVEL; + else + /* all compression types support a level 0 */ + *lvl = 0; + } load_crypto_module(*type); again: - *cc = crypto_alloc_comp(crypto_name_from_type(*type, lvl), 0, 0); + *cc = crypto_alloc_comp(crypto_name_from_type(*type, *lvl), 0, 0); if (IS_ERR(*cc)) { ret = PTR_ERR(*cc); CERROR("Cannot initialize compressor %i, error %i.\n", *type, @@ -233,10 +244,10 @@ out: if (ret) { *cc = NULL; } else /* success */ { - if (lvl != -1) - ll_crypto_comp_set_level(*cc, lvl); + if (*lvl != -1) + ll_crypto_comp_set_level(*cc, *lvl); CDEBUG(D_SEC, "%s: crypto_comp allocated, type %i, level %i\n", - obd_name, *type, lvl); + obd_name, *type, *lvl); } RETURN(ret); diff --git a/lustre/ofd/ofd_compress.c b/lustre/ofd/ofd_compress.c index 5e73e44..cfb87a5 100644 --- a/lustre/ofd/ofd_compress.c +++ b/lustre/ofd/ofd_compress.c @@ -83,7 +83,7 @@ static int decompress_chunk_in_lnb(const char *obd_name, type = llch->llch_compr_type; lvl = llch->llch_compr_level; hdr_size = llch->llch_header_size; - rc = alloc_compr(obd_name, &type, lvl, &cc, true); + rc = alloc_compr(obd_name, &type, &lvl, &cc, true); if (rc) { CERROR("%s: Setup for decompression failed, type %i, lvl %d, rc = %d\n", obd_name, type, lvl, rc); diff --git a/lustre/osc/osc_compress.c b/lustre/osc/osc_compress.c index d26b42c..0b9ef25 100644 --- a/lustre/osc/osc_compress.c +++ b/lustre/osc/osc_compress.c @@ -141,7 +141,7 @@ int compress_request(const char *obd_name, struct obdo *oa, src_buf_bits = chunk_bits + 1; dest_buf_bits = chunk_bits + 1; - rc = alloc_compr(obd_name, &type, lvl, &cc, false); + rc = alloc_compr(obd_name, &type, &lvl, &cc, false); /* if we're unable to setup compression, alloc_compr prints a warning * but we do not fail the IO - just write data uncompressed */ @@ -345,7 +345,7 @@ int decompress_request(struct osc_brw_async_args *aa, int page_count) buf_bits = chunk_bits + 1; pages_per_chunk = chunk_size / PAGE_SIZE; - rc = alloc_compr(obd_name, &type, lvl, &cc, true); + rc = alloc_compr(obd_name, &type, &lvl, &cc, true); if (rc) GOTO(out, rc); -- 1.8.3.1