Skip to contentSkip to conversation

md raid acceleration and the async_tx api

PATCH Yuri Tikhonov 3 participants 4 messages Aug 27, 2007 – Aug 30, 2007 MD RAID

lore
Share & tools
lore
#0 lore raw

Hello,

I tested the h/w accelerated RAID-5 using the kernel with PAGE_SIZE set to
64KB and found the bonnie++ application hangs-up during the "Re-writing" test. I made some investigations and discovered that the hang-up occurs because one of the mpage_end_io_read() calls is missing (these are the callbacks initiated from the ops_complete_biofill() function).

The fact is that my low-level ADMA driver (the ppc440spe one) successfully
initiated the ops_complete_biofill() callback but the ops_complete_biofill() function itself skipped calling the bi_end_io() handler of the completed bio (current dev->read) because during processing of this (current dev->read) bio some other request had come to the sh (current dev_q->toread). Thus ops_complete_biofill() scheduled another biofill operation which, as a result, overwrote the unacknowledged bio (dev->read in ops_run_biofill()), and so we lost the previous dev->read bio completely.

Here is a patch that solves this problem. Perhaps this might be implemented
in some more elegant and effective way. What are your thoughts regarding this?

Regards, Yuri

drivers/md/raid5.c +15 -2
index 08b4893..7abc96b 100644
@@ -838,11 +838,24 @@ static void ops_complete_biofill(void *stripe_head_ref)
 		/* acknowledge completion of a biofill operation */
 		/* and check if we need to reply to a read request
 		 */
