more initialization stuff out of main(), remove weird coincidentally successful one_g variable

This commit is contained in:
discomfitor 2011-08-11 00:52:59 -04:00 committed by Con Kolivas
parent cfd6915b20
commit 1c64dcfb31
6 changed files with 27 additions and 24 deletions

View file

@ -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

22
main.c
View file

@ -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);

View file

@ -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)

View file

@ -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

23
util.c
View file

@ -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;

1
util.h
View file

@ -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);