Reverse the order of disk buffers that are accessed in backward order.

This improves a little the speed.
This commit is contained in:
Andrea Mazzoleni 2013-11-04 19:45:29 +01:00
parent 3dd6e50c4e
commit 6a3438f883
9 changed files with 31 additions and 11 deletions

7
TODO
View file

@ -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.

View file

@ -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);

9
raid.c
View file

@ -236,7 +236,8 @@ void raid5_int32(unsigned char** vbuf, unsigned data, unsigned size)
for(i=0;i<size;i+=8) {
p0 = v_32(vbuf[l][i]);
p1 = v_32(vbuf[l][i+4]);
/* 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) {
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<size;i+=16) {
p0 = v_64(vbuf[l][i]);
p1 = v_64(vbuf[l][i+8]);
/* 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) {
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]));

View file

@ -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);

View file

@ -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 */

View file

@ -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 */

2
sync.c
View file

@ -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);

11
util.c
View file

@ -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<count;++i)
buffer[i] = buffer_aligned + i * (size + MALLOC_DISPLACEMENT);
/* reverse order for the initial ones */
for(i=0;i<reverse/2;++i) {
void* ptr = buffer[i];
buffer[i] = buffer[reverse - 1 - i];
buffer[reverse - 1 - i] = ptr;
}
return buffer;
}

3
util.h
View file

@ -460,9 +460,10 @@ void* malloc_nofail_align(size_t size, void** freeptr);
/**
* Safe aligned vector allocation.
* Returns a vector of "count" pointers, each one pointing to a block of the specified "size".
* The first "reverse" pointers are put in reverse memory offset order.
* If no memory is available, it aborts.
*/
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);
/**
* Test the memory vector for RAM problems.