-		if (test_bit(R5_Wantfill, &dev_q->flags) && !dev_q->toread) {
+		if (test_bit(R5_Wantfill, &dev_q->flags)) {
 			struct bio *rbi, *rbi2;
 			struct r5dev *dev = &sh->dev[i];
 
-			clear_bit(R5_Wantfill, &dev_q->flags);
+			/* There is a chance that another fill operation
+			 * had been scheduled for this dev while we
+			 * processed sh. In this case do one of the following
+			 * alternatives:
+			 * - if there is no active completed biofill for the dev
+			 *   then go to the next dev leaving Wantfill set;
+			 * - if there is active completed biofill for the dev
+			 *   then ack it but leave Wantfill set.
+			 */
+			if (dev_q->toread && !dev->read)
+				continue;
+
+			if (!dev_q->toread)
+				clear_bit(R5_Wantfill, &dev_q->flags);
 
 			/* The access to dev->read is outside of the
 			 * spin_lock_irq(&conf->device_lock), but is protected
#1 lore raw
Quoted 4 lines

From: Yuri Tikhonov [mailto:[email protected]]
Hello,

I tested the h/w accelerated RAID-5 using the kernel with PAGE_SIZE

set to

Quoted 1 line

64KB and found the bonnie++ application hangs-up during the

"Re-writing"

Quoted 1 line

test. I made some investigations and discovered that the hang-up

occurs

Quoted 4 lines

because one of the mpage_end_io_read() calls is missing (these are the callbacks initiated from the ops_complete_biofill() function).

The fact is that my low-level ADMA driver (the ppc440spe one)

successfully

Quoted 1 line

initiated the ops_complete_biofill() callback but the

ops_complete_biofill()

Quoted 1 line

function itself skipped calling the bi_end_io() handler of the

completed bio

Quoted 1 line

(current dev->read) because during processing of this (current

dev->read) bio

Quoted 3 lines

some other request had come to the sh (current dev_q->toread). Thus ops_complete_biofill() scheduled another biofill operation which, as a result, overwrote the unacknowledged bio (dev->read in

ops_run_biofill()),

Quoted 3 lines

and so we lost the previous dev->read bio completely.

Here is a patch that solves this problem. Perhaps this might be

implemented

Quoted 1 line

in some more elegant and effective way. What are your thoughts

regarding

drivers/md/raid5.c static void ops_complete_biofill(void

Quoted 9 lines

this?

Regards, Yuri

drivers/md/raid5.c +0 -0
index 08b4893..7abc96b 100644
@@ -838,11 +838,24 @@ static void ops_complete_biofill(void

*stripe_head_ref)

drivers/md/raid5.c static void ops_complete_biofill(void · line 841

Quoted 4 lines
drivers/md/raid5.c +0 -1
 		/* acknowledge completion of a biofill operation */
 		/* and check if we need to reply to a read request
 		 */
-		if (test_bit(R5_Wantfill, &dev_q->flags) &&

!dev_q->toread) {

drivers/md/raid5.c static void ops_complete_biofill(void · line 847

Quoted 8 lines
drivers/md/raid5.c +4 -1
+		if (test_bit(R5_Wantfill, &dev_q->flags)) {
 			struct bio *rbi, *rbi2;
 			struct r5dev *dev = &sh->dev[i];
 
-			clear_bit(R5_Wantfill, &dev_q->flags);
+			/* There is a chance that another fill operation
+			 * had been scheduled for this dev while we
+			 * processed sh. In this case do one of the

following

drivers/md/raid5.c static void ops_complete_biofill(void · line 849

Quoted 2 lines
drivers/md/raid5.c +2 -0
+			 * alternatives:
+			 * - if there is no active completed biofill for

the dev

drivers/md/raid5.c static void ops_complete_biofill(void · line 850

Quoted 1 line
drivers/md/raid5.c +1 -0
+			 *   then go to the next dev leaving Wantfill

set;

drivers/md/raid5.c static void ops_complete_biofill(void · line 851

Quoted 1 line
drivers/md/raid5.c +1 -0
+			 * - if there is active completed biofill for

the dev

drivers/md/raid5.c static void ops_complete_biofill(void · line 861

Quoted 10 lines
drivers/md/raid5.c +7 -0
+			 *   then ack it but leave Wantfill set.
+			 */
+			if (dev_q->toread && !dev->read)
+				continue;
+
+			if (!dev_q->toread)
+				clear_bit(R5_Wantfill, &dev_q->flags);
 
 			/* The access to dev->read is outside of the
 			 * spin_lock_irq(&conf->device_lock), but is

protected

This still looks racy... I think the complete fix is to make the R5_Wantfill and dev_q->toread accesses atomic. Please test the following patch (also attached) and let me know if it fixes what you are seeing:

Applies on top of git://lost.foo-projects.org/~dwillia2/git/iop
md-for-linus

---
raid5: fix ops_complete_biofill race in the asynchronous offload case

Protect against dev_q->toread toggling while testing and clearing the R5_Wantfill bit. This change prevents all asynchronous completions (tasklets) from running during handle_stripe.
---

 drivers/md/raid5.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
drivers/md/raid5.c +0 -0
index 2f9022d..91c14c6 100644
@@ -824,6 +824,7 @@ static void ops_complete_biofill(void

*stripe_head_ref)
(unsigned long long)sh->sector);

/* clear completed biofills */
+ spin_lock(&sq->lock);
for (i = sh->disks; i--; ) {
struct r5dev *dev = &sh->dev[i]; struct r5_queue_dev *dev_q = &sq->dev[i];
@@ -861,6 +862,7 @@ static void ops_complete_biofill(void *stripe_head_ref)
}
clear_bit(STRIPE_OP_BIOFILL, &sh->ops.ack); clear_bit(STRIPE_OP_BIOFILL, &sh->ops.pending);
+ spin_unlock(&sq->lock);

return_io(return_bi);

@@ -2279,7 +2281,7 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
(unsigned long long)bi->bi_sector,
(unsigned long long)sq->sector);

- spin_lock(&sq->lock);
+ spin_lock_bh(&sq->lock);
spin_lock_irq(&conf->device_lock);
sh = sq->sh;
if (forwrite) {
@@ -2306,7 +2308,7 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
*bip = bi;
bi->bi_phys_segments ++; spin_unlock_irq(&conf->device_lock);
- spin_unlock(&sq->lock);
+ spin_unlock_bh(&sq->lock);

pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
(unsigned long long)bi->bi_sector,
@@ -2339,7 +2341,7 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
overlap:
set_bit(R5_Overlap, &sh->dev[dd_idx].flags); spin_unlock_irq(&conf->device_lock);
- spin_unlock(&sq->lock);
+ spin_unlock_bh(&sq->lock);
return 0;
}

@@ -3127,7 +3129,7 @@ static void handle_stripe5(struct stripe_head *sh)
atomic_read(&sh->count), sq->pd_idx, sh->ops.pending, sh->ops.ack, sh->ops.complete);

- spin_lock(&sq->lock);
+ spin_lock_bh(&sq->lock);
clear_bit(STRIPE_HANDLE, &sh->state);

s.syncing = test_bit(STRIPE_SYNCING, &sh->state);
@@ -3370,7 +3372,7 @@ static void handle_stripe5(struct stripe_head *sh)
if (sh->ops.count)
pending = get_stripe_work(sh);

- spin_unlock(&sq->lock);
+ spin_unlock_bh(&sq->lock);

if (pending)
raid5_run_ops(sh, pending);
@@ -3397,7 +3399,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
atomic_read(&sh->count), pd_idx, r6s.qd_idx);
memset(&s, 0, sizeof(s));

- spin_lock(&sq->lock);
+ spin_lock_bh(&sq->lock);
clear_bit(STRIPE_HANDLE, &sh->state);

s.syncing = test_bit(STRIPE_SYNCING, &sh->state);
@@ -3576,7 +3578,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
if (s.expanding && s.locked == 0)
handle_stripe_expansion(conf, sh, &r6s);

- spin_unlock(&sq->lock);
+ spin_unlock_bh(&sq->lock);

return_io(return_bi);

raid5: fix ops_complete_biofill race in the asynchronous offload case

From: Dan Williams <[email protected]>

Protect against dev_q->toread toggling while testing and clearing the R5_Wantfill bit. This change prevents all asynchronous completions (tasklets) from running during handle_stripe.
---

 drivers/md/raid5.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
drivers/md/raid5.c +9 -7
index 2f9022d..91c14c6 100644
@@ -824,6 +824,7 @@ static void ops_complete_biofill(void *stripe_head_ref)
 		(unsigned long long)sh->sector);
 
 	/* clear completed biofills */
+	spin_lock(&sq->lock);
 	for (i = sh->disks; i--; ) {
 		struct r5dev *dev = &sh->dev[i];
 		struct r5_queue_dev *dev_q = &sq->dev[i];
@@ -861,6 +862,7 @@ static void ops_complete_biofill(void *stripe_head_ref)
 	}
 	clear_bit(STRIPE_OP_BIOFILL, &sh->ops.ack);
 	clear_bit(STRIPE_OP_BIOFILL, &sh->ops.pending);
+	spin_unlock(&sq->lock);
 
 	return_io(return_bi);
 
@@ -2279,7 +2281,7 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
 		(unsigned long long)bi->bi_sector,
 		(unsigned long long)sq->sector);
 
