Skip to content

Commit 584acdd

Browse files
Markus Stockhausenneilbrown
authored andcommitted
md/raid5: activate raid6 rmw feature
Glue it altogehter. The raid6 rmw path should work the same as the already existing raid5 logic. So emulate the prexor handling/flags and split functions as needed. 1) Enable xor_syndrome() in the async layer. 2) Split ops_run_prexor() into RAID4/5 and RAID6 logic. Xor the syndrome at the start of a rmw run as we did it before for the single parity. 3) Take care of rmw run in ops_run_reconstruct6(). Again process only the changed pages to get syndrome back into sync. 4) Enhance set_syndrome_sources() to fill NULL pages if we are in a rmw run. The lower layers will calculate start & end pages from that and call the xor_syndrome() correspondingly. 5) Adapt the several places where we ignored Q handling up to now. Performance numbers for a single E5630 system with a mix of 10 7200k desktop/server disks. 300 seconds random write with 8 threads onto a 3,2TB (10*400GB) RAID6 64K chunk without spare (group_thread_cnt=4) bsize rmw_level=1 rmw_level=0 rmw_level=1 rmw_level=0 skip_copy=1 skip_copy=1 skip_copy=0 skip_copy=0 4K 115 KB/s 141 KB/s 165 KB/s 140 KB/s 8K 225 KB/s 275 KB/s 324 KB/s 274 KB/s 16K 434 KB/s 536 KB/s 640 KB/s 534 KB/s 32K 751 KB/s 1,051 KB/s 1,234 KB/s 1,045 KB/s 64K 1,339 KB/s 1,958 KB/s 2,282 KB/s 1,962 KB/s 128K 2,673 KB/s 3,862 KB/s 4,113 KB/s 3,898 KB/s 256K 7,685 KB/s 7,539 KB/s 7,557 KB/s 7,638 KB/s 512K 19,556 KB/s 19,558 KB/s 19,652 KB/s 19,688 Kb/s Signed-off-by: Markus Stockhausen <stockhausen@collogia.de> Signed-off-by: NeilBrown <neilb@suse.de>
1 parent a582564 commit 584acdd

4 files changed

Lines changed: 115 additions & 30 deletions

File tree

‎crypto/async_tx/async_pq.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ do_sync_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
124124
{
125125
void **srcs;
126126
int i;
127+
int start = -1, stop = disks - 3;
127128

128129
if (submit->scribble)
129130
srcs = submit->scribble;
@@ -134,10 +135,21 @@ do_sync_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
134135
if (blocks[i] == NULL) {
135136
BUG_ON(i > disks - 3); /* P or Q can't be zero */
136137
srcs[i] = (void*)raid6_empty_zero_page;
137-
} else
138+
} else {
138139
srcs[i] = page_address(blocks[i]) + offset;
140+
if (i < disks - 2) {
141+
stop = i;
142+
if (start == -1)
143+
start = i;
144+
}
145+
}
139146
}
140-
raid6_call.gen_syndrome(disks, len, srcs);
147+
if (submit->flags & ASYNC_TX_PQ_XOR_DST) {
148+
BUG_ON(!raid6_call.xor_syndrome);
149+
if (start >= 0)
150+
raid6_call.xor_syndrome(disks, start, stop, len, srcs);
151+
} else
152+
raid6_call.gen_syndrome(disks, len, srcs);
141153
async_tx_sync_epilog(submit);
142154
}
143155

@@ -178,7 +190,8 @@ async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
178190
if (device)
179191
unmap = dmaengine_get_unmap_data(device->dev, disks, GFP_NOIO);
180192

181-
if (unmap &&
193+
/* XORing P/Q is only implemented in software */
194+
if (unmap && !(submit->flags & ASYNC_TX_PQ_XOR_DST) &&
182195
(src_cnt <= dma_maxpq(device, 0) ||
183196
dma_maxpq(device, DMA_PREP_CONTINUE) > 0) &&
184197
is_dma_pq_aligned(device, offset, 0, len)) {

‎drivers/md/raid5.c‎

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,9 @@ ops_run_compute5(struct stripe_head *sh, struct raid5_percpu *percpu)
13171317
* destination buffer is recorded in srcs[count] and the Q destination
13181318
* is recorded in srcs[count+1]].
13191319
*/
1320-
static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh)
1320+
static int set_syndrome_sources(struct page **srcs,
1321+
struct stripe_head *sh,
1322+
int srctype)
13211323
{
13221324
int disks = sh->disks;
13231325
int syndrome_disks = sh->ddf_layout ? disks : (disks - 2);
@@ -1332,8 +1334,15 @@ static int set_syndrome_sources(struct page **srcs, struct stripe_head *sh)
13321334
i = d0_idx;
13331335
do {
13341336
int slot = raid6_idx_to_slot(i, sh, &count, syndrome_disks);
1337+
struct r5dev *dev = &sh->dev[i];
13351338

1336-
srcs[slot] = sh->dev[i].page;
1339+
if (i == sh->qd_idx || i == sh->pd_idx ||
1340+
(srctype == SYNDROME_SRC_ALL) ||
1341+
(srctype == SYNDROME_SRC_WANT_DRAIN &&
1342+
test_bit(R5_Wantdrain, &dev->flags)) ||
1343+
(srctype == SYNDROME_SRC_WRITTEN &&
1344+
dev->written))
1345+
srcs[slot] = sh->dev[i].page;
13371346
i = raid6_next_disk(i, disks);
13381347
} while (i != d0_idx);
13391348

@@ -1373,7 +1382,7 @@ ops_run_compute6_1(struct stripe_head *sh, struct raid5_percpu *percpu)
13731382
atomic_inc(&sh->count);
13741383

13751384
if (target == qd_idx) {
1376-
count = set_syndrome_sources(blocks, sh);
1385+
count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_ALL);
13771386
blocks[count] = NULL; /* regenerating p is not necessary */
13781387
BUG_ON(blocks[count+1] != dest); /* q should already be set */
13791388
init_async_submit(&submit, ASYNC_TX_FENCE, NULL,
@@ -1481,7 +1490,7 @@ ops_run_compute6_2(struct stripe_head *sh, struct raid5_percpu *percpu)
14811490
tx = async_xor(dest, blocks, 0, count, STRIPE_SIZE,
14821491
&submit);
14831492

1484-
count = set_syndrome_sources(blocks, sh);
1493+
count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_ALL);
14851494
init_async_submit(&submit, ASYNC_TX_FENCE, tx,
14861495
ops_complete_compute, sh,
14871496
to_addr_conv(sh, percpu, 0));
@@ -1515,8 +1524,8 @@ static void ops_complete_prexor(void *stripe_head_ref)
15151524
}
15161525

