Commit eeabb986 authored by Michele Dionisio's avatar Michele Dionisio Committed by Richard Weinberger

ubifs: Add support for zstd compression.

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: default avatarMichele Dionisio <michele.dionisio@gmail.com>
[rw: rewrote commit message]
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent 817aa094
...@@ -6,8 +6,10 @@ config UBIFS_FS ...@@ -6,8 +6,10 @@ config UBIFS_FS
select CRYPTO if UBIFS_FS_ADVANCED_COMPR select CRYPTO if UBIFS_FS_ADVANCED_COMPR
select CRYPTO if UBIFS_FS_LZO select CRYPTO if UBIFS_FS_LZO
select CRYPTO if UBIFS_FS_ZLIB select CRYPTO if UBIFS_FS_ZLIB
select CRYPTO if UBIFS_FS_ZSTD
select CRYPTO_LZO if UBIFS_FS_LZO select CRYPTO_LZO if UBIFS_FS_LZO
select CRYPTO_DEFLATE if UBIFS_FS_ZLIB select CRYPTO_DEFLATE if UBIFS_FS_ZLIB
select CRYPTO_ZSTD if UBIFS_FS_ZSTD
select CRYPTO_HASH_INFO select CRYPTO_HASH_INFO
select UBIFS_FS_XATTR if FS_ENCRYPTION select UBIFS_FS_XATTR if FS_ENCRYPTION
depends on MTD_UBI depends on MTD_UBI
...@@ -38,6 +40,14 @@ config UBIFS_FS_ZLIB ...@@ -38,6 +40,14 @@ config UBIFS_FS_ZLIB
help help
Zlib compresses better than LZO but it is slower. Say 'Y' if unsure. 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 config UBIFS_ATIME_SUPPORT
bool "Access time support" bool "Access time support"
default n default n
......
...@@ -59,6 +59,24 @@ static struct ubifs_compressor zlib_compr = { ...@@ -59,6 +59,24 @@ static struct ubifs_compressor zlib_compr = {
}; };
#endif #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 */ /* All UBIFS compressors */
struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT]; struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
...@@ -216,13 +234,19 @@ int __init ubifs_compressors_init(void) ...@@ -216,13 +234,19 @@ int __init ubifs_compressors_init(void)
if (err) if (err)
return err; return err;
err = compr_init(&zlib_compr); err = compr_init(&zstd_compr);
if (err) if (err)
goto out_lzo; goto out_lzo;
err = compr_init(&zlib_compr);
if (err)
goto out_zstd;
ubifs_compressors[UBIFS_COMPR_NONE] = &none_compr; ubifs_compressors[UBIFS_COMPR_NONE] = &none_compr;
return 0; return 0;
out_zstd:
compr_exit(&zstd_compr);
out_lzo: out_lzo:
compr_exit(&lzo_compr); compr_exit(&lzo_compr);
return err; return err;
...@@ -235,4 +259,5 @@ void ubifs_compressors_exit(void) ...@@ -235,4 +259,5 @@ void ubifs_compressors_exit(void)
{ {
compr_exit(&lzo_compr); compr_exit(&lzo_compr);
compr_exit(&zlib_compr); compr_exit(&zlib_compr);
compr_exit(&zstd_compr);
} }
...@@ -1045,6 +1045,8 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options, ...@@ -1045,6 +1045,8 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
c->mount_opts.compr_type = UBIFS_COMPR_LZO; c->mount_opts.compr_type = UBIFS_COMPR_LZO;
else if (!strcmp(name, "zlib")) else if (!strcmp(name, "zlib"))
c->mount_opts.compr_type = UBIFS_COMPR_ZLIB; c->mount_opts.compr_type = UBIFS_COMPR_ZLIB;
else if (!strcmp(name, "zstd"))
c->mount_opts.compr_type = UBIFS_COMPR_ZSTD;
else { else {
ubifs_err(c, "unknown compressor \"%s\"", name); //FIXME: is c ready? ubifs_err(c, "unknown compressor \"%s\"", name); //FIXME: is c ready?
kfree(name); kfree(name);
......
...@@ -340,12 +340,14 @@ enum { ...@@ -340,12 +340,14 @@ enum {
* UBIFS_COMPR_NONE: no compression * UBIFS_COMPR_NONE: no compression
* UBIFS_COMPR_LZO: LZO compression * UBIFS_COMPR_LZO: LZO compression
* UBIFS_COMPR_ZLIB: ZLIB compression * UBIFS_COMPR_ZLIB: ZLIB compression
* UBIFS_COMPR_ZSTD: ZSTD compression
* UBIFS_COMPR_TYPES_CNT: count of supported compression types * UBIFS_COMPR_TYPES_CNT: count of supported compression types
*/ */
enum { enum {
UBIFS_COMPR_NONE, UBIFS_COMPR_NONE,
UBIFS_COMPR_LZO, UBIFS_COMPR_LZO,
UBIFS_COMPR_ZLIB, UBIFS_COMPR_ZLIB,
UBIFS_COMPR_ZSTD,
UBIFS_COMPR_TYPES_CNT, UBIFS_COMPR_TYPES_CNT,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment