]> wimlib.net Git - wimlib/blobdiff - src/compress_parallel.c
Fix a few format strings
[wimlib] / src / compress_parallel.c
index fa7f5dde113750adea8a1b43f12227748cd5109d..c99c0a86826bc66b841a45ffe1224f57e195f6ab 100644 (file)
@@ -43,6 +43,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#ifdef HAVE_SYS_SYSCTL_H
+#  include <sys/sysctl.h>
+#endif
 
 struct message_queue {
        struct list_head list;
 
 struct message_queue {
        struct list_head list;
@@ -116,12 +119,19 @@ get_avail_memory(void)
        if (phys_bytes == 0)
                goto default_size;
        return phys_bytes;
        if (phys_bytes == 0)
                goto default_size;
        return phys_bytes;
-#else
+#elif defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES)
        long page_size = sysconf(_SC_PAGESIZE);
        long num_pages = sysconf(_SC_PHYS_PAGES);
        if (page_size <= 0 || num_pages <= 0)
                goto default_size;
        return ((u64)page_size * (u64)num_pages);
        long page_size = sysconf(_SC_PAGESIZE);
        long num_pages = sysconf(_SC_PHYS_PAGES);
        if (page_size <= 0 || num_pages <= 0)
                goto default_size;
        return ((u64)page_size * (u64)num_pages);
+#else
+       int mib[2] = {CTL_HW, HW_MEMSIZE};
+       u64 memsize;
+       size_t len = sizeof(memsize);
+       if (sysctl(mib, ARRAY_LEN(mib), &memsize, &len, NULL, 0) < 0 || len != 8)
+               goto default_size;
+       return memsize;
 #endif
 
 default_size:
 #endif
 
 default_size:
@@ -423,16 +433,26 @@ new_parallel_chunk_compressor(int out_ctype, u32 out_chunk_size,
 
        desired_num_threads = num_threads;
 
 
        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
        for (;;) {
                approx_mem_required =
                        (u64)chunks_per_msg *
                        (u64)msgs_per_thread *
                        (u64)num_threads *
                        (u64)out_chunk_size
+                       + out_chunk_size
                        + 1000000
                        + 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;
 
                if (approx_mem_required <= max_memory)
                        break;
 
@@ -511,7 +531,9 @@ new_parallel_chunk_compressor(int out_ctype, u32 out_chunk_size,
                if (ret) {
                        errno = ret;
                        ret = WIMLIB_ERR_NOMEM;
                if (ret) {
                        errno = ret;
                        ret = WIMLIB_ERR_NOMEM;
-                       WARNING_WITH_ERRNO("Failed to create compressor thread %u of %u");
+                       WARNING_WITH_ERRNO("Failed to create compressor thread %u of %u",
+                                          ctx->num_started_threads + 1,
+                                          num_threads);
                        goto err;
                }
        }
                        goto err;
                }
        }