]> wimlib.net Git - wimlib/blobdiff - src/compress_parallel.c
header cleanups
[wimlib] / src / compress_parallel.c
index e083c079ab614a26e83edabdefbcf6fa0e06b102..acf4ea58afc24b4299f7848d22301486c6be5bbe 100644 (file)
@@ -7,19 +7,18 @@
 /*
  * Copyright (C) 2013 Eric Biggers
  *
- * This file is part of wimlib, a library for working with WIM files.
+ * This file is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version.
  *
- * wimlib is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 3 of the License, or (at your option) any later
- * version.
+ * This file is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
  *
- * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * wimlib; if not, see http://www.gnu.org/licenses/.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this file; if not, see http://www.gnu.org/licenses/.
  */
 
 #ifdef HAVE_CONFIG_H
 
 #ifdef ENABLE_MULTITHREADED_COMPRESSION
 
-#include "wimlib/assert.h"
-#include "wimlib/chunk_compressor.h"
-#include "wimlib/error.h"
-#include "wimlib/list.h"
-#include "wimlib/util.h"
-#ifdef __WIN32__
-#  include "wimlib/win32.h" /* win32_get_number_of_processors() */
-#endif
-
 #include <errno.h>
 #include <limits.h>
 #include <pthread.h>
 #  include <sys/sysctl.h>
 #endif
 
+#include "wimlib/assert.h"
+#include "wimlib/chunk_compressor.h"
+#include "wimlib/error.h"
+#include "wimlib/list.h"
+#include "wimlib/util.h"
+#ifdef __WIN32__
+#  include "wimlib/win32.h" /* win32_get_number_of_processors() */
+#endif
+
 struct message_queue {
        struct list_head list;
        pthread_mutex_t lock;
@@ -62,7 +61,7 @@ struct compressor_thread_data {
        struct wimlib_compressor *compressor;
 };
 
-#define MAX_CHUNKS_PER_MSG 2
+#define MAX_CHUNKS_PER_MSG 16
 
 struct message {
        u8 *uncompressed_chunks[MAX_CHUNKS_PER_MSG];
@@ -433,7 +432,13 @@ new_parallel_chunk_compressor(int out_ctype, u32 out_chunk_size,
        desired_num_threads = num_threads;
 
        if (out_chunk_size < ((u32)1 << 23)) {
-               chunks_per_msg = MAX_CHUNKS_PER_MSG;
+               /* Relatively small chunks.  Use 2 messages per thread, each
+                * with at least 2 chunks.  Use more chunks per message if there
+                * are lots of threads and/or the chunks are very small.  */
+               chunks_per_msg = 2;
+               chunks_per_msg += num_threads * (65536 / out_chunk_size) / 16;
+               chunks_per_msg = max(chunks_per_msg, 2);
+               chunks_per_msg = min(chunks_per_msg, MAX_CHUNKS_PER_MSG);
                msgs_per_thread = 2;
        } else {
                /* Big chunks: Just have one buffer per thread --- more would
@@ -451,7 +456,7 @@ new_parallel_chunk_compressor(int out_ctype, u32 out_chunk_size,
                        + 1000000
                        + num_threads * wimlib_get_compressor_needed_memory(out_ctype,
                                                                            out_chunk_size,
-                                                                           NULL);
+                                                                           0);
                if (approx_mem_required <= max_memory)
                        break;
 
@@ -510,8 +515,8 @@ new_parallel_chunk_compressor(int out_ctype, u32 out_chunk_size,
 
                dat->chunks_to_compress_queue = &ctx->chunks_to_compress_queue;
                dat->compressed_chunks_queue = &ctx->compressed_chunks_queue;
-               ret = wimlib_create_compressor(out_ctype, out_chunk_size,
-                                              NULL, &dat->compressor);
+               ret = wimlib_create_compressor(out_ctype, out_chunk_size, 0,
+                                              &dat->compressor);
                if (ret)
                        goto err;
        }