ubifs: Add support for zstd compression.
authorMichele Dionisio <michele.dionisio@gmail.com>
Wed, 15 May 2019 21:02:02 +0000 (23:02 +0200)
committerRichard Weinberger <richard@nod.at>
Mon, 8 Jul 2019 17:43:53 +0000 (19:43 +0200)
zstd shows a good compression rate and is faster than lzo,
also on slow ARM cores.

Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Signed-off-by: Michele Dionisio <michele.dionisio@gmail.com>
[rw: rewrote commit message]
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/Kconfig
fs/ubifs/compress.c
fs/ubifs/super.c
fs/ubifs/ubifs-media.h

index 3902a677743e3bc036642d43af36c847d033de70..69932bcfa92081c1f6826216dcc05b663437a6bb 100644 (file)
@@ -6,8 +6,10 @@ config UBIFS_FS
        select CRYPTO if UBIFS_FS_ADVANCED_COMPR
        select CRYPTO if UBIFS_FS_LZO
        select CRYPTO if UBIFS_FS_ZLIB
+       select CRYPTO if UBIFS_FS_ZSTD
        select CRYPTO_LZO if UBIFS_FS_LZO
        select CRYPTO_DEFLATE if UBIFS_FS_ZLIB
+       select CRYPTO_ZSTD if UBIFS_FS_ZSTD
        select CRYPTO_HASH_INFO
        select UBIFS_FS_XATTR if FS_ENCRYPTION
        depends on MTD_UBI
@@ -38,6 +40,14 @@ config UBIFS_FS_ZLIB
        help
          Zlib compresses better than LZO but it is slower. Say 'Y' if unsure.
 
+config UBIFS_FS_ZSTD
+       bool "ZSTD compression support" if UBIFS_FS_ADVANCED_COMPR
+       depends on UBIFS_FS
+       default y
+       help
+         ZSTD compresses is a big win in speed over Zlib and
+         in compression ratio over LZO. Say 'Y' if unsure.
+
 config UBIFS_ATIME_SUPPORT
        bool "Access time support"
        default n
index 99c53ad11e93e360a99edaa1da30d2dbd30cd8dd..3a92e6af69b2296347c97adece77e85a2224e0ef 100644 (file)
@@ -59,6 +59,24 @@ static struct ubifs_compressor zlib_compr = {
 };
 #endif
 
+#ifdef CONFIG_UBIFS_FS_ZSTD
+static DEFINE_MUTEX(zstd_enc_mutex);
+static DEFINE_MUTEX(zstd_dec_mutex);
+
+static struct ubifs_compressor zstd_compr = {
+       .compr_type = UBIFS_COMPR_ZSTD,
+       .comp_mutex = &zstd_enc_mutex,
+       .decomp_mutex = &zstd_dec_mutex,
+       .name = "zstd",
+       .capi_name = "zstd",
+};
+#else
+static struct ubifs_compressor zstd_compr = {
+       .compr_type = UBIFS_COMPR_ZSTD,
+       .name = "zstd",
+};
+#endif
+
 /* All UBIFS compressors */
 struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
 
@@ -216,13 +234,19 @@ int __init ubifs_compressors_init(void)
        if (err)
                return err;
 
-       err = compr_init(&zlib_compr);
+       err = compr_init(&zstd_compr);
        if (err)
                goto out_lzo;
 
+       err = compr_init(&zlib_compr);
+       if (err)
+               goto out_zstd;
+
        ubifs_compressors[UBIFS_COMPR_NONE] = &none_compr;
        return 0;
 
+out_zstd:
+       compr_exit(&zstd_compr);
 out_lzo:
        compr_exit(&lzo_compr);
        return err;
@@ -235,4 +259,5 @@ void ubifs_compressors_exit(void)
 {
        compr_exit(&lzo_compr);
        compr_exit(&zlib_compr);
+       compr_exit(&zstd_compr);
 }
index 13b8f68f6c24c408cbf21331280429dcc5bacae5..5c472cca387675fdb0c7d166f36615873b3e21ad 100644 (file)
@@ -1045,6 +1045,8 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
                                c->mount_opts.compr_type = UBIFS_COMPR_LZO;
                        else if (!strcmp(name, "zlib"))
                                c->mount_opts.compr_type = UBIFS_COMPR_ZLIB;
+                       else if (!strcmp(name, "zstd"))
+                               c->mount_opts.compr_type = UBIFS_COMPR_ZSTD;
                        else {
                                ubifs_err(c, "unknown compressor \"%s\"", name); //FIXME: is c ready?
                                kfree(name);
index 355d3081d8828c18091b9f7570f32299970d2c5b..3c9792cbb6ffcacfbf69376703c74c5085a2d265 100644 (file)
@@ -340,12 +340,14 @@ enum {
  * UBIFS_COMPR_NONE: no compression
  * UBIFS_COMPR_LZO: LZO compression
  * UBIFS_COMPR_ZLIB: ZLIB compression
+ * UBIFS_COMPR_ZSTD: ZSTD compression
  * UBIFS_COMPR_TYPES_CNT: count of supported compression types
  */
 enum {
        UBIFS_COMPR_NONE,
        UBIFS_COMPR_LZO,
        UBIFS_COMPR_ZLIB,
+       UBIFS_COMPR_ZSTD,
        UBIFS_COMPR_TYPES_CNT,
 };