-	spin_lock(&sq->lock);
+	spin_lock_bh(&sq->lock);
 	spin_lock_irq(&conf->device_lock);
 	sh = sq->sh;
 	if (forwrite) {
@@ -2306,7 +2308,7 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
 	*bip = bi;
 	bi->bi_phys_segments ++;
 	spin_unlock_irq(&conf->device_lock);
-	spin_unlock(&sq->lock);
+	spin_unlock_bh(&sq->lock);
 
 	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
 		(unsigned long long)bi->bi_sector,
@@ -2339,7 +2341,7 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
  overlap:
 	set_bit(R5_Overlap, &sh->dev[dd_idx].flags);
 	spin_unlock_irq(&conf->device_lock);
-	spin_unlock(&sq->lock);
+	spin_unlock_bh(&sq->lock);
 	return 0;
 }
 
@@ -3127,7 +3129,7 @@ static void handle_stripe5(struct stripe_head *sh)
 		atomic_read(&sh->count), sq->pd_idx,
 		sh->ops.pending, sh->ops.ack, sh->ops.complete);
 
-	spin_lock(&sq->lock);
+	spin_lock_bh(&sq->lock);
 	clear_bit(STRIPE_HANDLE, &sh->state);
 
 	s.syncing = test_bit(STRIPE_SYNCING, &sh->state);
@@ -3370,7 +3372,7 @@ static void handle_stripe5(struct stripe_head *sh)
 	if (sh->ops.count)
 		pending = get_stripe_work(sh);
 
-	spin_unlock(&sq->lock);
+	spin_unlock_bh(&sq->lock);
 
 	if (pending)
 		raid5_run_ops(sh, pending);
@@ -3397,7 +3399,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
 	       atomic_read(&sh->count), pd_idx, r6s.qd_idx);
 	memset(&s, 0, sizeof(s));
 
-	spin_lock(&sq->lock);
+	spin_lock_bh(&sq->lock);
 	clear_bit(STRIPE_HANDLE, &sh->state);
 
 	s.syncing = test_bit(STRIPE_SYNCING, &sh->state);
@@ -3576,7 +3578,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
 	if (s.expanding && s.locked == 0)
 		handle_stripe_expansion(conf, sh, &r6s);
 
-	spin_unlock(&sq->lock);
+	spin_unlock_bh(&sq->lock);
 
 	return_io(return_bi);
 
#2 lore raw

Hi Dan,

Quoted 4 lines · you

This still looks racy... I think the complete fix is to make the R5_Wantfill and dev_q->toread accesses atomic. Please test the following patch (also attached) and let me know if it fixes what you are seeing:

Your approach doesn't help, the Bonnie++ utility hangs up during the
ReWriting stage.

Note that before applying your patch I rolled my fix in the
ops_complete_biofill() function back. Do I understand it right that your patch should be used *instead* of my one rather than *with* it ?

Regards, Yuri

#3 lore raw
Quoted 12 lines · Yuri Tikhonov

Hi Dan,

Quoted 4 lines · you

