Reduce memory occupation for MT

The copy buffer doesn't need a copy for each thread.
This commit is contained in:
Andrea Mazzoleni 2016-01-05 14:48:39 +01:00
parent fb404ef149
commit da5be1c5a7
2 changed files with 14 additions and 7 deletions

View file

@ -271,8 +271,8 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
/* rehash buffers */
rehandle = malloc_nofail_align(diskmax * sizeof(struct snapraid_rehash), &rehandle_alloc);
/* we need disk + 2 for each parity level buffers */
buffermax = diskmax + state->level * 2;
/* we need 1 * data + 2 * parity */
buffermax = diskmax + 2 * state->level;
/* initialize the io threads */
io_init(&io, state, buffermax, scrub_data_reader, handle, diskmax, scrub_parity_reader, 0, parity_handle, state->level);

View file

@ -660,6 +660,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
unsigned j;
void* zero_alloc;
void** zero;
void* copy_alloc;
void** copy;
unsigned buffermax;
data_off_t countsize;
block_off_t countpos;
@ -689,13 +691,16 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
/* rehash buffers */
rehandle = malloc_nofail_align(diskmax * sizeof(struct snapraid_rehash), &rehandle_alloc);
/* we need 2 * data + 1 * parity */
buffermax = 2 * diskmax + state->level;
/* we need 1 * data + 1 * parity */
buffermax = diskmax + state->level;
/* initialize the io threads */
io_init(&io, state, buffermax, sync_data_reader, handle, diskmax, 0, sync_parity_writer, parity_handle, state->level);
/* fill up the zero buffer */
/* allocate the copy buffer */
copy = malloc_nofail_vector_align(diskmax, diskmax, state->block_size, &copy_alloc);
/* allocate and fill the zero buffer */
zero = malloc_nofail_align(state->block_size, &zero_alloc);
memset(zero, 0, state->block_size);
raid_zero(zero);
@ -991,7 +996,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
failed_mac = 0;
for (j = 0; j < failed_count; ++j) {
unsigned char* block_buffer = buffer[failed[j].index];
unsigned char* block_copy = buffer[diskmax + state->level + failed[j].index];
unsigned char* block_copy = copy[failed[j].index];
unsigned block_state = block_state_get(failed[j].block);
/* we try to recover only if at least one BLK is present */
@ -1071,7 +1076,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
for (j = 0; j < failed_count; ++j) {
unsigned char hash[HASH_SIZE];
unsigned char* block_buffer = buffer[failed[j].index];
unsigned char* block_copy = buffer[diskmax + state->level + failed[j].index];
unsigned char* block_copy = copy[failed[j].index];
unsigned block_state = block_state_get(failed[j].block);
if (block_state == BLOCK_STATE_BLK) {
@ -1348,6 +1353,8 @@ bail:
free(handle);
free(zero_alloc);
free(copy_alloc);
free(copy);
free(rehandle_alloc);
free(failed);
free(failed_map);