Switch location of Dedupe context creation to allow correct index memory sizing.

This commit is contained in:
Moinak Ghosh 2013-05-07 20:50:13 +05:30
parent 969e242b31
commit 2740a00c76

32
main.c
View file

@ -1947,6 +1947,7 @@ start_compress(const char *filename, uint64_t chunksize, int level)
tdat->cksum_mt = 0; tdat->cksum_mt = 0;
tdat->level = level; tdat->level = level;
tdat->data = NULL; tdat->data = NULL;
tdat->rctx = NULL;
tdat->props = &props; tdat->props = &props;
sem_init(&(tdat->start_sem), 0, 0); sem_init(&(tdat->start_sem), 0, 0);
sem_init(&(tdat->cmp_done_sem), 0, 0); sem_init(&(tdat->cmp_done_sem), 0, 0);
@ -1959,19 +1960,6 @@ start_compress(const char *filename, uint64_t chunksize, int level)
COMP_BAIL; COMP_BAIL;
} }
} }
if (enable_rabin_scan || enable_fixed_scan || enable_rabin_global) {
tdat->rctx = create_dedupe_context(chunksize, compressed_chunksize, rab_blk_size,
algo, &props, enable_delta_encode, dedupe_flag, VERSION, COMPRESS, sbuf.st_size,
tmpdir, pipe_mode, nprocs);
if (tdat->rctx == NULL) {
COMP_BAIL;
}
tdat->rctx->index_sem = &(tdat->index_sem);
tdat->rctx->id = i;
} else {
tdat->rctx = NULL;
}
if (encrypt_type) { if (encrypt_type) {
if (hmac_init(&tdat->chunk_hmac, cksum, &crypto_ctx) == -1) { if (hmac_init(&tdat->chunk_hmac, cksum, &crypto_ctx) == -1) {
@ -1987,6 +1975,24 @@ start_compress(const char *filename, uint64_t chunksize, int level)
} }
thread = 1; thread = 1;
/*
* initialize Dedupe Context here after all other allocations so that index size can be correctly
* computed based on free memory.
*/
if (enable_rabin_scan || enable_fixed_scan || enable_rabin_global) {
for (i = 0; i < nprocs; i++) {
tdat = dary[i];
tdat->rctx = create_dedupe_context(chunksize, compressed_chunksize, rab_blk_size,
algo, &props, enable_delta_encode, dedupe_flag, VERSION, COMPRESS, sbuf.st_size,
tmpdir, pipe_mode, nprocs);
if (tdat->rctx == NULL) {
COMP_BAIL;
}
tdat->rctx->index_sem = &(tdat->index_sem);
tdat->rctx->id = i;
}
}
if (enable_rabin_global) { if (enable_rabin_global) {
for (i = 0; i < nprocs; i++) { for (i = 0; i < nprocs; i++) {
tdat = dary[i]; tdat = dary[i];