2018-03-21 12:31:31

by Geliang Tang

[permalink] [raw]
Subject: [PATCH] pstore: add zstd compression support

This patch added the 6th compression algorithm support for pstore: zstd.

Signed-off-by: Geliang Tang <[email protected]>
---
Depend on 'crypto: Add zstd support' by Nick Terrell <[email protected]>
---
fs/pstore/Kconfig | 17 ++++++++++++++---
fs/pstore/platform.c | 16 ++++++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 09c19ef91526..63cf4813559a 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -50,12 +50,19 @@ config PSTORE_842_COMPRESS
help
This option enables 842 compression algorithm support.

+config PSTORE_ZSTD_COMPRESS
+ tristate "zstd compression"
+ depends on PSTORE
+ select CRYPTO_ZSTD
+ help
+ This option enables zstd compression algorithm support.
+
config PSTORE_COMPRESS
def_bool y
depends on PSTORE
depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS || \
PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS || \
- PSTORE_842_COMPRESS
+ PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS

choice
prompt "Default pstore compression algorithm"
@@ -65,8 +72,8 @@ choice
This change be changed at boot with "pstore.compress=..." on
the kernel command line.

- Currently, pstore has support for 5 compression algorithms:
- deflate, lzo, lz4, lz4hc and 842.
+ Currently, pstore has support for 6 compression algorithms:
+ deflate, lzo, lz4, lz4hc, 842 and zstd.

The default compression algorithm is deflate.

@@ -85,6 +92,9 @@ choice
config PSTORE_842_COMPRESS_DEFAULT
bool "842" if PSTORE_842_COMPRESS

+ config PSTORE_ZSTD_COMPRESS_DEFAULT
+ bool "zstd" if PSTORE_ZSTD_COMPRESS
+
endchoice

config PSTORE_COMPRESS_DEFAULT
@@ -95,6 +105,7 @@ config PSTORE_COMPRESS_DEFAULT
default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
default "842" if PSTORE_842_COMPRESS_DEFAULT
+ default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT

config PSTORE_CONSOLE
bool "Log kernel console messages"
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 1143ef351c58..9df8cdc378f5 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -34,6 +34,9 @@
#if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
#include <linux/lz4.h>
#endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+#include <linux/zstd.h>
+#endif
#include <linux/crypto.h>
#include <linux/string.h>
#include <linux/timer.h>
@@ -192,6 +195,13 @@ static int zbufsize_842(size_t size)
}
#endif

+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+static int zbufsize_zstd(size_t size)
+{
+ return ZSTD_compressBound(size);
+}
+#endif
+
static const struct pstore_zbackend *zbackend __ro_after_init;

static const struct pstore_zbackend zbackends[] = {
@@ -224,6 +234,12 @@ static const struct pstore_zbackend zbackends[] = {
.zbufsize = zbufsize_842,
.name = "842",
},
+#endif
+#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
+ {
+ .zbufsize = zbufsize_zstd,
+ .name = "zstd",
+ },
#endif
{ }
};
--
2.14.1



2018-03-21 12:31:27

by Geliang Tang

[permalink] [raw]
Subject: [PATCH] pstore: rename two compression functions

We have following five functions which deal with pstore compression.
This patch renamed two functions to make the names of those functions
consistent:

allocate_buf_for_compression -> pstore_init_compression
free_buf_for_compression -> pstore_free_compression
pstore_choose_compression pstore_choose_compression
pstore_compress pstore_compress
pstore_decompress pstore_decompress

Signed-off-by: Geliang Tang <[email protected]>
---
fs/pstore/platform.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 1143ef351c58..03d16b6ed5ec 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -256,7 +256,7 @@ static int pstore_decompress(void *in, void *out,
return outlen;
}

-static void allocate_buf_for_compression(void)
+static void pstore_init_compression(void)
{
if (!zbackend)
return;
@@ -285,7 +285,7 @@ static void allocate_buf_for_compression(void)
}
}

-static void free_buf_for_compression(void)
+static void pstore_free_compression(void)
{
if (!IS_ERR_OR_NULL(tfm))
crypto_free_comp(tfm);
@@ -560,7 +560,7 @@ int pstore_register(struct pstore_info *psi)
return -EINVAL;
}

- allocate_buf_for_compression();
+ pstore_init_compression();

if (pstore_is_mounted())
pstore_get_records(0);
@@ -611,7 +611,7 @@ void pstore_unregister(struct pstore_info *psi)
if (psi->flags & PSTORE_FLAGS_DMESG)
pstore_unregister_kmsg();

- free_buf_for_compression();
+ pstore_free_compression();

psinfo = NULL;
backend = NULL;
--
2.14.1


2018-03-21 12:32:15

by Geliang Tang

[permalink] [raw]
Subject: [PATCH] pstore: set PSTORE_842_COMPRESS tristate

