Skip to content

Commit eeabb98

Browse files
mdionisiorichardweinberger
authored andcommitted
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 <[email protected]> Signed-off-by: Michele Dionisio <[email protected]> [rw: rewrote commit message] Signed-off-by: Richard Weinberger <[email protected]>
1 parent 817aa09 commit eeabb98

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

fs/ubifs/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ config UBIFS_FS
66
select CRYPTO if UBIFS_FS_ADVANCED_COMPR
77
select CRYPTO if UBIFS_FS_LZO
88
select CRYPTO if UBIFS_FS_ZLIB
9+
select CRYPTO if UBIFS_FS_ZSTD
910
select CRYPTO_LZO if UBIFS_FS_LZO
1011
select CRYPTO_DEFLATE if UBIFS_FS_ZLIB
12+
select CRYPTO_ZSTD if UBIFS_FS_ZSTD
1113
select CRYPTO_HASH_INFO
1214
select UBIFS_FS_XATTR if FS_ENCRYPTION
1315
depends on MTD_UBI
@@ -38,6 +40,14 @@ config UBIFS_FS_ZLIB
3840
help
3941
Zlib compresses better than LZO but it is slower. Say 'Y' if unsure.
4042

43+
config UBIFS_FS_ZSTD
44+
bool "ZSTD compression support" if UBIFS_FS_ADVANCED_COMPR
45+
depends on UBIFS_FS
46+
default y
47+
help
48+
ZSTD compresses is a big win in speed over Zlib and
49+
in compression ratio over LZO. Say 'Y' if unsure.
50+
4151
config UBIFS_ATIME_SUPPORT
4252
bool "Access time support"
4353
default n

fs/ubifs/compress.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ static struct ubifs_compressor zlib_compr = {
5959
};
6060
#endif
6161

62+
#ifdef CONFIG_UBIFS_FS_ZSTD
63+
static DEFINE_MUTEX(zstd_enc_mutex);
64+
static DEFINE_MUTEX(zstd_dec_mutex);
65+
66+
static struct ubifs_compressor zstd_compr = {
67+
.compr_type = UBIFS_COMPR_ZSTD,
68+
.comp_mutex = &zstd_enc_mutex,
69+
.decomp_mutex = &zstd_dec_mutex,
70+
.name = "zstd",
71+
.capi_name = "zstd",
72+
};
73+
#else
74+
static struct ubifs_compressor zstd_compr = {
75+
.compr_type = UBIFS_COMPR_ZSTD,
76+
.name = "zstd",
77+
};
78+
#endif
79+
6280
/* All UBIFS compressors */
6381
struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
6482

@@ -216,13 +234,19 @@ int __init ubifs_compressors_init(void)
216234
if (err)
217235
return err;
218236

219-
err = compr_init(&zlib_compr);
237+
err = compr_init(&zstd_compr);
220238
if (err)
221239
goto out_lzo;
222240

241+
err = compr_init(&zlib_compr);
242+
if (err)
243+
goto out_zstd;
244+
223245
ubifs_compressors[UBIFS_COMPR_NONE] = &none_compr;
224246
return 0;
225247

248+
out_zstd:
249+
compr_exit(&zstd_compr);
226250
out_lzo:
227251
compr_exit(&lzo_compr);
228252
return err;
@@ -235,4 +259,5 @@ void ubifs_compressors_exit(void)
235259
{
236260
compr_exit(&lzo_compr);
237261
compr_exit(&zlib_compr);
262+
compr_exit(&zstd_compr);
238263
}

fs/ubifs/super.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,8 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,
10451045
c->mount_opts.compr_type = UBIFS_COMPR_LZO;
10461046
else if (!strcmp(name, "zlib"))
10471047
c->mount_opts.compr_type = UBIFS_COMPR_ZLIB;
1048+
else if (!strcmp(name, "zstd"))
1049+
c->mount_opts.compr_type = UBIFS_COMPR_ZSTD;
10481050
else {
10491051
ubifs_err(c, "unknown compressor \"%s\"", name); //FIXME: is c ready?
10501052
kfree(name);

fs/ubifs/ubifs-media.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,14 @@ enum {
340340
* UBIFS_COMPR_NONE: no compression
341341
* UBIFS_COMPR_LZO: LZO compression
342342
* UBIFS_COMPR_ZLIB: ZLIB compression
343+
* UBIFS_COMPR_ZSTD: ZSTD compression
343344
* UBIFS_COMPR_TYPES_CNT: count of supported compression types
344345
*/
345346
enum {
346347
UBIFS_COMPR_NONE,
347348
UBIFS_COMPR_LZO,
348349
UBIFS_COMPR_ZLIB,
350+
UBIFS_COMPR_ZSTD,
349351
UBIFS_COMPR_TYPES_CNT,
350352
};
351353

0 commit comments

Comments
 (0)