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

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;