mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Rafactors again with some minor changes.
This commit is contained in:
parent
e01b88b72b
commit
3be88162b9
3 changed files with 55 additions and 37 deletions
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
/**
|
||||
* Memory displacement to avoid cache collisions on contiguous blocks,
|
||||
* ued by raid_malloc_vector().
|
||||
* used by raid_malloc_vector().
|
||||
*
|
||||
* When allocating a sequence of blocks with a size of power of 2,
|
||||
* there is the risk that the start of each block is mapped into the same
|
||||
|
|
@ -32,20 +32,22 @@
|
|||
* in parallel, from the start to the end.
|
||||
*
|
||||
* The selected value was choosen empirically with some speed tests
|
||||
* with 8/12/16/20/24 data buffers and 3 parity buffers
|
||||
* for RAID-5/6/TP computation.
|
||||
* with 8/12/16/20/24 data buffers of 256 KB.
|
||||
*
|
||||
* With displacement (8 buffers, icore5, 32 bit):
|
||||
* With displacement:
|
||||
* (8 buffers of 256 KB, icore5, 32 bits):
|
||||
*
|
||||
* PAR1 sse2x4 21936 [MB/s]
|
||||
* PAR2 sse2x2 11902 [MB/s]
|
||||
* PARz sse2x1 5838 [MB/s]
|
||||
* sse2
|
||||
* par1 21936 [MB/s]
|
||||
* par2 11902 [MB/s]
|
||||
* parz 5838 [MB/s]
|
||||
*
|
||||
* Without displacement:
|
||||
*
|
||||
* PAR1 sse2x4 15368 [MB/s]
|
||||
* PAR2 sse2x2 6814 [MB/s]
|
||||
* PARz sse2x1 3033 [MB/s]
|
||||
* sse2
|
||||
* par1 15368 [MB/s]
|
||||
* par2 6814 [MB/s]
|
||||
* parz 3033 [MB/s]
|
||||
*/
|
||||
#define RAID_MALLOC_DISPLACEMENT (7*256)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
#include "memory.h"
|
||||
#include "cpu.h"
|
||||
|
||||
/*
|
||||
* Initializes and selects the best algorithm.
|
||||
*/
|
||||
void raid_init(void)
|
||||
{
|
||||
raid_par3_ptr = raid_par3_int8;
|
||||
|
|
@ -109,10 +112,15 @@ void raid_par_ref(int nd, int np, size_t size, void **vv)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of data disks to test.
|
||||
/*
|
||||
* Size of the blocks to test.
|
||||
*/
|
||||
#define TEST_DATA_MAX 8
|
||||
#define TEST_SIZE PAGE_SIZE
|
||||
|
||||
/*
|
||||
* Number of data blocks to test.
|
||||
*/
|
||||
#define TEST_COUNT (65536 / TEST_SIZE)
|
||||
|
||||
/*
|
||||
* Parity generation test.
|
||||
|
|
@ -120,7 +128,7 @@ void raid_par_ref(int nd, int np, size_t size, void **vv)
|
|||
static int raid_test_par(int nd, int np, size_t size, void **v, void **ref)
|
||||
{
|
||||
int i;
|
||||
void *t[TEST_DATA_MAX + RAID_PARITY_MAX];
|
||||
void *t[TEST_COUNT + RAID_PARITY_MAX];
|
||||
|
||||
/* setup data */
|
||||
for (i = 0; i < nd; ++i)
|
||||
|
|
@ -146,7 +154,7 @@ static int raid_test_par(int nd, int np, size_t size, void **v, void **ref)
|
|||
static int raid_test_rec(int nrd, int *id, int nrp, int *ip, int nd, int np, size_t size, void **v, void **ref)
|
||||
{
|
||||
int i, j;
|
||||
void *t[TEST_DATA_MAX + RAID_PARITY_MAX];
|
||||
void *t[TEST_COUNT + RAID_PARITY_MAX];
|
||||
|
||||
/* setup data */
|
||||
for (i = 0, j = 0; i < nd; ++i) {
|
||||
|
|
@ -183,18 +191,19 @@ static int raid_test_rec(int nrd, int *id, int nrp, int *ip, int nd, int np, siz
|
|||
*/
|
||||
int raid_selftest(void)
|
||||
{
|
||||
const int nd = TEST_DATA_MAX;
|
||||
const int nd = TEST_COUNT;
|
||||
const size_t size = TEST_SIZE;
|
||||
const int nv = nd + RAID_PARITY_MAX * 2 + 1;
|
||||
const size_t size = 4096;
|
||||
void *v_alloc;
|
||||
void **v;
|
||||
void *ref[nd + RAID_PARITY_MAX];
|
||||
int id[RAID_PARITY_MAX];
|
||||
int ip[RAID_PARITY_MAX];
|
||||
int i, np;
|
||||
int ret = 0;
|
||||
|
||||
/* ensure to have enough space for data */
|
||||
BUG_ON(TEST_DATA_MAX * size > 65536);
|
||||
BUG_ON(nd * size > 65536);
|
||||
|
||||
v = raid_malloc_vector(nd, nv, size, &v_alloc);
|
||||
if (!v)
|
||||
|
|
@ -216,20 +225,18 @@ int raid_selftest(void)
|
|||
|
||||
/* test for each parity level */
|
||||
for (np = 1; np <= RAID_PARITY_MAX; ++np) {
|
||||
int r;
|
||||
|
||||
/* test parity generation */
|
||||
r = raid_test_par(nd, np, size, v, ref);
|
||||
if (r != 0)
|
||||
return r;
|
||||
ret = raid_test_par(nd, np, size, v, ref);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
/* test recovering with full broken data disks */
|
||||
for (i = 0; i < np; ++i)
|
||||
id[i] = nd - np + i;
|
||||
|
||||
r = raid_test_rec(np, id, 0, ip, nd, np, size, v, ref);
|
||||
if (r != 0)
|
||||
return r;
|
||||
ret = raid_test_rec(np, id, 0, ip, nd, np, size, v, ref);
|
||||
if (ret != 0)
|
||||
goto bail;
|
||||
|
||||
/* test recovering with half broken data and ending parity */
|
||||
for (i = 0; i < np / 2; ++i)
|
||||
|
|
@ -238,9 +245,9 @@ int raid_selftest(void)
|
|||
for (i = 0; i < (np + 1) / 2; ++i)
|
||||
ip[i] = np - np / 2 + i;
|
||||
|
||||
r = raid_test_rec(np / 2, id, np / 2, ip, nd, np, size, v, ref);
|
||||
if (r != 0)
|
||||
return r;
|
||||
ret = raid_test_rec(np / 2, id, np / 2, ip, nd, np, size, v, ref);
|
||||
if (ret != 0)
|
||||
goto bail;
|
||||
|
||||
/* test recovering with half broken data and leading parity */
|
||||
for (i = 0; i < np / 2; ++i)
|
||||
|
|
@ -249,14 +256,15 @@ int raid_selftest(void)
|
|||
for (i = 0; i < (np + 1) / 2; ++i)
|
||||
ip[i] = i;
|
||||
|
||||
r = raid_test_rec(np / 2, id, np / 2, ip, nd, np, size, v, ref);
|
||||
if (r != 0)
|
||||
return r;
|
||||
ret = raid_test_rec(np / 2, id, np / 2, ip, nd, np, size, v, ref);
|
||||
if (ret != 0)
|
||||
goto bail;
|
||||
}
|
||||
|
||||
bail:
|
||||
free(v_alloc);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct raid_func {
|
||||
|
|
|
|||
16
raid/test.c
16
raid/test.c
|
|
@ -206,7 +206,7 @@ int raid_test_rec(int mode, int nd, size_t size)
|
|||
/* check */
|
||||
for (i = 0; i < nr; ++i)
|
||||
if (memcmp(test[i], data_save[i], size) != 0)
|
||||
return -1;
|
||||
goto bail;
|
||||
|
||||
/* restore */
|
||||
for (i = 0; i < nr; ++i) {
|
||||
|
|
@ -222,8 +222,12 @@ int raid_test_rec(int mode, int nd, size_t size)
|
|||
|
||||
free(v_alloc);
|
||||
free(v);
|
||||
|
||||
return 0;
|
||||
|
||||
bail:
|
||||
free(v_alloc);
|
||||
free(v);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int raid_test_par(int mode, int nd, size_t size)
|
||||
|
|
@ -318,12 +322,16 @@ int raid_test_par(int mode, int nd, size_t size)
|
|||
/* check it */
|
||||
for (i = 0; i < np; ++i)
|
||||
if (memcmp(v[nd + np + i], v[nd + i], size) != 0)
|
||||
return -1;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
free(v_alloc);
|
||||
free(v);
|
||||
|
||||
return 0;
|
||||
|
||||
bail:
|
||||
free(v_alloc);
|
||||
free(v);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue