Skip to contentSkip to conversation

raid5: Add R5_ReadNoMerge flag which prevent bio from merging at block layer

RFC PATCH In review majianpeng 2 participants 4 messages Jul 13, 2012 – Jul 21, 2012 MD RAID

lore
Share & tools
lore

majianpeng

author
#0 lore raw

RFC PATCH 1/1 raid5: Add R5_ReadNoMerge flag which prevent bio from merging at block layer

Because bios will merge at block-layer,so bios-error may caused by other bio which be merged into to the same request.
Using this flag,it will find exactly error-sector and not do redundant operation like re-write and re-read.

V0->V1:Using REQ_FLUSH instead REQ_NOMERGE avoid bio merging at block layer.

---
 drivers/md/raid5.c |   14 ++++++++++++--
 drivers/md/raid5.h |    1 +
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/md/raid5.c +12 -2
index 04348d7..059989f6 100644
@@ -640,6 +640,9 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
 			else
 				bi->bi_sector = (sh->sector
 						 + rdev->data_offset);
+			if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
+				bi->bi_rw |= REQ_FLUSH;
+
 			bi->bi_flags = 1 << BIO_UPTODATE;
 			bi->bi_idx = 0;
 			bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
@@ -1739,7 +1742,9 @@ static void raid5_end_read_request(struct bio * bi, int error)
 			atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
 			clear_bit(R5_ReadError, &sh->dev[i].flags);
 			clear_bit(R5_ReWrite, &sh->dev[i].flags);
-		}
+		} else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
+			clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
+
 		if (atomic_read(&rdev->read_errors))
 			atomic_set(&rdev->read_errors, 0);
 	} else {
@@ -1784,7 +1789,11 @@ static void raid5_end_read_request(struct bio * bi, int error)
 		else
 			retry = 1;
 		if (retry)
-			set_bit(R5_ReadError, &sh->dev[i].flags);
+			if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) {
+				set_bit(R5_ReadError, &sh->dev[i].flags);
+				clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
+			} else
+				set_bit(R5_ReadNoMerge, &sh->dev[i].flags);
 		else {
 			clear_bit(R5_ReadError, &sh->dev[i].flags);
 			clear_bit(R5_ReWrite, &sh->dev[i].flags);
@@ -4504,6 +4513,7 @@ static int  retry_aligned_read(struct r5conf *conf, struct bio *raid_bio)
 			return handled;
 		}
 
+		set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags);
 		handle_stripe(sh);
 		release_stripe(sh);
 		handled++;
drivers/md/raid5.h +1 -0
index 2164021..6767d07 100644
@@ -273,6 +273,7 @@ enum r5dev_flags {
 	R5_Wantwrite,
 	R5_Overlap,	/* There is a pending overlapping request
 			 * on this block */
+	R5_ReadNoMerge, /* prevent bio from merging in block-layer */
 	R5_ReadError,	/* seen a read error here recently */
 	R5_ReWrite,	/* have tried to over-write the readerror */
 
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 65 lines · On Fri, 13 Jul 2012 19:13:35 +0800 majianpeng <[email protected]> wrote:

Because bios will merge at block-layer,so bios-error may caused by other bio which be merged into to the same request.
Using this flag,it will find exactly error-sector and not do redundant operation like re-write and re-read.

V0->V1:Using REQ_FLUSH instead REQ_NOMERGE avoid bio merging at block layer.

---
 drivers/md/raid5.c |   14 ++++++++++++--
 drivers/md/raid5.h |    1 +
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/md/raid5.c +12 -2
index 04348d7..059989f6 100644
@@ -640,6 +640,9 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
 			else
 				bi->bi_sector = (sh->sector
 						 + rdev->data_offset);
+			if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
+				bi->bi_rw |= REQ_FLUSH;
+
 			bi->bi_flags = 1 << BIO_UPTODATE;
 			bi->bi_idx = 0;
 			bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
@@ -1739,7 +1742,9 @@ static void raid5_end_read_request(struct bio * bi, int error)
 			atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
 			clear_bit(R5_ReadError, &sh->dev[i].flags);
 			clear_bit(R5_ReWrite, &sh->dev[i].flags);
-		}
+		} else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
+			clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
+
 		if (atomic_read(&rdev->read_errors))
 			atomic_set(&rdev->read_errors, 0);
 	} else {
@@ -1784,7 +1789,11 @@ static void raid5_end_read_request(struct bio * bi, int error)
 		else
 			retry = 1;
 		if (retry)
-			set_bit(R5_ReadError, &sh->dev[i].flags);
+			if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) {
+				set_bit(R5_ReadError, &sh->dev[i].flags);
+				clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
+			} else
+				set_bit(R5_ReadNoMerge, &sh->dev[i].flags);
 		else {
 			clear_bit(R5_ReadError, &sh->dev[i].flags);
 			clear_bit(R5_ReWrite, &sh->dev[i].flags);
@@ -4504,6 +4513,7 @@ static int  retry_aligned_read(struct r5conf *conf, struct bio *raid_bio)
 			return handled;
 		}
 
