mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ubifs: Add zstd support
@ 2022-02-07 15:14 Sascha Hauer
  2022-06-23 10:45 ` Uwe Kleine-König
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2022-02-07 15:14 UTC (permalink / raw)
  To: Barebox List

zstd shows a good compression rate and is faster than lzo. This adds
UBIFS support for it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/ubifs/Kconfig       |  5 ++++
 fs/ubifs/ubifs-media.h |  2 ++
 fs/ubifs/ubifs.c       | 52 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+)

diff --git a/fs/ubifs/Kconfig b/fs/ubifs/Kconfig
index ae58c2b7f2..15fcec4459 100644
--- a/fs/ubifs/Kconfig
+++ b/fs/ubifs/Kconfig
@@ -17,4 +17,9 @@ config FS_UBIFS_COMPRESSION_ZLIB
 	select ZLIB
 	prompt "ZLIB compression support"
 
+config FS_UBIFS_COMPRESSION_ZSTD
+	bool
+	select ZSTD_DECOMPRESS
+	prompt "ZSTD compression support"
+
 endif
diff --git a/fs/ubifs/ubifs-media.h b/fs/ubifs/ubifs-media.h
index 8b7c184401..697b1b8906 100644
--- a/fs/ubifs/ubifs-media.h
+++ b/fs/ubifs/ubifs-media.h
@@ -348,12 +348,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,
 };
 
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index ced3d1f47f..88a4340a38 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -19,6 +19,7 @@
 #include <magicvar.h>
 #include <linux/stat.h>
 #include <linux/zlib.h>
+#include <linux/zstd.h>
 #include <linux/mtd/mtd.h>
 
 #include "ubifs.h"
@@ -33,6 +34,7 @@ struct ubifs_priv {
 
 static struct z_stream_s ubifs_zlib_stream;
 
+static ZSTD_DCtx *ubifs_zstd_cctx;
 
 /* compress.c */
 
@@ -48,6 +50,22 @@ static int gzip_decompress(const unsigned char *in, size_t in_len,
 }
 #endif
 
+#if defined(CONFIG_ZSTD_DECOMPRESS)
+static int zstd_decompress(const unsigned char *in, size_t in_len,
+			   unsigned char *out, size_t *out_len)
+{
+	size_t olen;
+
+	olen = ZSTD_decompressDCtx(ubifs_zstd_cctx, out, *out_len, in, in_len);
+	if (ZSTD_isError(olen))
+		return -EINVAL;
+
+	*out_len = olen;
+
+	return 0;
+}
+#endif
+
 /* Fake description object for the "none" compressor */
 static struct ubifs_compressor none_compr = {
 	.compr_type = UBIFS_COMPR_NONE,
@@ -74,6 +92,15 @@ static struct ubifs_compressor zlib_compr = {
 #endif
 };
 
+static struct ubifs_compressor zstd_compr = {
+	.compr_type = UBIFS_COMPR_ZSTD,
+	.name = "zstd",
+#ifdef CONFIG_ZSTD_DECOMPRESS
+	.capi_name = "zstd",
+	.decompress = zstd_decompress,
+#endif
+};
+
 /* All UBIFS compressors */
 struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
 
@@ -238,6 +265,10 @@ int __init ubifs_compressors_init(void)
 	if (err)
 		return err;
 
+	err = compr_init(&zstd_compr);
+	if (err)
+		return err;
+
 	err = compr_init(&none_compr);
 	if (err)
 		return err;
@@ -492,6 +523,21 @@ static int zlib_decomp_init(void)
 	return 0;
 }
 
+static int zstd_decomp_init(void)
+{
+	const size_t wksp_size = ZSTD_DCtxWorkspaceBound();
+	void *wksp = malloc(wksp_size);
+
+	if (!wksp)
+		return -ENOMEM;
+
+	ubifs_zstd_cctx = ZSTD_initDCtx(wksp, wksp_size);
+	if (!ubifs_zstd_cctx)
+		return -EINVAL;
+
+	return 0;
+}
+
 int ubifs_allow_encrypted;
 int ubifs_allow_authenticated_unauthenticated;
 
@@ -505,6 +551,12 @@ static int ubifs_init(void)
 			return ret;
 	}
 
+	if (IS_ENABLED(CONFIG_ZSTD_DECOMPRESS)) {
+		ret = zstd_decomp_init();
+		if (ret)
+			return ret;
+	}
+
 	globalvar_add_simple_bool("ubifs.allow_encrypted", &ubifs_allow_encrypted);
 	globalvar_add_simple_bool("ubifs.allow_authenticated_unauthenticated",
 				  &ubifs_allow_authenticated_unauthenticated);
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ubifs: Add zstd support
  2022-02-07 15:14 [PATCH] ubifs: Add zstd support Sascha Hauer
@ 2022-06-23 10:45 ` Uwe Kleine-König
  2022-06-24  8:16   ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König @ 2022-06-23 10:45 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

[-- Attachment #1: Type: text/plain, Size: 1120 bytes --]

Hello,

On Mon, Feb 07, 2022 at 04:14:57PM +0100, Sascha Hauer wrote:
> zstd shows a good compression rate and is faster than lzo. This adds
> UBIFS support for it.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

This patch is part of 2022.03.0 with commit cd1610d8ab30 ("ubifs: Add
zstd support")

Since then there is a warning in my imx builds (using imx_defconfig):

  CC      fs/ubifs/super.o
fs/ubifs/super.c: In function ‘validate_inode’:
fs/ubifs/super.c:89:28: warning: comparison is always false due to limited range of data type [-Wtype-limits]
   89 |         if (ui->compr_type >= UBIFS_COMPR_TYPES_CNT) {
      |                            ^~

That's because UBIFS_COMPR_TYPES_CNT is now 4 and ui->compr_type is an
unsigned int compr_type:2.

I wonder if the check should just be dropped now that all bits are used,
but I don't feel confident enough to say that's the right thing to do.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ubifs: Add zstd support
  2022-06-23 10:45 ` Uwe Kleine-König
@ 2022-06-24  8:16   ` Sascha Hauer
  0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2022-06-24  8:16 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Barebox List

On Thu, Jun 23, 2022 at 12:45:21PM +0200, Uwe Kleine-König wrote:
> Hello,
> 
> On Mon, Feb 07, 2022 at 04:14:57PM +0100, Sascha Hauer wrote:
> > zstd shows a good compression rate and is faster than lzo. This adds
> > UBIFS support for it.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> 
> This patch is part of 2022.03.0 with commit cd1610d8ab30 ("ubifs: Add
> zstd support")
> 
> Since then there is a warning in my imx builds (using imx_defconfig):
> 
>   CC      fs/ubifs/super.o
> fs/ubifs/super.c: In function ‘validate_inode’:
> fs/ubifs/super.c:89:28: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>    89 |         if (ui->compr_type >= UBIFS_COMPR_TYPES_CNT) {
>       |                            ^~
> 
> That's because UBIFS_COMPR_TYPES_CNT is now 4 and ui->compr_type is an
> unsigned int compr_type:2.

Same here.

> 
> I wonder if the check should just be dropped now that all bits are used,
> but I don't feel confident enough to say that's the right thing to do.

The code is the same in the Kernel, but the Kernel has -Wtype-limits
disabled.

I'd say we can remove this check. You could increase your kernel patch
count by suggesting the same there.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-24  8:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07 15:14 [PATCH] ubifs: Add zstd support Sascha Hauer
2022-06-23 10:45 ` Uwe Kleine-König
2022-06-24  8:16   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox