Skip to content

Commit f591df3

Browse files
Zhengyuan Liuliu-song-6
authored andcommitted
md/raid6: fix algorithm choice under larger PAGE_SIZE
There are several algorithms available for raid6 to generate xor and syndrome parity, including basic int1, int2 ... int32 and SIMD optimized implementation like sse and neon. To test and choose the best algorithms at the initial stage, we need provide enough disk data to feed the algorithms. However, the disk number we provided depends on page size and gfmul table, seeing bellow: const int disks = (65536/PAGE_SIZE) + 2; So when come to 64K PAGE_SIZE, there is only one data disk plus 2 parity disk, as a result the chosed algorithm is not reliable. For example, on my arm64 machine with 64K page enabled, it will choose intx32 as the best one, although the NEON implementation is better. This patch tries to fix the problem by defining a constant raid6 disk number to supporting arbitrary page size. Suggested-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Zhengyuan Liu <liuzhengyuan@kylinos.cn> Signed-off-by: Song Liu <songliubraving@fb.com>
1 parent 5e5ac01 commit f591df3

2 files changed

Lines changed: 44 additions & 23 deletions

File tree

‎include/linux/raid/pq.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern const char raid6_empty_zero_page[PAGE_SIZE];
2828
#include <errno.h>
2929
#include <inttypes.h>
3030
#include <stddef.h>
31+
#include <string.h>
3132
#include <sys/mman.h>
3233
#include <sys/time.h>
3334
#include <sys/types.h>
@@ -43,6 +44,9 @@ typedef uint64_t u64;
4344
#ifndef PAGE_SIZE
4445
# define PAGE_SIZE 4096
4546
#endif
47+
#ifndef PAGE_SHIFT
48+
# define PAGE_SHIFT 12
49+
#endif
4650
extern const char raid6_empty_zero_page[PAGE_SIZE];
4751

4852
#define __init

‎lib/raid6/algos.c‎

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ const struct raid6_recov_calls *const raid6_recov_algos[] = {
124124
#define time_before(x, y) ((x) < (y))
125125
#endif
126126

127+
#define RAID6_TEST_DISKS 8
128+
#define RAID6_TEST_DISKS_ORDER 3
129+
127130
static inline const struct raid6_recov_calls *raid6_choose_recov(void)
128131
{
129132
const struct raid6_recov_calls *const *algo;
@@ -146,7 +149,7 @@ static inline const struct raid6_recov_calls *raid6_choose_recov(void)
146149
}
147150

148151
static inline const struct raid6_calls *raid6_choose_gen(
149-
void *(*const dptrs)[(65536/PAGE_SIZE)+2], const int disks)
152+
void *(*const dptrs)[RAID6_TEST_DISKS], const int disks)
150153
{
151154
unsigned long perf, bestgenperf, bestxorperf, j0, j1;
152155
int start = (disks>>1)-1, stop = disks-3; /* work on the second half of the disks */
@@ -181,7 +184,8 @@ static inline const struct raid6_calls *raid6_choose_gen(
181184
best = *algo;
182185
}
183186
pr_info("raid6: %-8s gen() %5ld MB/s\n", (*algo)->name,
184-
(perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2));
187+
(perf * HZ * (disks-2)) >>
188+
(20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2));
185189

186190
if (!(*algo)->xor_syndrome)
187191
continue;
@@ -204,17 +208,24 @@ static inline const struct raid6_calls *raid6_choose_gen(
204208
bestxorperf = perf;
205209

206210
pr_info("raid6: %-8s xor() %5ld MB/s\n", (*algo)->name,
207-
(perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2+1));
211+
(perf * HZ * (disks-2)) >>
212+
(20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1));
208213
}
209214
}
210215

211216
if (best) {
212-
pr_info("raid6: using algorithm %s gen() %ld MB/s\n",
213-
best->name,
214-
(bestgenperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2));
215-
if (best->xor_syndrome)
216-
pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n",
217-
(bestxorperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2+1));
217+
if (IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) {
218+
pr_info("raid6: using algorithm %s gen() %ld MB/s\n",
219+
best->name,
220+
(bestgenperf * HZ * (disks-2)) >>
221+
(20 - PAGE_SHIFT+RAID6_TIME_JIFFIES_LG2));
222+
if (best->xor_syndrome)
223+
pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n",
224+
(bestxorperf * HZ * (disks-2)) >>
225+
(20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1));
226+
} else
227+
pr_info("raid6: skip pq benchmark and using algorithm %s\n",
228+
best->name);
218229
raid6_call = *best;
219230
} else
220231
pr_err("raid6: Yikes! No algorithm found!\n");
@@ -228,35 +239,41 @@ static inline const struct raid6_calls *raid6_choose_gen(
228239

229240
int __init raid6_select_algo(void)
230241
{
231-
const int disks = (65536/PAGE_SIZE)+2;
242+
const int disks = RAID6_TEST_DISKS;
232243

233244
const struct raid6_calls *gen_best;
234245
const struct raid6_recov_calls *rec_best;
235-
char *syndromes;
236-
void *dptrs[(65536/PAGE_SIZE)+2];
237-
int i;
238-
239-
for (i = 0; i < disks-2; i++)
240-
dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i;
241-
242-
/* Normal code - use a 2-page allocation to avoid D$ conflict */
243-
syndromes = (void *) __get_free_pages(GFP_KERNEL, 1);
246+
char *disk_ptr, *p;
247+
void *dptrs[RAID6_TEST_DISKS];
248+
int i, cycle;
244249

245-
if (!syndromes) {
250+
/* prepare the buffer and fill it circularly with gfmul table */
251+
disk_ptr = (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER);
252+
if (!disk_ptr) {
246253
pr_err("raid6: Yikes! No memory available.\n");
247254
return -ENOMEM;
248255
}
249256

250-
dptrs[disks-2] = syndromes;
251-
dptrs[disks-1] = syndromes + PAGE_SIZE;
257+
p = disk_ptr;
258+
for (i = 0; i < disks; i++)
259+
dptrs[i] = p + PAGE_SIZE * i;
260+
261+
cycle = ((disks - 2) * PAGE_SIZE) / 65536;
262+
for (i = 0; i < cycle; i++) {
263+
memcpy(p, raid6_gfmul, 65536);
264+
p += 65536;
265+
}
266+
267+
if ((disks - 2) * PAGE_SIZE % 65536)
268+
memcpy(p, raid6_gfmul, (disks - 2) * PAGE_SIZE % 65536);
252269

253270
/* select raid gen_syndrome function */
254271
gen_best = raid6_choose_gen(&dptrs, disks);
255272

256273
/* select raid recover functions */
257274
rec_best = raid6_choose_recov();
258275

259-
free_pages((unsigned long)syndromes, 1);
276+
free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER);
260277

261278
return gen_best && rec_best ? 0 : -EINVAL;
262279
}

0 commit comments

Comments
 (0)