diff --git a/lrzip_private.h b/lrzip_private.h index 8fd9762..1fca208 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -168,6 +168,7 @@ struct rzip_control { i64 window; unsigned long flags; i64 ramsize; + i64 usable_ram; i64 max_chunk; i64 max_mmap; int threads; diff --git a/main.c b/main.c index cf3833f..a608f8c 100644 --- a/main.c +++ b/main.c @@ -210,8 +210,6 @@ static void show_summary(void) { /* OK, if verbosity set, print summary of options selected */ if (!INFO) { - i64 temp_chunk, temp_window, temp_ramsize; /* to show heurisitic computed values */ - if (!TEST_ONLY) print_verbose("The following options are in effect for this %s.\n", DECOMPRESS ? "DECOMPRESSION" : "COMPRESSION"); @@ -255,13 +253,12 @@ static void show_summary(void) print_verbose("Compression Window: %lld = %lldMB\n", control.window, control.window * 100ull); /* show heuristically computed window size */ if (!control.window && !UNLIMITED) { - temp_ramsize = control.ramsize; - if (BITS32) - temp_ramsize = MAX(temp_ramsize - 900000000ll, 900000000ll); - if (STDIN) - temp_chunk = temp_ramsize / 3; + i64 temp_chunk, temp_window; + + if (STDOUT || STDIN) + temp_chunk = control.maxram; else - temp_chunk = temp_ramsize / 3 * 2; + temp_chunk = control.maxram * 2; temp_window = temp_chunk / (100 * 1024 * 1024); print_verbose("Heuristically Computed Compression Window: %lld = %lldMB\n", temp_window, temp_window * 100ull); } @@ -638,8 +635,9 @@ int main(int argc, char *argv[]) /* Decrease usable ram size on 32 bits due to kernel/userspace split */ if (BITS32) - control.ramsize = MAX(control.ramsize - 900000000ll, 900000000ll); - control.maxram = control.ramsize / 3; + control.usable_ram = MAX(control.ramsize - 900000000ll, 900000000ll); + else + control.usable_ram = control.ramsize; /* Set the main nice value to half that of the backend threads since * the rzip stage is usually the rate limiting step */ @@ -705,6 +703,14 @@ int main(int argc, char *argv[]) } } + /* Use less ram when using STDOUT to store the temporary output file */ + if (STDOUT) + control.maxram = control.usable_ram * 2 / 9; + else + control.maxram = control.usable_ram / 3; + if (BITS32) + control.maxram = MIN(control.maxram, two_gig); + show_summary(); gettimeofday(&start_time, NULL); diff --git a/stream.c b/stream.c index c07e177..a4f6889 100644 --- a/stream.c +++ b/stream.c @@ -1318,7 +1318,7 @@ fill_another: if (!last_head) s->eos = 1; else if (s->uthread_no != s->unext_thread && !ucthread[s->uthread_no].busy && - sinfo->ram_alloced < control->ramsize / 3) + sinfo->ram_alloced < control->maxram) goto fill_another; out: lock_mutex(&output_lock);