diff options
author | Zhao Lei <zhaolei@cn.fujitsu.com> | 2015-03-03 07:38:46 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2016-01-20 10:22:16 -0500 |
commit | b7178a5f0372a51260cf6e74d828e315e43dfc86 (patch) | |
tree | 2791d81ab923fd046de7b8f944714b7079c72d97 /fs | |
parent | bfca9a6d4b1322ba36235e8a652f05a9668ef59b (diff) |
btrfs: Use unified stripe_page's index calculation
We are using different index calculation method for stripe_page in
current code:
1: (rbio->stripe_len / PAGE_CACHE_SIZE) * stripe_index + page_index
2: DIV_ROUND_UP(rbio->stripe_len, PAGE_CACHE_SIZE) * stripe_index + page_index
3: DIV_ROUND_UP(rbio->stripe_len * stripe_index, PAGE_CACHE_SIZE) + page_index
...
They can get same result when stripe_len align to PAGE_CACHE_SIZE,
this is why current code can work, intruduce and use a common function
for calculation is a better choose.
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/raid56.c | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index 9ee11b41ba5d..c435fe0f86e4 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c | |||
@@ -609,13 +609,28 @@ static int rbio_can_merge(struct btrfs_raid_bio *last, | |||
609 | return 1; | 609 | return 1; |
610 | } | 610 | } |
611 | 611 | ||
612 | static int rbio_stripe_page_index(struct btrfs_raid_bio *rbio, int stripe, | ||
613 | int index) | ||
614 | { | ||
615 | return stripe * rbio->stripe_npages + index; | ||
616 | } | ||
617 | |||
618 | /* | ||
619 | * these are just the pages from the rbio array, not from anything | ||
620 | * the FS sent down to us | ||
621 | */ | ||
622 | static struct page *rbio_stripe_page(struct btrfs_raid_bio *rbio, int stripe, | ||
623 | int index) | ||
624 | { | ||
625 | return rbio->stripe_pages[rbio_stripe_page_index(rbio, stripe, index)]; | ||
626 | } | ||
627 | |||
612 | /* | 628 | /* |
613 | * helper to index into the pstripe | 629 | * helper to index into the pstripe |
614 | */ | 630 | */ |
615 | static struct page *rbio_pstripe_page(struct btrfs_raid_bio *rbio, int index) | 631 | static struct page *rbio_pstripe_page(struct btrfs_raid_bio *rbio, int index) |
616 | { | 632 | { |
617 | index += (rbio->nr_data * rbio->stripe_len) >> PAGE_CACHE_SHIFT; | 633 | return rbio_stripe_page(rbio, rbio->nr_data, index); |
618 | return rbio->stripe_pages[index]; | ||
619 | } | 634 | } |
620 | 635 | ||
621 | /* | 636 | /* |
@@ -626,10 +641,7 @@ static struct page *rbio_qstripe_page(struct btrfs_raid_bio *rbio, int index) | |||
626 | { | 641 | { |
627 | if (rbio->nr_data + 1 == rbio->real_stripes) | 642 | if (rbio->nr_data + 1 == rbio->real_stripes) |
628 | return NULL; | 643 | return NULL; |
629 | 644 | return rbio_stripe_page(rbio, rbio->nr_data + 1, index); | |
630 | index += ((rbio->nr_data + 1) * rbio->stripe_len) >> | ||
631 | PAGE_CACHE_SHIFT; | ||
632 | return rbio->stripe_pages[index]; | ||
633 | } | 645 | } |
634 | 646 | ||
635 | /* | 647 | /* |
@@ -947,8 +959,7 @@ static struct page *page_in_rbio(struct btrfs_raid_bio *rbio, | |||
947 | */ | 959 | */ |
948 | static unsigned long rbio_nr_pages(unsigned long stripe_len, int nr_stripes) | 960 | static unsigned long rbio_nr_pages(unsigned long stripe_len, int nr_stripes) |
949 | { | 961 | { |
950 | unsigned long nr = stripe_len * nr_stripes; | 962 | return DIV_ROUND_UP(stripe_len, PAGE_CACHE_SIZE) * nr_stripes; |
951 | return DIV_ROUND_UP(nr, PAGE_CACHE_SIZE); | ||
952 | } | 963 | } |
953 | 964 | ||
954 | /* | 965 | /* |
@@ -1026,13 +1037,13 @@ static int alloc_rbio_pages(struct btrfs_raid_bio *rbio) | |||
1026 | return 0; | 1037 | return 0; |
1027 | } | 1038 | } |
1028 | 1039 | ||
1029 | /* allocate pages for just the p/q stripes */ | 1040 | /* only allocate pages for p/q stripes */ |
1030 | static int alloc_rbio_parity_pages(struct btrfs_raid_bio *rbio) | 1041 | static int alloc_rbio_parity_pages(struct btrfs_raid_bio *rbio) |
1031 | { | 1042 | { |
1032 | int i; | 1043 | int i; |
1033 | struct page *page; | 1044 | struct page *page; |
1034 | 1045 | ||
1035 | i = (rbio->nr_data * rbio->stripe_len) >> PAGE_CACHE_SHIFT; | 1046 | i = rbio_stripe_page_index(rbio, rbio->nr_data, 0); |
1036 | 1047 | ||
1037 | for (; i < rbio->nr_pages; i++) { | 1048 | for (; i < rbio->nr_pages; i++) { |
1038 | if (rbio->stripe_pages[i]) | 1049 | if (rbio->stripe_pages[i]) |
@@ -1121,18 +1132,6 @@ static void validate_rbio_for_rmw(struct btrfs_raid_bio *rbio) | |||
1121 | } | 1132 | } |
1122 | 1133 | ||
1123 | /* | 1134 | /* |
1124 | * these are just the pages from the rbio array, not from anything | ||
1125 | * the FS sent down to us | ||
1126 | */ | ||
1127 | static struct page *rbio_stripe_page(struct btrfs_raid_bio *rbio, int stripe, int page) | ||
1128 | { | ||
1129 | int index; | ||
1130 | index = stripe * (rbio->stripe_len >> PAGE_CACHE_SHIFT); | ||
1131 | index += page; | ||
1132 | return rbio->stripe_pages[index]; | ||
1133 | } | ||
1134 | |||
1135 | /* | ||
1136 | * helper function to walk our bio list and populate the bio_pages array with | 1135 | * helper function to walk our bio list and populate the bio_pages array with |
1137 | * the result. This seems expensive, but it is faster than constantly | 1136 | * the result. This seems expensive, but it is faster than constantly |
1138 | * searching through the bio list as we setup the IO in finish_rmw or stripe | 1137 | * searching through the bio list as we setup the IO in finish_rmw or stripe |