This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=eb86aaa906c28f1c8d2139fca7200a3b9049da12

The following commit(s) were added to refs/heads/main by this push:
     new eb86aaa90 libdpkg: Add new multithreaded xz decompression support
eb86aaa90 is described below

commit eb86aaa906c28f1c8d2139fca7200a3b9049da12 (HEAD -> main)
Author: Guillem Jover <[email protected]>
AuthorDate: Wed Dec 14 04:42:11 2022 +0100

    libdpkg: Add new multithreaded xz decompression support
    
    Starting with the xz 5.4.0 release, liblzma now supports multithreaded
    decompression. Add the code to make use of it in libdpkg, if the
    liblzma library in the system supports that, to improve the archive
    unpacking speed.
    
    Closes: #956452
---
 lib/dpkg/compress.c | 24 ++++++++++++++++++++++++
 m4/dpkg-libs.m4     |  4 ++++
 2 files changed, 28 insertions(+)

diff --git a/lib/dpkg/compress.c b/lib/dpkg/compress.c
index 6352d1b17..3e81ee636 100644
--- a/lib/dpkg/compress.c
+++ b/lib/dpkg/compress.c
@@ -636,12 +636,29 @@ filter_xz_get_cputhreads(struct compress_params *params)
 static void
 filter_unxz_init(struct io_lzma *io, lzma_stream *s)
 {
+#ifdef HAVE_LZMA_MT_DECODER
+       lzma_mt mt_options = {
+               .flags = 0,
+               .block_size = 0,
+               .timeout = 0,
+               .filters = NULL,
+       };
+#else
        uint64_t memlimit = UINT64_MAX;
+#endif
        lzma_ret ret;
 
        io->status |= DPKG_STREAM_DECOMPRESS;
 
+#ifdef HAVE_LZMA_MT_DECODER
+       mt_options.memlimit_stop = UINT64_MAX;
+       mt_options.memlimit_threading = filter_xz_get_memlimit();
+       mt_options.threads = filter_xz_get_cputhreads(io->params);
+
+       ret = lzma_stream_decoder_mt(s, &mt_options);
+#else
        ret = lzma_stream_decoder(s, memlimit, 0);
+#endif
        if (ret != LZMA_OK)
                filter_lzma_error(io, ret);
 }
@@ -748,12 +765,19 @@ decompress_xz(struct compress_params *params, int fd_in, 
int fd_out,
               const char *desc)
 {
        struct command cmd;
+       char *threads_opt = NULL;
 
        command_decompress_init(&cmd, XZ, desc);
 
+       if (params->threads_max > 0) {
+               threads_opt = str_fmt("-T%d", params->threads_max);
+               command_add_arg(&cmd, threads_opt);
+       }
+
        fd_fd_filter(&cmd, fd_in, fd_out, env_xz);
 
        command_destroy(&cmd);
+       free(threads_opt);
 }
 
 static void
diff --git a/m4/dpkg-libs.m4 b/m4/dpkg-libs.m4
index 4c02e83ca..845aa78d8 100644
--- a/m4/dpkg-libs.m4
+++ b/m4/dpkg-libs.m4
@@ -102,6 +102,10 @@ AC_DEFUN([DPKG_LIB_LZMA], [
     AC_DEFINE([HAVE_LZMA_MT_ENCODER], [1],
       [xz multithreaded compression support])
   ])
+  AC_CHECK_LIB([lzma], [lzma_stream_decoder_mt], [
+    AC_DEFINE([HAVE_LZMA_MT_DECODER], [1],
+      [xz multithreaded decompression support])
+  ])
 ])# DPKG_LIB_LZMA
 
 # DPKG_LIB_BZ2

-- 
Dpkg.Org's dpkg

Reply via email to