]> wimlib.net Git - wimlib/blobdiff - src/compress_parallel.c
wimlib_iterate_dir_tree(): Canonicalize WIM path
[wimlib] / src / compress_parallel.c
index d0ce5266464cb4021797cbd2a81c4ed5c5c652c3..376e59d6a2fdca8a05fae9486d58fc0f51bba08d 100644 (file)
@@ -26,6 +26,8 @@
 #  include "config.h"
 #endif
 
+#ifdef ENABLE_MULTITHREADED_COMPRESSION
+
 #include "wimlib/assert.h"
 #include "wimlib/chunk_compressor.h"
 #include "wimlib/error.h"
@@ -421,16 +423,26 @@ new_parallel_chunk_compressor(int out_ctype, u32 out_chunk_size,
 
        desired_num_threads = num_threads;
 
-       chunks_per_msg = MAX_CHUNKS_PER_MSG;
-       msgs_per_thread = 2;
+       if (out_chunk_size < ((u32)1 << 23)) {
+               chunks_per_msg = MAX_CHUNKS_PER_MSG;
+               msgs_per_thread = 2;
+       } else {
+               /* Big chunks: Just have one buffer per thread --- more would
+                * just waste memory.  */
+               chunks_per_msg = 1;
+               msgs_per_thread = 1;
+       }
        for (;;) {
                approx_mem_required =
                        (u64)chunks_per_msg *
                        (u64)msgs_per_thread *
                        (u64)num_threads *
                        (u64)out_chunk_size
+                       + out_chunk_size
                        + 1000000
-                       + (out_chunk_size * num_threads * 4);
+                       + num_threads * wimlib_get_compressor_needed_memory(out_ctype,
+                                                                           out_chunk_size,
+                                                                           NULL);
                if (approx_mem_required <= max_memory)
                        break;
 
@@ -534,3 +546,5 @@ err:
        parallel_chunk_compressor_destroy(&ctx->base);
        return ret;
 }
+
+#endif /* ENABLE_MULTITHREADED_COMPRESSION */