15171526
static struct dma_async_tx_descriptor *
1518-
ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu,
1519-
struct dma_async_tx_descriptor *tx)
1527+
ops_run_prexor5(struct stripe_head *sh, struct raid5_percpu *percpu,
1528+
struct dma_async_tx_descriptor *tx)
15201529
{
15211530
int disks = sh->disks;
15221531
struct page **xor_srcs = to_addr_page(percpu, 0);
@@ -1544,6 +1553,26 @@ ops_run_prexor(struct stripe_head *sh, struct raid5_percpu *percpu,
15441553
return tx;
15451554
}
15461555

1556+
static struct dma_async_tx_descriptor *
1557+
ops_run_prexor6(struct stripe_head *sh, struct raid5_percpu *percpu,
1558+
struct dma_async_tx_descriptor *tx)
1559+
{
1560+
struct page **blocks = to_addr_page(percpu, 0);
1561+
int count;
1562+
struct async_submit_ctl submit;
1563+
1564+
pr_debug("%s: stripe %llu\n", __func__,
1565+
(unsigned long long)sh->sector);
1566+
1567+
count = set_syndrome_sources(blocks, sh, SYNDROME_SRC_WANT_DRAIN);
1568+
1569+
init_async_submit(&submit, ASYNC_TX_FENCE|ASYNC_TX_PQ_XOR_DST, tx,
1570+
ops_complete_prexor, sh, to_addr_conv(sh, percpu, 0));
1571+
tx = async_gen_syndrome(blocks, 0, count+2, STRIPE_SIZE, &submit);
1572+
1573+
return tx;
1574+
}
1575+
15471576
static struct dma_async_tx_descriptor *
15481577
ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
15491578
{
@@ -1746,6 +1775,8 @@ ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu,
17461775
int count, i, j = 0;
17471776
struct stripe_head *head_sh = sh;
17481777
int last_stripe;
1778+
int synflags;
1779+
unsigned long txflags;
17491780

17501781
pr_debug("%s: stripe %llu\n", __func__, (unsigned long long)sh->sector);
17511782

@@ -1765,14 +1796,23 @@ ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu,
17651796

17661797
again:
17671798
blocks = to_addr_page(percpu, j);
1768-
count = set_syndrome_sources(blocks, sh);
1799+
1800+
if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) {
1801+
synflags = SYNDROME_SRC_WRITTEN;
1802+
txflags = ASYNC_TX_ACK | ASYNC_TX_PQ_XOR_DST;
1803+
} else {
1804+
synflags = SYNDROME_SRC_ALL;
1805+
txflags = ASYNC_TX_ACK;
1806+
}
1807+
1808+
count = set_syndrome_sources(blocks, sh, synflags);
17691809
last_stripe = !head_sh->batch_head ||
17701810
list_first_entry(&sh->batch_list,
17711811
struct stripe_head, batch_list) == head_sh;
17721812

17731813
if (last_stripe) {
17741814
atomic_inc(&head_sh->count);
1775-
init_async_submit(&submit, ASYNC_TX_ACK, tx, ops_complete_reconstruct,
1815+
init_async_submit(&submit, txflags, tx, ops_complete_reconstruct,
17761816
head_sh, to_addr_conv(sh, percpu, j));
17771817
} else
17781818
init_async_submit(&submit, 0, tx, NULL, NULL,
@@ -1843,7 +1883,7 @@ static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu
18431883
(unsigned long long)sh->sector, checkp);
18441884

18451885
BUG_ON(sh->batch_head);
1846-
count = set_syndrome_sources(srcs, sh);
1886+
count = set_syndrome_sources(srcs, sh, SYNDROME_SRC_ALL);
18471887
if (!checkp)
18481888
srcs[count] = NULL;
18491889

@@ -1884,8 +1924,12 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
18841924
async_tx_ack(tx);
18851925
}
18861926

1887-
if (test_bit(STRIPE_OP_PREXOR, &ops_request))
1888-
tx = ops_run_prexor(sh, percpu, tx);
1927+
if (test_bit(STRIPE_OP_PREXOR, &ops_request)) {
1928+
if (level < 6)
1929+
tx = ops_run_prexor5(sh, percpu, tx);
1930+
else
1931+
tx = ops_run_prexor6(sh, percpu, tx);
1932+
}
18891933

18901934
if (test_bit(STRIPE_OP_BIODRAIN, &ops_request)) {
18911935
tx = ops_run_biodrain(sh, tx);
@@ -2770,7 +2814,7 @@ static void
27702814
schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
27712815
int rcw, int expand)
27722816
{
2773-
int i, pd_idx = sh->pd_idx, disks = sh->disks;
2817+
int i, pd_idx = sh->pd_idx, qd_idx = sh->qd_idx, disks = sh->disks;
27742818
struct r5conf *conf = sh->raid_conf;
27752819
int level = conf->level;
27762820

@@ -2806,13 +2850,15 @@ schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
28062850
if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state))
28072851
atomic_inc(&conf->pending_full_writes);
28082852
} else {
2809-
BUG_ON(level == 6);
28102853
BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) ||
28112854
test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags)));
2855+
BUG_ON(level == 6 &&
2856+
(!(test_bit(R5_UPTODATE, &sh->dev[qd_idx].flags) ||
2857+
test_bit(R5_Wantcompute, &sh->dev[qd_idx].flags))));
28122858

