Skip to content

Commit 2ca68f5

Browse files
committed
md/raid1: store behind-write pages in bi_vecs.
When performing write-behind we allocate pages to store the data during write. Previously we just keep a list of pages. Now we keep a list of bi_vec which includes offset and size. This means that the r1bio has complete information to create a new bio which will be needed for retrying after write errors. Signed-off-by: NeilBrown <neilb@suse.de> Reviewed-by: Namhyung Kim <namhyung@gmail.com>
1 parent 4367af5 commit 2ca68f5

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

‎drivers/md/raid1.c‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ static void r1_bio_write_done(r1bio_t *r1_bio)
327327
/* free extra copy of the data pages */
328328
int i = r1_bio->behind_page_count;
329329
while (i--)
330-
safe_put_page(r1_bio->behind_pages[i]);
331-
kfree(r1_bio->behind_pages);
332-
r1_bio->behind_pages = NULL;
330+
safe_put_page(r1_bio->behind_bvecs[i].bv_page);
331+
kfree(r1_bio->behind_bvecs);
332+
r1_bio->behind_bvecs = NULL;
333333
}
334334
/* clear the bitmap if all writes complete successfully */
335335
bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
@@ -748,30 +748,31 @@ static void alloc_behind_pages(struct bio *bio, r1bio_t *r1_bio)
748748
{
749749
int i;
750750
struct bio_vec *bvec;
751-
struct page **pages = kzalloc(bio->bi_vcnt * sizeof(struct page*),
751+
struct bio_vec *bvecs = kzalloc(bio->bi_vcnt * sizeof(struct bio_vec),
752752
GFP_NOIO);
753-
if (unlikely(!pages))
753+
if (unlikely(!bvecs))
754754
return;
755755

756756
bio_for_each_segment(bvec, bio, i) {
757-
pages[i] = alloc_page(GFP_NOIO);
758-
if (unlikely(!pages[i]))
757+
bvecs[i] = *bvec;
758+
bvecs[i].bv_page = alloc_page(GFP_NOIO);
759+
if (unlikely(!bvecs[i].bv_page))
759760
goto do_sync_io;
760-
memcpy(kmap(pages[i]) + bvec->bv_offset,
761-
kmap(bvec->bv_page) + bvec->bv_offset, bvec->bv_len);
762-
kunmap(pages[i]);
761+
memcpy(kmap(bvecs[i].bv_page) + bvec->bv_offset,
762+
kmap(bvec->bv_page) + bvec->bv_offset, bvec->bv_len);
763+
kunmap(bvecs[i].bv_page);
763764
kunmap(bvec->bv_page);
764765
}
765-
r1_bio->behind_pages = pages;
766+
r1_bio->behind_bvecs = bvecs;
766767
r1_bio->behind_page_count = bio->bi_vcnt;
767768
set_bit(R1BIO_BehindIO, &r1_bio->state);
768769
return;
769770

770771
do_sync_io:
771772
for (i = 0; i < bio->bi_vcnt; i++)
772-
if (pages[i])
773-
put_page(pages[i]);
774-
kfree(pages);
773+
if (bvecs[i].bv_page)
774+
put_page(bvecs[i].bv_page);
775+
kfree(bvecs);
775776
PRINTK("%dB behind alloc failed, doing sync I/O\n", bio->bi_size);
776777
}
777778

@@ -1058,7 +1059,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
10581059
&r1_bio->state));
10591060
first_clone = 0;
10601061
}
1061-
if (r1_bio->behind_pages) {
1062+
if (r1_bio->behind_bvecs) {
10621063
struct bio_vec *bvec;
10631064
int j;
10641065

@@ -1070,7 +1071,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
10701071
* them all
10711072
*/
10721073
__bio_for_each_segment(bvec, mbio, j, 0)
1073-
bvec->bv_page = r1_bio->behind_pages[j];
1074+
bvec->bv_page = r1_bio->behind_bvecs[j].bv_page;
10741075
if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
10751076
atomic_inc(&r1_bio->behind_remaining);
10761077
}

‎drivers/md/raid1.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct r1bio_s {
101101

102102
struct list_head retry_list;
103103
/* Next two are only valid when R1BIO_BehindIO is set */
104-
struct page **behind_pages;
104+
struct bio_vec *behind_bvecs;
105105
int behind_page_count;
106106
/*
107107
* if the IO is in WRITE direction, then multiple bios are used.

0 commit comments

Comments
 (0)