|
Aleksandr Kazakov |
35d714 |
From a5803faa083690526b96484c7e6a4cc915ca3921 Mon Nov 28 16:35:09 2022
|
|
Aleksandr Kazakov |
35d714 |
From: Aleksandr Kazakov <alexkazakov@meta.com>
|
|
Aleksandr Kazakov |
35d714 |
Date: Mon, 28 Nov 2022 16:35:09 +0000
|
|
Aleksandr Kazakov |
35d714 |
Subject: [PATCH] Backport multi-threaded zstd to 4.14.x to support
|
|
Aleksandr Kazakov |
35d714 |
multi-threaded zstd compression on centos 8
|
|
Aleksandr Kazakov |
35d714 |
|
|
Aleksandr Kazakov |
35d714 |
Signed-off-by: Aleksandr Kazakov <alexkazakov@meta.com>
|
|
Aleksandr Kazakov |
35d714 |
---
|
|
Aleksandr Kazakov |
35d714 |
configure.ac | 2 +-
|
|
Aleksandr Kazakov |
35d714 |
macros.in | 1 +
|
|
Aleksandr Kazakov |
35d714 |
rpmio/rpmio.c | 82 +++++++++++++++++++++++++++++++++++----------------
|
|
Aleksandr Kazakov |
35d714 |
3 files changed, 58 insertions(+), 27 deletions(-)
|
|
Aleksandr Kazakov |
35d714 |
|
|
Aleksandr Kazakov |
35d714 |
diff --git a/configure.ac b/configure.ac
|
|
Aleksandr Kazakov |
35d714 |
index 47327bd..b1213ae 100644
|
|
Aleksandr Kazakov |
35d714 |
--- a/configure.ac
|
|
Aleksandr Kazakov |
35d714 |
+++ b/configure.ac
|
|
Aleksandr Kazakov |
35d714 |
@@ -214,7 +214,7 @@ AC_ARG_ENABLE([zstd],
|
|
Aleksandr Kazakov |
35d714 |
[enable_zstd=auto])
|
|
Aleksandr Kazakov |
35d714 |
|
|
Aleksandr Kazakov |
35d714 |
AS_IF([test "x$enable_zstd" != "xno"], [
|
|
Aleksandr Kazakov |
35d714 |
- PKG_CHECK_MODULES([ZSTD], [libzstd], [have_zstd=yes], [have_zstd=no])
|
|
Aleksandr Kazakov |
35d714 |
+ PKG_CHECK_MODULES([ZSTD], [libzstd >= 1.3.8], [have_zstd=yes], [have_zstd=no])
|
|
Aleksandr Kazakov |
35d714 |
AS_IF([test "$enable_zstd" = "yes"], [
|
|
Aleksandr Kazakov |
35d714 |
if test "$have_zstd" = "no"; then
|
|
Aleksandr Kazakov |
35d714 |
AC_MSG_ERROR([--enable-zstd specified, but not available])
|
|
Aleksandr Kazakov |
35d714 |
diff --git a/macros.in b/macros.in
|
|
Aleksandr Kazakov |
35d714 |
index 9b9fe23..832b60a 100644
|
|
Aleksandr Kazakov |
35d714 |
--- a/macros.in
|
|
Aleksandr Kazakov |
35d714 |
+++ b/macros.in
|
|
Aleksandr Kazakov |
35d714 |
@@ -394,6 +394,7 @@ package or when debugging this package.\
|
|
Aleksandr Kazakov |
35d714 |
# "w9.bzdio" bzip2 level 9.
|
|
Aleksandr Kazakov |
35d714 |
# "w6.xzdio" xz level 6, xz's default.
|
|
Aleksandr Kazakov |
35d714 |
# "w7T16.xzdio" xz level 7 using 16 thread (xz only)
|
|
Aleksandr Kazakov |
35d714 |
+# "w19T8.zstdio" zstd level 19 using 8 threads
|
|
Aleksandr Kazakov |
35d714 |
# "w6.lzdio" lzma-alone level 6, lzma's default
|
|
Aleksandr Kazakov |
35d714 |
#
|
|
Aleksandr Kazakov |
35d714 |
#%_source_payload w9.gzdio
|
|
Aleksandr Kazakov |
35d714 |
diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c
|
|
Aleksandr Kazakov |
35d714 |
index 09b5d02..d030a9c 100644
|
|
Aleksandr Kazakov |
35d714 |
--- a/rpmio/rpmio.c
|
|
Aleksandr Kazakov |
35d714 |
+++ b/rpmio/rpmio.c
|
|
Aleksandr Kazakov |
35d714 |
@@ -1070,6 +1070,7 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode)
|
|
Aleksandr Kazakov |
35d714 |
char *t = stdio;
|
|
Aleksandr Kazakov |
35d714 |
char *te = t + sizeof(stdio) - 2;
|
|
Aleksandr Kazakov |
35d714 |
int c;
|
|
Aleksandr Kazakov |
35d714 |
+ int threads = 0;
|
|
Aleksandr Kazakov |
35d714 |
|
|
Aleksandr Kazakov |
35d714 |
switch ((c = *s++)) {
|
|
Aleksandr Kazakov |
35d714 |
case 'a':
|
|
Aleksandr Kazakov |
35d714 |
@@ -1098,7 +1099,14 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode)
|
|
Aleksandr Kazakov |
35d714 |
flags &= ~O_ACCMODE;
|
|
Aleksandr Kazakov |
35d714 |
flags |= O_RDWR;
|
|
Aleksandr Kazakov |
35d714 |
continue;
|
|
Aleksandr Kazakov |
35d714 |
- break;
|
|
Aleksandr Kazakov |
35d714 |
+ case 'T':
|
|
Aleksandr Kazakov |
35d714 |
+ if (*s >= '0' && *s <= '9') {
|
|
Aleksandr Kazakov |
35d714 |
+ threads = strtol(s, (char **)&s, 10);
|
|
Aleksandr Kazakov |
35d714 |
+ /* T0 means automatic detection */
|
|
Aleksandr Kazakov |
35d714 |
+ if (threads == 0)
|
|
Aleksandr Kazakov |
35d714 |
+ threads = sysconf(_SC_NPROCESSORS_ONLN);
|
|
Aleksandr Kazakov |
35d714 |
+ }
|
|
Aleksandr Kazakov |
35d714 |
+ continue;
|
|
Aleksandr Kazakov |
35d714 |
default:
|
|
Aleksandr Kazakov |
35d714 |
if (c >= (int)'0' && c <= (int)'9') {
|
|
Aleksandr Kazakov |
35d714 |
level = strtol(s-1, (char **)&s, 10);
|
|
Aleksandr Kazakov |
35d714 |
@@ -1132,10 +1140,16 @@ static rpmzstd rpmzstdNew(int fdno, const char *fmode)
|
|
Aleksandr Kazakov |
35d714 |
}
|
|
Aleksandr Kazakov |
35d714 |
nb = ZSTD_DStreamInSize();
|
|
Aleksandr Kazakov |
35d714 |
} else { /* compressing */
|
|
Aleksandr Kazakov |
35d714 |
- if ((_stream = (void *) ZSTD_createCStream()) == NULL
|
|
Aleksandr Kazakov |
35d714 |
- || ZSTD_isError(ZSTD_initCStream(_stream, level))) {
|
|
Aleksandr Kazakov |
35d714 |
+ if ((_stream = (void *) ZSTD_createCCtx()) == NULL
|
|
Aleksandr Kazakov |
35d714 |
+ || ZSTD_isError(ZSTD_CCtx_setParameter(_stream, ZSTD_c_compressionLevel, level))) {
|
|
Aleksandr Kazakov |
35d714 |
goto err;
|
|
Aleksandr Kazakov |
35d714 |
}
|
|
Aleksandr Kazakov |
35d714 |
+
|
|
Aleksandr Kazakov |
35d714 |
+ rpmlog(RPMLOG_DEBUG, "using %i threads in zstd compression\n", threads);
|
|
Aleksandr Kazakov |
35d714 |
+ if (threads > 0) {
|
|
Aleksandr Kazakov |
35d714 |
+ if (ZSTD_isError (ZSTD_CCtx_setParameter(_stream, ZSTD_c_nbWorkers, threads)))
|
|
Aleksandr Kazakov |
35d714 |
+ rpmlog(RPMLOG_WARNING, "zstd library does not support multi-threading\n");
|
|
Aleksandr Kazakov |
35d714 |
+ }
|
|
Aleksandr Kazakov |
35d714 |
nb = ZSTD_CStreamOutSize();
|
|
Aleksandr Kazakov |
35d714 |
}
|
|
Aleksandr Kazakov |
35d714 |
|
|
Aleksandr Kazakov |
35d714 |
@@ -1155,7 +1169,7 @@ err:
|
|
Aleksandr Kazakov |
35d714 |
if ((flags & O_ACCMODE) == O_RDONLY)
|
|
Aleksandr Kazakov |
35d714 |
ZSTD_freeDStream(_stream);
|
|
Aleksandr Kazakov |
35d714 |
else
|
|
Aleksandr Kazakov |
35d714 |
- ZSTD_freeCStream(_stream);
|
|
Aleksandr Kazakov |
35d714 |
+ ZSTD_freeCCtx(_stream);
|
|
Aleksandr Kazakov |
35d714 |
return NULL;
|
|
Aleksandr Kazakov |
35d714 |
}
|
|
Aleksandr Kazakov |
35d714 |
|
|
Aleksandr Kazakov |
35d714 |
@@ -1181,16 +1195,24 @@ assert(zstd);
|
|
Aleksandr Kazakov |
35d714 |
rc = 0;
|
|
Aleksandr Kazakov |
35d714 |
} else { /* compressing */
|
|
Aleksandr Kazakov |
35d714 |
/* close frame */
|
|
Aleksandr Kazakov |
35d714 |
- zstd->zob.dst = zstd->b;
|
|
Aleksandr Kazakov |
35d714 |
- zstd->zob.size = zstd->nb;
|
|
Aleksandr Kazakov |
35d714 |
- zstd->zob.pos = 0;
|
|
Aleksandr Kazakov |
35d714 |
- int xx = ZSTD_flushStream(zstd->_stream, &zstd->zob);
|
|
Aleksandr Kazakov |
35d714 |
- if (ZSTD_isError(xx))
|
|
Aleksandr Kazakov |
35d714 |
- fps->errcookie = ZSTD_getErrorName(xx);
|
|
Aleksandr Kazakov |
35d714 |
- else if (zstd->zob.pos != fwrite(zstd->b, 1, zstd->zob.pos, zstd->fp))
|
|
Aleksandr Kazakov |
35d714 |
- fps->errcookie = "zstdFlush fwrite failed.";
|
|
Aleksandr Kazakov |
35d714 |
- else
|
|
Aleksandr Kazakov |
35d714 |
- rc = 0;
|
|
Aleksandr Kazakov |
35d714 |
+ int xx;
|
|
Aleksandr Kazakov |
35d714 |
+ do {
|
|
Aleksandr Kazakov |
35d714 |
+ ZSTD_inBuffer zib = { NULL, 0, 0 };
|
|
Aleksandr Kazakov |
35d714 |
+ zstd->zob.dst = zstd->b;
|
|
Aleksandr Kazakov |
35d714 |
+ zstd->zob.size = zstd->nb;
|
|
Aleksandr Kazakov |
35d714 |
+ zstd->zob.pos = 0;
|
|
Aleksandr Kazakov |
35d714 |
+ xx = ZSTD_compressStream2(zstd->_stream, &zstd->zob, &zib, ZSTD_e_flush);
|
|
Aleksandr Kazakov |
35d714 |
+ if (ZSTD_isError(xx)) {
|
|
Aleksandr Kazakov |
35d714 |
+ fps->errcookie = ZSTD_getErrorName(xx);
|
|
Aleksandr Kazakov |
35d714 |
+ break;
|
|
Aleksandr Kazakov |
35d714 |
+ }
|
|
Aleksandr Kazakov |
35d714 |
+ else if (zstd->zob.pos != fwrite(zstd->b, 1, zstd->zob.pos, zstd->fp)) {
|
|
Aleksandr Kazakov |
35d714 |
+ fps->errcookie = "zstdClose fwrite failed.";
|
|
Aleksandr Kazakov |
35d714 |
+ break;
|
|
Aleksandr Kazakov |
35d714 |
+ }
|
|
Aleksandr Kazakov |
35d714 |
+ else
|
|
Aleksandr Kazakov |
35d714 |
+ rc = 0;
|
|
Aleksandr Kazakov |
35d714 |
+ } while (xx != 0);
|
|
Aleksandr Kazakov |
35d714 |
}
|
|
Aleksandr Kazakov |
35d714 |
return rc;
|
|
Aleksandr Kazakov |
35d714 |
}
|
|
Aleksandr Kazakov |
35d714 |
@@ -1235,7 +1257,7 @@ assert(zstd);
|
|
Aleksandr Kazakov |
35d714 |
zstd->zob.pos = 0;
|
|
Aleksandr Kazakov |
35d714 |
|
|
Aleksandr Kazakov |
35d714 |
/* Compress next chunk. */
|
|
Aleksandr Kazakov |
35d714 |
- int xx = ZSTD_compressStream(zstd->_stream, &zstd->zob, &zib;;
|
|
Aleksandr Kazakov |
35d714 |
+ int xx = ZSTD_compressStream2(zstd->_stream, &zstd->zob, &zib, ZSTD_e_continue);
|
|
Aleksandr Kazakov |
35d714 |
if (ZSTD_isError(xx)) {
|
|
Aleksandr Kazakov |
35d714 |
fps->errcookie = ZSTD_getErrorName(xx);
|
|
Aleksandr Kazakov |
35d714 |
return -1;
|
|
Aleksandr Kazakov |
35d714 |
@@ -1264,17 +1286,25 @@ assert(zstd);
|
|
Aleksandr Kazakov |
35d714 |
ZSTD_freeDStream(zstd->_stream);
|
|
Aleksandr Kazakov |
35d714 |
} else { /* compressing */
|
|
Aleksandr Kazakov |
35d714 |
/* close frame */
|
|
Aleksandr Kazakov |
35d714 |
- zstd->zob.dst = zstd->b;
|
|
Aleksandr Kazakov |
35d714 |
- zstd->zob.size = zstd->nb;
|
|
Aleksandr Kazakov |
35d714 |
- zstd->zob.pos = 0;
|
|
Aleksandr Kazakov |
35d714 |
- int xx = ZSTD_endStream(zstd->_stream, &zstd->zob);
|
|
Aleksandr Kazakov |
35d714 |
- if (ZSTD_isError(xx))
|
|
Aleksandr Kazakov |
35d714 |
- fps->errcookie = ZSTD_getErrorName(xx);
|
|
Aleksandr Kazakov |
35d714 |
- else if (zstd->zob.pos != fwrite(zstd->b, 1, zstd->zob.pos, zstd->fp))
|
|
Aleksandr Kazakov |
35d714 |
- fps->errcookie = "zstdClose fwrite failed.";
|
|
Aleksandr Kazakov |
35d714 |
- else
|
|
Aleksandr Kazakov |
35d714 |
- rc = 0;
|
|
Aleksandr Kazakov |
35d714 |
- ZSTD_freeCStream(zstd->_stream);
|
|
Aleksandr Kazakov |
35d714 |
+ int xx;
|
|
Aleksandr Kazakov |
35d714 |
+ do {
|
|
Aleksandr Kazakov |
35d714 |
+ ZSTD_inBuffer zib = { NULL, 0, 0 };
|
|
Aleksandr Kazakov |
35d714 |
+ zstd->zob.dst = zstd->b;
|
|
Aleksandr Kazakov |
35d714 |
+ zstd->zob.size = zstd->nb;
|
|
Aleksandr Kazakov |
35d714 |
+ zstd->zob.pos = 0;
|
|
Aleksandr Kazakov |
35d714 |
+ xx = ZSTD_compressStream2(zstd->_stream, &zstd->zob, &zib, ZSTD_e_end);
|
|
Aleksandr Kazakov |
35d714 |
+ if (ZSTD_isError(xx)) {
|
|
Aleksandr Kazakov |
35d714 |
+ fps->errcookie = ZSTD_getErrorName(xx);
|
|
Aleksandr Kazakov |
35d714 |
+ break;
|
|
Aleksandr Kazakov |
35d714 |
+ }
|
|
Aleksandr Kazakov |
35d714 |
+ else if (zstd->zob.pos != fwrite(zstd->b, 1, zstd->zob.pos, zstd->fp)) {
|
|
Aleksandr Kazakov |
35d714 |
+ fps->errcookie = "zstdClose fwrite failed.";
|
|
Aleksandr Kazakov |
35d714 |
+ break;
|
|
Aleksandr Kazakov |
35d714 |
+ }
|
|
Aleksandr Kazakov |
35d714 |
+ else
|
|
Aleksandr Kazakov |
35d714 |
+ rc = 0;
|
|
Aleksandr Kazakov |
35d714 |
+ } while (xx != 0);
|
|
Aleksandr Kazakov |
35d714 |
+ ZSTD_freeCCtx(zstd->_stream);
|
|
Aleksandr Kazakov |
35d714 |
}
|
|
Aleksandr Kazakov |
35d714 |
|
|
Aleksandr Kazakov |
35d714 |
if (zstd->fp && fileno(zstd->fp) > 2)
|
|
Aleksandr Kazakov |
35d714 |
--
|
|
Aleksandr Kazakov |
35d714 |
2.38.1
|
|
Aleksandr Kazakov |
35d714 |
|