Whamcloud - gitweb
EX-6269 obd: add 'lvl' for best and fast
authorPatrick Farrell <pfarrell@whamcloud.com>
Tue, 9 Jan 2024 23:20:05 +0000 (18:20 -0500)
committerAndreas Dilger <adilger@whamcloud.com>
Sat, 13 Jan 2024 02:43:48 +0000 (02:43 +0000)
'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 <pfarrell@whamcloud.com>
Change-Id: I7c29659d4f027af2e44285ae38e4c9d91e35509a
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53600
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/lustre_compr.h
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/obdclass/lustre_compr.c
lustre/ofd/ofd_compress.c
lustre/osc/osc_compress.c

index 962ea74..3ccd308 100644 (file)
@@ -29,7 +29,7 @@
 #include <linux/crypto.h>
 
 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,
index e667dd4..be5c9da 100644 (file)
@@ -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))
index b922e48..606eca5 100644 (file)
@@ -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);
index 5e73e44..cfb87a5 100644 (file)
@@ -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);
index d26b42c..0b9ef25 100644 (file)
@@ -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);