From 6a3438f883f6217d8dbb8dd9b1a618832dace7db Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 4 Nov 2013 19:45:29 +0100 Subject: [PATCH] Reverse the order of disk buffers that are accessed in backward order. This improves a little the speed. --- TODO | 7 +++++++ check.c | 2 +- raid.c | 9 ++++++--- scrub.c | 2 +- selftest.c | 4 ++-- speed.c | 2 +- sync.c | 2 +- util.c | 11 ++++++++++- util.h | 3 ++- 9 files changed, 31 insertions(+), 11 deletions(-) diff --git a/TODO b/TODO index 43db37ce..fd7371a4 100644 --- a/TODO +++ b/TODO @@ -23,6 +23,13 @@ we already have all the hashes when sync starts. We need to extend the NEW blocks with an hash, likely using the dummy 0 hash as marker for no hash. +* When renaming to .unrecoverable at now we always overwrite +losing partial, but potentially better, previous copy of the files. +Is is possible a better strategy ? +Maybe we can rename the unrecoverable as the real file, if the real file +is missing at the first open. This should ensure to always +get better results if the file is hashed. + - Minor * In the content file save the timestap of the parity files. diff --git a/check.c b/check.c index ad95fecc..c4f4ab80 100644 --- a/check.c +++ b/check.c @@ -486,7 +486,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* we need disk + 2 for each parity level buffers + 1 zero buffer */ buffermax = diskmax + state->level * 2 + 1; - buffer = malloc_nofail_vector_align(buffermax, state->block_size, &buffer_alloc); + buffer = malloc_nofail_vector_align(diskmax, buffermax, state->block_size, &buffer_alloc); if (!state->opt.skip_self) mtest_vector(buffer, buffermax, state->block_size); diff --git a/raid.c b/raid.c index 7f779122..cce017da 100644 --- a/raid.c +++ b/raid.c @@ -236,7 +236,8 @@ void raid5_int32(unsigned char** vbuf, unsigned data, unsigned size) for(i=0;i=0;--d) { p0 ^= v_32(vbuf[d][i]); p1 ^= v_32(vbuf[d][i+4]); @@ -264,7 +265,8 @@ void raid5_int64(unsigned char** vbuf, unsigned data, unsigned size) for(i=0;i=0;--d) { p0 ^= v_64(vbuf[d][i]); p1 ^= v_64(vbuf[d][i+8]); @@ -297,7 +299,8 @@ void raid5_sse2(unsigned char** vbuf, unsigned data, unsigned size) asm volatile("movdqa %0,%%xmm1" : : "m" (vbuf[l][i+16])); asm volatile("movdqa %0,%%xmm2" : : "m" (vbuf[l][i+32])); asm volatile("movdqa %0,%%xmm3" : : "m" (vbuf[l][i+48])); - /* accessing disks in backward order doesn't affect speed */ + /* accessing disks in backward order because the buffers */ + /* are also in backward order */ for(d=l-1;d>=0;--d) { asm volatile("movdqa %0,%%xmm4" : : "m" (vbuf[d][i])); asm volatile("movdqa %0,%%xmm5" : : "m" (vbuf[d][i+16])); diff --git a/scrub.c b/scrub.c index 3e0b81a5..f999fb63 100644 --- a/scrub.c +++ b/scrub.c @@ -67,7 +67,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* we need disk + 2 for each parity level buffers */ buffermax = diskmax + state->level * 2; - buffer = malloc_nofail_vector_align(buffermax, state->block_size, &buffer_alloc); + buffer = malloc_nofail_vector_align(diskmax, buffermax, state->block_size, &buffer_alloc); if (!state->opt.skip_self) mtest_vector(buffer, buffermax, state->block_size); diff --git a/selftest.c b/selftest.c index 6b223945..7d63bfbf 100644 --- a/selftest.c +++ b/selftest.c @@ -102,7 +102,7 @@ static void recovtest(unsigned diskmax, unsigned block_size) buffermax = diskmax + LEV_MAX * 2 + 2; - buffer = malloc_nofail_vector_align(buffermax, block_size, &buffer_alloc); + buffer = malloc_nofail_vector_align(diskmax, buffermax, block_size, &buffer_alloc); mtest_vector(buffer, buffermax, block_size); data = buffer; @@ -214,7 +214,7 @@ static void gentest(unsigned diskmax, unsigned block_size) buffermax = diskmax + LEV_MAX * 2; - buffer = malloc_nofail_vector_align(buffermax, block_size, &buffer_alloc); + buffer = malloc_nofail_vector_align(diskmax, buffermax, block_size, &buffer_alloc); mtest_vector(buffer, buffermax, block_size); /* fill with random */ diff --git a/speed.c b/speed.c index a9d54aa6..937f93d7 100644 --- a/speed.c +++ b/speed.c @@ -73,7 +73,7 @@ void speed(void) /* we need disk + 1 for each parity level buffers + 1 zero buffer */ buffermax = diskmax + LEV_MAX + 1; - buffer = malloc_nofail_vector_align(buffermax, block_size, &buffer_alloc); + buffer = malloc_nofail_vector_align(diskmax, buffermax, block_size, &buffer_alloc); mtest_vector(buffer, buffermax, block_size); /* initialize disks with fixed data */ diff --git a/sync.c b/sync.c index 0b80118b..44b23e67 100644 --- a/sync.c +++ b/sync.c @@ -74,7 +74,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* we need disk + 1 for each parity level buffers */ buffermax = diskmax + state->level; - buffer = malloc_nofail_vector_align(buffermax, state->block_size, &buffer_alloc); + buffer = malloc_nofail_vector_align(diskmax, buffermax, state->block_size, &buffer_alloc); if (!state->opt.skip_self) mtest_vector(buffer, buffermax, state->block_size); diff --git a/util.c b/util.c index a3925d66..084579b4 100644 --- a/util.c +++ b/util.c @@ -1372,12 +1372,14 @@ void* malloc_nofail_align(size_t size, void** freeptr) */ #define MALLOC_DISPLACEMENT (7*256) -unsigned char** malloc_nofail_vector_align(size_t count, size_t size, void** freeptr) +unsigned char** malloc_nofail_vector_align(size_t reverse, size_t count, size_t size, void** freeptr) { unsigned char** buffer; unsigned char* buffer_aligned; size_t i; + assert(reverse <= count); + buffer = malloc_nofail(count * sizeof(void*)); buffer_aligned = malloc_nofail_align(count * (size + MALLOC_DISPLACEMENT), freeptr); @@ -1385,6 +1387,13 @@ unsigned char** malloc_nofail_vector_align(size_t count, size_t size, void** fre for(i=0;i