Modify maxram to mean the most we'll allocate in one chunk and add usable_ram for the most we'll allocate to one task.

Limit all maxram on 32bits to 1GB since most don't like mallocing more than this.
Update testing to allow larger total amount based on usable ram while sticking to maxram limit per alloc.
This commit is contained in:
ckolivas 2011-03-22 12:10:21 +11:00
parent 68cca4dea5
commit f56e48c4f2
4 changed files with 22 additions and 19 deletions

View file

@ -213,6 +213,7 @@ struct rzip_control {
const char *suffix; const char *suffix;
int compression_level; int compression_level;
i64 overhead; // compressor overhead i64 overhead; // compressor overhead
i64 usable_ram; // the most ram we'll try to use on one activity
i64 maxram; // the largest chunk of ram to allocate i64 maxram; // the largest chunk of ram to allocate
unsigned char lzma_properties[5]; // lzma properties, encoded unsigned char lzma_properties[5]; // lzma properties, encoded
i64 window; i64 window;

9
main.c
View file

@ -766,16 +766,15 @@ int main(int argc, char *argv[])
else else
control.maxram = control.ramsize / 3; control.maxram = control.ramsize / 3;
if (BITS32) { if (BITS32) {
i64 usable_ram;
/* Decrease usable ram size on 32 bits due to kernel / /* Decrease usable ram size on 32 bits due to kernel /
* userspace split. Cannot allocate larger than a 1 * userspace split. Cannot allocate larger than a 1
* gigabyte chunk due to 32 bit signed long being * gigabyte chunk due to 32 bit signed long being
* used in alloc */ * used in alloc */
usable_ram = MAX(control.ramsize - 900000000ll, 900000000ll); control.usable_ram = MAX(control.ramsize - 900000000ll, 900000000ll);
control.maxram = MIN(control.maxram, usable_ram); control.maxram = MIN(control.maxram, control.usable_ram);
control.maxram = MIN(control.maxram, one_g); control.maxram = MIN(control.maxram, one_g);
} } else
control.usable_ram = control.maxram;
round_to_page(&control.maxram); round_to_page(&control.maxram);
show_summary(); show_summary();

5
rzip.c
View file

@ -812,11 +812,6 @@ void rzip_fd(rzip_control *control, int fd_in, int fd_out)
* buffer to work on 2/3 ram size, leaving enough ram for the * buffer to work on 2/3 ram size, leaving enough ram for the
* compression backends */ * compression backends */
control->max_mmap = control->maxram; control->max_mmap = control->maxram;
/* On 32 bits we can have a big window with sliding mmap, but can
* not enable much per mmap/malloc */
if (BITS32)
control->max_mmap = MIN((unsigned long long)control->max_mmap, two_gig);
round_to_page(&control->max_mmap); round_to_page(&control->max_mmap);
/* Set maximum chunk size to 2/3 of ram if not unlimited or specified /* Set maximum chunk size to 2/3 of ram if not unlimited or specified

View file

@ -985,14 +985,9 @@ void *open_stream_out(rzip_control *control, int f, unsigned int n, i64 chunk_li
else else
testbufs = 2; testbufs = 2;
/* Serious limits imposed on 32 bit capabilities */
if (BITS32)
limit = MIN((unsigned long long)limit, (two_gig / testbufs) -
(control->overhead * control->threads));
testsize = (limit * testbufs) + (control->overhead * control->threads); testsize = (limit * testbufs) + (control->overhead * control->threads);
if (testsize > control->maxram) if (testsize > control->usable_ram)
limit = (control->maxram - (control->overhead * control->threads)) / testbufs; limit = (control->usable_ram - (control->overhead * control->threads)) / testbufs;
/* If we don't have enough ram for the number of threads, decrease the /* If we don't have enough ram for the number of threads, decrease the
* number of threads till we do, or only have one thread. */ * number of threads till we do, or only have one thread. */
@ -1001,17 +996,30 @@ void *open_stream_out(rzip_control *control, int f, unsigned int n, i64 chunk_li
--control->threads; --control->threads;
else else
break; break;
limit = (control->maxram - (control->overhead * control->threads)) / testbufs; limit = (control->usable_ram - (control->overhead * control->threads)) / testbufs;
limit = MIN(limit, chunk_limit); limit = MIN(limit, chunk_limit);
} }
if (BITS32) // Shouldn't be higher than this by now, but just in case
limit = MIN(limit, one_g);
/* Use a nominal minimum size should we fail all previous shrinking */
limit = MAX(limit, STREAM_BUFSIZE); limit = MAX(limit, STREAM_BUFSIZE);
retest_malloc: retest_malloc:
testsize = (limit * testbufs) + (control->overhead * control->threads); testsize = limit + (control->overhead * control->threads);
testmalloc = malloc(testsize); testmalloc = malloc(testsize);
if (!testmalloc) { if (!testmalloc) {
limit = limit / 10 * 9; limit = limit / 10 * 9;
goto retest_malloc; goto retest_malloc;
} }
if (!NO_COMPRESS) {
char *testmalloc2 = malloc(limit);
if (!testmalloc2) {
free(testmalloc);
limit = limit / 10 * 9;
goto retest_malloc;
}
free(testmalloc2);
}
free(testmalloc); free(testmalloc);
print_maxverbose("Succeeded in testing %lld sized malloc for back end compression\n", testsize); print_maxverbose("Succeeded in testing %lld sized malloc for back end compression\n", testsize);