All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tao Liu <ltao@redhat.com>
To: kexec@lists.infradead.org
Cc: k-hagio-ab@nec.com, Tao Liu <ltao@redhat.com>,
	Coiby Xu <coxu@redhat.com>
Subject: [PATCH 05/11] makedumpfile: Add single thread zstd compression processing
Date: Fri, 10 Sep 2021 18:33:12 +0800	[thread overview]
Message-ID: <20210910103318.292017-6-ltao@redhat.com> (raw)
In-Reply-To: <20210910103318.292017-1-ltao@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
---
 makedumpfile.c | 41 ++++++++++++++++++++++++++++++++++++-----
 makedumpfile.h |  3 +++
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/makedumpfile.c b/makedumpfile.c
index f3bf297..76a7a77 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -296,18 +296,20 @@ is_cache_page(unsigned long flags)
 static inline unsigned long
 calculate_len_buf_out(long page_size)
 {
-	unsigned long zlib = compressBound(page_size);
-	unsigned long lzo = 0;
-	unsigned long snappy = 0;
+	unsigned long zlib, lzo, snappy, zstd;
+	zlib = lzo = snappy = zstd = 0;
 
+	zlib = compressBound(page_size);
 #ifdef USELZO
 	lzo = page_size + page_size / 16 + 64 + 3;
 #endif
 #ifdef USESNAPPY
 	snappy = snappy_max_compressed_length(page_size);
 #endif
-
-	return MAX(zlib, MAX(lzo, snappy));
+#ifdef USEZSTD
+	zstd = ZSTD_compressBound(page_size);
+#endif
+	return MAX(zlib, MAX(lzo, MAX(snappy, zstd)));
 }
 
 #define BITMAP_SECT_LEN 4096
@@ -7298,6 +7300,10 @@ write_kdump_header(void)
 	else if (info->flag_compress & DUMP_DH_COMPRESSED_SNAPPY)
 		dh->status |= DUMP_DH_COMPRESSED_SNAPPY;
 #endif
+#ifdef USEZSTD
+	else if (info->flag_compress & DUMP_DH_COMPRESSED_ZSTD)
+		dh->status |= DUMP_DH_COMPRESSED_ZSTD;
+#endif
 
 	size = sizeof(struct disk_dump_header);
 	if (!write_buffer(info->fd_dumpfile, 0, dh, size, info->name_dumpfile))
@@ -8567,6 +8573,9 @@ write_kdump_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_pag
 #ifdef USELZO
 	lzo_bytep wrkmem = NULL;
 #endif
+#ifdef USEZSTD
+	ZSTD_CCtx *cctx = NULL;
+#endif
 
 	if (info->flag_elf_dumpfile)
 		return FALSE;
@@ -8586,6 +8595,14 @@ write_kdump_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_pag
 		goto out;
 	}
 #endif
+#ifdef USEZSTD
+	if (info->flag_compress & DUMP_DH_COMPRESSED_ZSTD) {
+		if ((cctx = ZSTD_createCCtx()) == NULL) {
+			ERRMSG("Can't allocate ZSTD_CCtx.\n");
+			goto out;
+		}
+	}
+#endif
 
 	len_buf_out = calculate_len_buf_out(info->page_size);
 
@@ -8668,6 +8685,16 @@ write_kdump_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_pag
 			   && (size_out < info->page_size)) {
 			pd.flags = DUMP_DH_COMPRESSED_SNAPPY;
 			pd.size  = size_out;
+#endif
+#ifdef USEZSTD
+		} else if ((info->flag_compress & DUMP_DH_COMPRESSED_ZSTD)
+			    && (size_out = ZSTD_compressCCtx(cctx,
+						buf_out, len_buf_out,
+						buf, info->page_size, ZSTD_dfast))
+			    && (!ZSTD_isError(size_out))
+			    && (size_out < info->page_size)) {
+			pd.flags = DUMP_DH_COMPRESSED_ZSTD;
+			pd.size  = size_out;
 #endif
 		} else {
 			pd.flags = 0;
@@ -8688,6 +8715,10 @@ write_kdump_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_pag
 out:
 	if (buf_out != NULL)
 		free(buf_out);
+#ifdef USEZSTD
+	if (cctx != NULL)
+		ZSTD_freeCCtx(cctx);
+#endif
 #ifdef USELZO
 	if (wrkmem != NULL)
 		free(wrkmem);
diff --git a/makedumpfile.h b/makedumpfile.h
index 46d77b0..a1a8cc2 100644
--- a/makedumpfile.h
+++ b/makedumpfile.h
@@ -38,6 +38,9 @@
 #ifdef USESNAPPY
 #include <snappy-c.h>
 #endif
+#ifdef USEZSTD
+#include <zstd.h>
+#endif
 #include "common.h"
 #include "dwarf_info.h"
 #include "diskdump_mod.h"
-- 
2.29.2


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

  parent reply	other threads:[~2021-09-10 10:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 10:33 [PATCH 00/11] makedumpfile: Add zstd support for makedumpfile Tao Liu
2021-09-10 10:33 ` [PATCH 01/11] makedumpfile: Add dump header for zstd Tao Liu
2021-09-10 10:33 ` [PATCH 02/11] makedumpfile: Add command-line processing " Tao Liu
2021-09-10 10:33 ` [PATCH 03/11] makedumpfile: Add zstd build support Tao Liu
2021-09-10 10:33 ` [PATCH 04/11] makedumpfile: Notify zstd unsupporting when disabled Tao Liu
2021-09-10 10:33 ` Tao Liu [this message]
2021-09-10 10:33 ` [PATCH 06/11] makedumpfile: Add parallel threads zstd compression processing Tao Liu
2021-09-10 10:33 ` [PATCH 07/11] makedumpfile: Add single thread zstd uncompression processing Tao Liu
2021-09-10 10:33 ` [PATCH 08/11] makedumpfile: Add parallel threads " Tao Liu
2021-09-10 10:33 ` [PATCH 09/11] makedumpfile: Add zstd help message Tao Liu
2021-09-10 10:33 ` [PATCH 10/11] makedumpfile: Add zstd manual description Tao Liu
2021-09-10 10:33 ` [PATCH 11/11] makedumpfile: Add zstd README description Tao Liu
2021-09-14  7:04 ` [PATCH 00/11] makedumpfile: Add zstd support for makedumpfile HAGIO KAZUHITO(萩尾 一仁)
2021-09-14  8:33   ` Tao Liu
2021-09-17  1:34     ` HAGIO KAZUHITO(萩尾 一仁)
2021-09-17  2:31       ` HAGIO KAZUHITO(萩尾 一仁)
2021-09-17  7:03         ` HAGIO KAZUHITO(萩尾 一仁)
2021-09-21  9:26           ` Tao Liu
2021-09-22  2:21             ` HAGIO KAZUHITO(萩尾 一仁)
2021-09-22  8:16               ` HAGIO KAZUHITO(萩尾 一仁)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210910103318.292017-6-ltao@redhat.com \
    --to=ltao@redhat.com \
    --cc=coxu@redhat.com \
    --cc=k-hagio-ab@nec.com \
    --cc=kexec@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.