28132859
for (i = disks; i--; ) {
28142860
struct r5dev *dev = &sh->dev[i];
2815-
if (i == pd_idx)
2861+
if (i == pd_idx || i == qd_idx)
28162862
continue;
28172863

28182864
if (dev->towrite &&
@@ -3476,28 +3522,27 @@ static void handle_stripe_dirtying(struct r5conf *conf,
34763522
int rmw = 0, rcw = 0, i;
34773523
sector_t recovery_cp = conf->mddev->recovery_cp;
34783524

3479-
/* RAID6 requires 'rcw' in current implementation.
3480-
* Otherwise, check whether resync is now happening or should start.
3525+
/* Check whether resync is now happening or should start.
34813526
* If yes, then the array is dirty (after unclean shutdown or
34823527
* initial creation), so parity in some stripes might be inconsistent.
34833528
* In this case, we need to always do reconstruct-write, to ensure
34843529
* that in case of drive failure or read-error correction, we
34853530
* generate correct data from the parity.
34863531
*/
3487-
if (conf->max_degraded == 2 ||
3532+
if (conf->rmw_level == PARITY_DISABLE_RMW ||
34883533
(recovery_cp < MaxSector && sh->sector >= recovery_cp &&
34893534
s->failed == 0)) {
34903535
/* Calculate the real rcw later - for now make it
34913536
* look like rcw is cheaper
34923537
*/
34933538
rcw = 1; rmw = 2;
3494-
pr_debug("force RCW max_degraded=%u, recovery_cp=%llu sh->sector=%llu\n",
3495-
conf->max_degraded, (unsigned long long)recovery_cp,
3539+
pr_debug("force RCW rmw_level=%u, recovery_cp=%llu sh->sector=%llu\n",
3540+
conf->rmw_level, (unsigned long long)recovery_cp,
34963541
(unsigned long long)sh->sector);
34973542
} else for (i = disks; i--; ) {
34983543
/* would I have to read this buffer for read_modify_write */
34993544
struct r5dev *dev = &sh->dev[i];
3500-
if ((dev->towrite || i == sh->pd_idx) &&
3545+
if ((dev->towrite || i == sh->pd_idx || i == sh->qd_idx) &&
35013546
!test_bit(R5_LOCKED, &dev->flags) &&
35023547
!(test_bit(R5_UPTODATE, &dev->flags) ||
35033548
test_bit(R5_Wantcompute, &dev->flags))) {
@@ -3507,7 +3552,8 @@ static void handle_stripe_dirtying(struct r5conf *conf,
35073552
rmw += 2*disks; /* cannot read it */
35083553
}
35093554
/* Would I have to read this buffer for reconstruct_write */
3510-
if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx &&
3555+
if (!test_bit(R5_OVERWRITE, &dev->flags) &&
3556+
i != sh->pd_idx && i != sh->qd_idx &&
35113557
!test_bit(R5_LOCKED, &dev->flags) &&
35123558
!(test_bit(R5_UPTODATE, &dev->flags) ||
35133559
test_bit(R5_Wantcompute, &dev->flags))) {
@@ -3520,15 +3566,15 @@ static void handle_stripe_dirtying(struct r5conf *conf,
35203566
pr_debug("for sector %llu, rmw=%d rcw=%d\n",
35213567
(unsigned long long)sh->sector, rmw, rcw);
35223568
set_bit(STRIPE_HANDLE, &sh->state);
3523-
if (rmw < rcw && rmw > 0) {
3569+
if ((rmw < rcw || (rmw == rcw && conf->rmw_level == PARITY_ENABLE_RMW)) && rmw > 0) {
35243570
/* prefer read-modify-write, but need to get some data */
35253571
if (conf->mddev->queue)
35263572
blk_add_trace_msg(conf->mddev->queue,
35273573
"raid5 rmw %llu %d",
35283574
(unsigned long long)sh->sector, rmw);
35293575
for (i = disks; i--; ) {
35303576
struct r5dev *dev = &sh->dev[i];
3531-
if ((dev->towrite || i == sh->pd_idx) &&
3577+
if ((dev->towrite || i == sh->pd_idx || i == sh->qd_idx) &&
35323578
!test_bit(R5_LOCKED, &dev->flags) &&
35333579
!(test_bit(R5_UPTODATE, &dev->flags) ||
35343580
test_bit(R5_Wantcompute, &dev->flags)) &&
@@ -3547,7 +3593,7 @@ static void handle_stripe_dirtying(struct r5conf *conf,
35473593
}
35483594
}
35493595
}
3550-
if (rcw <= rmw && rcw > 0) {
3596+
if ((rcw < rmw || (rcw == rmw && conf->rmw_level != PARITY_ENABLE_RMW)) && rcw > 0) {
35513597
/* want reconstruct write, but need to get some data */
35523598
int qread =0;
35533599
rcw = 0;
@@ -6344,10 +6390,16 @@ static struct r5conf *setup_conf(struct mddev *mddev)
63446390
}
63456391

63466392
conf->level = mddev->new_level;
6347-
if (conf->level == 6)
6393+
if (conf->level == 6) {
63486394
conf->max_degraded = 2;
6349-
else
6395+
if (raid6_call.xor_syndrome)
6396+
conf->rmw_level = PARITY_ENABLE_RMW;
6397+
else
6398+
conf->rmw_level = PARITY_DISABLE_RMW;
6399+
} else {
63506400
conf->max_degraded = 1;
6401+
conf->rmw_level = PARITY_ENABLE_RMW;
6402+
}
63516403
conf->algorithm = mddev->new_layout;
63526404
conf->reshape_progress = mddev->reshape_position;
63536405
if (conf->reshape_progress != MaxSector) {

‎drivers/md/raid5.h‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,23 @@ enum {
355355
STRIPE_OP_RECONSTRUCT,
356356
STRIPE_OP_CHECK,
357357
};
358+
359+
/*
360+
* RAID parity calculation preferences
361+
*/
362+
enum {
363+
PARITY_DISABLE_RMW = 0,
364+
PARITY_ENABLE_RMW,
365+
};
366+
367+
/*
368+
* Pages requested from set_syndrome_sources()
369+
*/
370+
enum {
371+
SYNDROME_SRC_ALL,
372+
SYNDROME_SRC_WANT_DRAIN,
373+
SYNDROME_SRC_WRITTEN,
374+
};
358375
/*
359376
* Plugging:
360377
*
@@ -411,7 +428,7 @@ struct r5conf {
411428
spinlock_t hash_locks[NR_STRIPE_HASH_LOCKS];
412429
struct mddev *mddev;
413430
int chunk_sectors;
414-
int level, algorithm;
431+
int level, algorithm, rmw_level;
415432
int max_degraded;
416433
int raid_disks;
417434
int max_nr_stripes;

‎include/linux/async_tx.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ struct dma_chan_ref {
6060
* dependency chain
6161
* @ASYNC_TX_FENCE: specify that the next operation in the dependency
6262
* chain uses this operation's result as an input
63+
* @ASYNC_TX_PQ_XOR_DST: do not overwrite the syndrome but XOR it with the
64+
* input data. Required for rmw case.
6365
*/
6466
enum async_tx_flags {
6567
ASYNC_TX_XOR_ZERO_DST = (1 << 0),
6668
ASYNC_TX_XOR_DROP_DST = (1 << 1),
6769
ASYNC_TX_ACK = (1 << 2),
6870
ASYNC_TX_FENCE = (1 << 3),
71+
ASYNC_TX_PQ_XOR_DST = (1 << 4),
6972
};
7073

7174
/**

0 commit comments

Comments
 (0)