+		set_bit(R5_ReadNoMerge, &sh->dev[dd_idx].flags);
 		handle_stripe(sh);
 		release_stripe(sh);
 		handled++;
drivers/md/raid5.h +0 -0
index 2164021..6767d07 100644

drivers/md/raid5.h enum r5dev_flags { · line 279

Quoted 7 lines
drivers/md/raid5.h +1 -0
@@ -273,6 +273,7 @@ enum r5dev_flags {
 	R5_Wantwrite,
 	R5_Overlap,	/* There is a pending overlapping request
 			 * on this block */
+	R5_ReadNoMerge, /* prevent bio from merging in block-layer */
 	R5_ReadError,	/* seen a read error here recently */
 	R5_ReWrite,	/* have tried to over-write the readerror */
 

Thanks, I've applied this.

We should probably do a similar thing in fix_read_error and fix_sync_read_error in RAID1 and RAID10...

Thanks,
NeilBrown

author
#2 lore raw

On 2012-07-16 13:48 NeilBrown <[email protected]> Wrote:

Quoted 16 lines · On Fri, 13 Jul 2012 19:13:35 +0800 majianpeng <[email protected]> wrote:
Quoted 15 lines

Because bios will merge at block-layer,so bios-error may caused by other bio which be merged into to the same request.
Using this flag,it will find exactly error-sector and not do redundant operation like re-write and re-read.

V0->V1:Using REQ_FLUSH instead REQ_NOMERGE avoid bio merging at block layer.

---
 drivers/md/raid5.c |   14 ++++++++++++--
 drivers/md/raid5.h |    1 +
 2 files changed, 13 insertions(+), 2 deletions(-)

[snip]

Quoted 6 lines

Thanks, I've applied this.

We should probably do a similar thing in fix_read_error and fix_sync_read_error in RAID1 and RAID10...

Thanks, I'll do it.

Quoted 4 lines

Thanks,
NeilBrown

author
#3 lore raw
In reply to NeilBrown

On 2012-07-16 13:48 NeilBrown <[email protected]> Wrote:

Quoted 11 lines · On Fri, 13 Jul 2012 19:13:35 +0800 majianpeng <[email protected]> wrote:
Quoted 10 lines

Because bios will merge at block-layer,so bios-error may caused by other bio which be merged into to the same request.
Using this flag,it will find exactly error-sector and not do redundant operation like re-write and re-read.

V0->V1:Using REQ_FLUSH instead REQ_NOMERGE avoid bio merging at block layer.

[snip]

Quoted 7 lines

Thanks, I've applied this.

We should probably do a similar thing in fix_read_error and fix_sync_read_error in RAID1 and RAID10...

I reviewed the code about fix_read_error/fix_sync_read_error. It already do the similar thing.

Quoted 4 lines

Thanks,
NeilBrown