This still looks racy... I think the complete fix is to make the R5_Wantfill and dev_q->toread accesses atomic. Please test the following patch (also attached) and let me know if it fixes what you are seeing:

Your approach doesn't help, the Bonnie++ utility hangs up during the
ReWriting stage.

Looking at it again I see that what I added would not affect the failure you are seeing. However I noticed that you are using a broken version of the stripe-queue and cache_arbiter patches. In the current revisions the dev_q->flags field has been moved back to dev->flags which fixes a data corruption issue and could potentially address the hang you are seeing. The latest revisions are:
raid5: add the stripe_queue object for tracking raid io requests (rev2)
raid5: use stripe_queues to prioritize the "most deserving" requests (rev6)

Quoted 4 lines

Note that before applying your patch I rolled my fix in the
ops_complete_biofill() function back. Do I understand it right that your patch should be used *instead* of my one rather than *with* it ?

You understood correctly. The attached patch integrates your change to keep R5_Wantfill set while also protecting the 'more_to_read' case.
Please try it on top of the latest stripe-queue changes [1] (instead
of the other proposed patches) .

Quoted 1 line

Regards, Yuri

Thanks,
Dan

[1] git fetch -f git://lost.foo-projects.org/~dwillia2/git/iop
md-for-linus:refs/heads/md-for-linus

raid5: fix the 'more_to_read' case in ops_complete_biofill

From: Dan Williams <[email protected]>

Prevent ops_complete_biofill from running concurrently with add_queue_bio

---

 drivers/md/raid5.c |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)
drivers/md/raid5.c +19 -14
index 2f9022d..1c591d3 100644
@@ -828,22 +828,19 @@ static void ops_complete_biofill(void *stripe_head_ref)
 		struct r5dev *dev = &sh->dev[i];
 		struct r5_queue_dev *dev_q = &sq->dev[i];
 
-		/* check if this stripe has new incoming reads */
+		/* 1/ acknowledge completion of a biofill operation
+		 * 2/ check if we need to reply to a read request.
+		 * 3/ check if we need to reschedule handle_stripe
+		 */
 		if (dev_q->toread)
 			more_to_read++;
 
-		/* acknowledge completion of a biofill operation */
-		/* and check if we need to reply to a read request
-		*/
-		if (test_bit(R5_Wantfill, &dev->flags) && !dev_q->toread) {
+		if (test_bit(R5_Wantfill, &dev->flags)) {
 			struct bio *rbi, *rbi2;
-			clear_bit(R5_Wantfill, &dev->flags);
 
-			/* The access to dev->read is outside of the
-			 * spin_lock_irq(&conf->device_lock), but is protected
-			 * by the STRIPE_OP_BIOFILL pending bit
-			 */
-			BUG_ON(!dev->read);
+			if (!dev_q->toread)
+				clear_bit(R5_Wantfill, &dev->flags);
+
 			rbi = dev->read;
 			dev->read = NULL;
 			while (rbi && rbi->bi_sector <
@@ -899,8 +896,15 @@ static void ops_run_biofill(struct stripe_head *sh)
 	}
 
 	atomic_inc(&sh->count);
+
+	/* spin_lock prevents ops_complete_biofill from running concurrently
+	 * with add_queue_bio in the synchronous case
+	 */
+	spin_lock(&sq->lock);
 	async_trigger_callback(ASYNC_TX_DEP_ACK | ASYNC_TX_ACK, tx,
 		ops_complete_biofill, sh);
+	spin_unlock(&sq->lock);
+
 }
 
 static void ops_complete_compute5(void *stripe_head_ref)
@@ -2279,7 +2283,8 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
 		(unsigned long long)bi->bi_sector,
 		(unsigned long long)sq->sector);
 
-	spin_lock(&sq->lock);
+	/* prevent asynchronous completions from running */
+	spin_lock_bh(&sq->lock);
 	spin_lock_irq(&conf->device_lock);
 	sh = sq->sh;
 	if (forwrite) {
@@ -2306,7 +2311,7 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
 	*bip = bi;
 	bi->bi_phys_segments ++;
 	spin_unlock_irq(&conf->device_lock);
-	spin_unlock(&sq->lock);
+	spin_unlock_bh(&sq->lock);
 
 	pr_debug("added bi b#%llu to stripe s#%llu, disk %d.\n",
 		(unsigned long long)bi->bi_sector,
@@ -2339,7 +2344,7 @@ static int add_queue_bio(struct stripe_queue *sq, struct bio *bi, int dd_idx,
  overlap:
 	set_bit(R5_Overlap, &sh->dev[dd_idx].flags);
 	spin_unlock_irq(&conf->device_lock);
-	spin_unlock(&sq->lock);
+	spin_unlock_bh(&sq->lock);
 	return 0;
 }