This patch sets PSTORE_842_COMPRESS 'tristate' like other pstore
compression algorithms in Kconfig.

Signed-off-by: Geliang Tang <[email protected]>
---
fs/pstore/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
index 09c19ef91526..a80c9bc0fbfc 100644
--- a/fs/pstore/Kconfig
+++ b/fs/pstore/Kconfig
@@ -44,7 +44,7 @@ config PSTORE_LZ4HC_COMPRESS
This option enables LZ4HC (high compression) mode algorithm.

config PSTORE_842_COMPRESS
- bool "842 compression"
+ tristate "842 compression"
depends on PSTORE
select CRYPTO_842
help
--
2.14.1


2018-04-23 08:05:02

by Geliang Tang

[permalink] [raw]
Subject: Re: [PATCH] pstore: add zstd compression support

On Wed, Mar 21, 2018 at 08:29:31PM +0800, Geliang Tang wrote:
> This patch added the 6th compression algorithm support for pstore: zstd.
>
> Signed-off-by: Geliang Tang <[email protected]>
> ---
> Depend on 'crypto: Add zstd support' by Nick Terrell <[email protected]>

Hi Kees,

The patch 'crypto: zstd - Add zstd support' has been applied to
linux-next tree, 20180423, already. So we can use zstd in pstore
compression now. Please reconsider if my patch can be applied.

Thanks.
-Geliang

> ---
> fs/pstore/Kconfig | 17 ++++++++++++++---
> fs/pstore/platform.c | 16 ++++++++++++++++
> 2 files changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
> index 09c19ef91526..63cf4813559a 100644
> --- a/fs/pstore/Kconfig
> +++ b/fs/pstore/Kconfig
> @@ -50,12 +50,19 @@ config PSTORE_842_COMPRESS
> help
> This option enables 842 compression algorithm support.
>
> +config PSTORE_ZSTD_COMPRESS
> + tristate "zstd compression"
> + depends on PSTORE
> + select CRYPTO_ZSTD
> + help
> + This option enables zstd compression algorithm support.
> +
> config PSTORE_COMPRESS
> def_bool y
> depends on PSTORE
> depends on PSTORE_DEFLATE_COMPRESS || PSTORE_LZO_COMPRESS || \
> PSTORE_LZ4_COMPRESS || PSTORE_LZ4HC_COMPRESS || \
> - PSTORE_842_COMPRESS
> + PSTORE_842_COMPRESS || PSTORE_ZSTD_COMPRESS
>
> choice
> prompt "Default pstore compression algorithm"
> @@ -65,8 +72,8 @@ choice
> This change be changed at boot with "pstore.compress=..." on
> the kernel command line.
>
> - Currently, pstore has support for 5 compression algorithms:
> - deflate, lzo, lz4, lz4hc and 842.
> + Currently, pstore has support for 6 compression algorithms:
> + deflate, lzo, lz4, lz4hc, 842 and zstd.
>
> The default compression algorithm is deflate.
>
> @@ -85,6 +92,9 @@ choice
> config PSTORE_842_COMPRESS_DEFAULT
> bool "842" if PSTORE_842_COMPRESS
>
> + config PSTORE_ZSTD_COMPRESS_DEFAULT
> + bool "zstd" if PSTORE_ZSTD_COMPRESS
> +
> endchoice
>
> config PSTORE_COMPRESS_DEFAULT
> @@ -95,6 +105,7 @@ config PSTORE_COMPRESS_DEFAULT
> default "lz4" if PSTORE_LZ4_COMPRESS_DEFAULT
> default "lz4hc" if PSTORE_LZ4HC_COMPRESS_DEFAULT
> default "842" if PSTORE_842_COMPRESS_DEFAULT
> + default "zstd" if PSTORE_ZSTD_COMPRESS_DEFAULT
>
> config PSTORE_CONSOLE
> bool "Log kernel console messages"
> diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
> index 1143ef351c58..9df8cdc378f5 100644
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
> @@ -34,6 +34,9 @@
> #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
> #include <linux/lz4.h>
> #endif
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> +#include <linux/zstd.h>
> +#endif
> #include <linux/crypto.h>
> #include <linux/string.h>
> #include <linux/timer.h>
> @@ -192,6 +195,13 @@ static int zbufsize_842(size_t size)
> }
> #endif
>
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> +static int zbufsize_zstd(size_t size)
> +{
> + return ZSTD_compressBound(size);
> +}
> +#endif
> +
> static const struct pstore_zbackend *zbackend __ro_after_init;
>
> static const struct pstore_zbackend zbackends[] = {
> @@ -224,6 +234,12 @@ static const struct pstore_zbackend zbackends[] = {
> .zbufsize = zbufsize_842,
> .name = "842",
> },
> +#endif
> +#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS)
> + {
> + .zbufsize = zbufsize_zstd,
> + .name = "zstd",
> + },
> #endif
> { }
> };
> --
> 2.14.1