From 1c64dcfb312b94b2fa563a9cd24c3756d4d1bfe6 Mon Sep 17 00:00:00 2001 From: discomfitor Date: Thu, 11 Aug 2011 00:52:59 -0400 Subject: [PATCH] more initialization stuff out of main(), remove weird coincidentally successful one_g variable --- lrzip_private.h | 2 ++ main.c | 22 +--------------------- stream.c | 2 -- stream.h | 1 - util.c | 23 +++++++++++++++++++++++ util.h | 1 + 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lrzip_private.h b/lrzip_private.h index 8512bf0..02e2ac5 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -177,6 +177,8 @@ typedef struct md5_ctx md5_ctx; #define SALT_LEN 8 #define CBC_LEN 16 +#define one_g (1000 * 1024 * 1024) + #if defined(NOTHREAD) || !defined(_SC_NPROCESSORS_ONLN) # define PROCESSORS (1) #else diff --git a/main.c b/main.c index 7812f54..da1608e 100644 --- a/main.c +++ b/main.c @@ -629,27 +629,7 @@ int main(int argc, char *argv[]) } } - /* Use less ram when using STDOUT to store the temporary output - * file. */ - if (STDOUT && ((STDIN && DECOMPRESS) || !(DECOMPRESS || TEST_ONLY))) - control->maxram = control->ramsize * 2 / 9; - else - control->maxram = control->ramsize / 3; - if (BITS32) { - /* Decrease usable ram size on 32 bits due to kernel / - * userspace split. Cannot allocate larger than a 1 - * gigabyte chunk due to 32 bit signed long being - * used in alloc, and at most 3GB can be malloced, and - * 2/3 of that makes for a total of 2GB to be split - * into thirds. - */ - control->usable_ram = MAX(control->ramsize - 900000000ll, 900000000ll); - control->maxram = MIN(control->maxram, control->usable_ram); - control->maxram = MIN(control->maxram, one_g * 2 / 3); - } else - control->usable_ram = control->maxram; - round_to_page(&control->maxram); - + setup_ram(control); show_summary(); gettimeofday(&start_time, NULL); diff --git a/stream.c b/stream.c index a745ad5..9a6f923 100644 --- a/stream.c +++ b/stream.c @@ -662,8 +662,6 @@ out: /* WORK FUNCTIONS */ -i64 one_g = 1000 * 1024 * 1024; - /* Look at whether we're writing to a ram location or physical files and write * the data accordingly. */ ssize_t put_fdout(rzip_control *control, void *offset_buf, ssize_t ret) diff --git a/stream.h b/stream.h index 9e4600a..e91a170 100644 --- a/stream.h +++ b/stream.h @@ -38,6 +38,5 @@ i64 read_stream(rzip_control *control, void *ss, int streamno, uchar *p, i64 len int close_stream_out(rzip_control *control, void *ss); int close_stream_in(void *ss); ssize_t put_fdout(rzip_control *control, void *offset_buf, ssize_t ret); -i64 one_g; #endif diff --git a/util.c b/util.c index b80eb25..930a37f 100644 --- a/util.c +++ b/util.c @@ -133,6 +133,29 @@ void failure(const char *format, ...) fatal_exit(); } +void setup_ram(rzip_control *control) +{ + /* Use less ram when using STDOUT to store the temporary output file. */ + if (STDOUT && ((STDIN && DECOMPRESS) || !(DECOMPRESS || TEST_ONLY))) + control->maxram = control->ramsize * 2 / 9; + else + control->maxram = control->ramsize / 3; + if (BITS32) { + /* Decrease usable ram size on 32 bits due to kernel / + * userspace split. Cannot allocate larger than a 1 + * gigabyte chunk due to 32 bit signed long being + * used in alloc, and at most 3GB can be malloced, and + * 2/3 of that makes for a total of 2GB to be split + * into thirds. + */ + control->usable_ram = MAX(control->ramsize - 900000000ll, 900000000ll); + control->maxram = MIN(control->maxram, control->usable_ram); + control->maxram = MIN(control->maxram, one_g * 2 / 3); + } else + control->usable_ram = control->maxram; + round_to_page(&control->maxram); +} + void round_to_page(i64 *size) { *size -= *size % PAGE_SIZE; diff --git a/util.h b/util.h index 74fe819..8b8bf90 100644 --- a/util.h +++ b/util.h @@ -27,6 +27,7 @@ void unlink_files(void); void register_outputfile(FILE *f); void fatal(const char *format, ...); void failure(const char *format, ...); +void setup_ram(rzip_control *control); void round_to_page(i64 *size); void get_rand(uchar *buf, int len); void lrz_stretch(rzip_control *control);