btrfs: reduce div64 calls for __btrfs_map_block() and its variants
v2 cover btrfs: reduce div64 calls for __btrfs_map_block() and its variants
Changelog:
v2:
- Fix a linkage error for 32bits platform in block-group.c We have a line "stripe_nr = (stripe_nr * num_stripes + i) / sub_stripes."
In that case, @stripe_nr itself is already u64, thus the division is dividing u64 with u32.
And we can not easily do a forced u32 conversion, as we only have ensured @stripe_nr can be contained in u32.
Even with 10G chunk size in mined, if the RAID10 array has over 26 devices, then we can overflow U32 and cause problems.
For now, keeps the old div_u64 call.
Div64 is much slower than 32 bit division, and only get improved in the most recent CPUs, that's why we have dedicated div64* helpers.
One usage of div64 is in __btrfs_map_block() and its variants, where we got @stripe_nr as u64, and all later division has to go the div64 helpers.
But the truth is, with our current chunk size limit (10G) and fixed stripe length (64K), we can have at most 160K stripes in a chunk, which is small enough for u32 already.
So this patchset would reduce div64 calls by:
- Remove map_lookup::stripe_len first
So now we don't need to call div64 to calculate @stripe_nr, just a simple right shift, then truncate to u32.
This is a prerequisite for the 2nd patch, without the fixed stripe length, we have to rely on div64.
- Reduce the width of various @stripe_nr to 32
- Use regular divitsion and module to do the calculation Now we can get rid of the fear that we missed some div64 helpers.
Qu Wenruo (2):
btrfs: remove map_lookup->stripe_len
btrfs: reduce div64 calls by limiting the number of stripes of a chunk
to u32
fs/btrfs/block-group.c | 22 +++--- fs/btrfs/scrub.c | 43 ++++++------ fs/btrfs/tests/extent-map-tests.c | 1 - fs/btrfs/tree-checker.c | 14 ++++ fs/btrfs/volumes.c | 110 +++++++++++++++--------------- fs/btrfs/volumes.h | 7 +- 6 files changed, 106 insertions(+), 91 deletions(-)
Signature · 1 line
2.39.1
PATCH v2 1/2 btrfs: remove map_lookup->stripe_len
Currently btrfs doesn't support stripe lengths other than 64KiB. This is already in the tree-checker.
Thus there is really no meaning to record that fixed value in map_lookup, and can all be replaced with BTRFS_STRIPE_LEN.
Furthermore we can introduce BTRFS_STRIPE_LEN_SHIFT to change a lot of multiplication to shift.
--- fs/btrfs/block-group.c | 6 ++--- fs/btrfs/scrub.c | 43 +++++++++++++++---------------- fs/btrfs/tests/extent-map-tests.c | 1 - fs/btrfs/volumes.c | 39 ++++++++++++---------------- fs/btrfs/volumes.h | 5 +++- 5 files changed, 44 insertions(+), 50 deletions(-)
fs/btrfs/block-group.c +3 -3
@@ -1994,12 +1994,12 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, map = em->map_lookup; data_stripe_length = em->orig_block_len; - io_stripe_size = map->stripe_len; + io_stripe_size =BTRFS_STRIPE_LEN ; chunk_start = em->start;/* For RAID5/6 adjust to a full IO stripe length */ if (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) - io_stripe_size = map->stripe_len *nr_data_stripes (map); + io_stripe_size =nr_data_stripes (map) <<BTRFS_STRIPE_LEN_SHIFT ; buf =kcalloc (map->num_stripes,sizeof (u64),GFP_NOFS );if (!buf) {
@@ -2021,7 +2021,7 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,continue ; stripe_nr = physical - map->stripes[i].physical; - stripe_nr =div64_u64_rem (stripe_nr, map->stripe_len, &offset); + stripe_nr =div64_u64_rem (stripe_nr,BTRFS_STRIPE_LEN , &offset);if (map->type & (BTRFS_BLOCK_GROUP_RAID0 |BTRFS_BLOCK_GROUP_RAID10 )) {
fs/btrfs/scrub.c +21 -22
157 lines not on this page · raw message
fs/btrfs/tests/extent-map-tests.c +0 -1
@@ -486,7 +486,6 @@ static int test_rmap_block(struct btrfs_fs_info *fs_info, em->map_lookup = map; map->num_stripes = test->num_stripes; - map->stripe_len =BTRFS_STRIPE_LEN ; map->type = test->raid_type;for (i =0 ; i < map->num_stripes; i++) {
fs/btrfs/volumes.c +16 -23
@@ -5095,7 +5095,7 @@ static void init_alloc_chunk_ctl_policy_regular(/* We don't want a chunk larger than 10% of writable space */ ctl->max_chunk_size =min (mult_perc (fs_devices->total_rw_bytes,10 ), ctl->max_chunk_size); - ctl->dev_extent_min =BTRFS_STRIPE_LEN * ctl->dev_stripes; + ctl->dev_extent_min = ctl->dev_stripes <<BTRFS_STRIPE_LEN_SHIFT ; } static void init_alloc_chunk_ctl_policy_zoned(
@@ -5377,7 +5377,6 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans, j * ctl->stripe_size; } } - map->stripe_len =BTRFS_STRIPE_LEN ; map->io_align =BTRFS_STRIPE_LEN ; map->io_width =BTRFS_STRIPE_LEN ; map->type = type;
@@ -5585,11 +5584,11 @@ int btrfs_chunk_alloc_add_chunk_item(struct btrfs_trans_handle *trans,btrfs_set_stack_chunk_length (chunk, bg->length);btrfs_set_stack_chunk_owner (chunk,BTRFS_EXTENT_TREE_OBJECTID ); -btrfs_set_stack_chunk_stripe_len (chunk, map->stripe_len); +btrfs_set_stack_chunk_stripe_len (chunk,BTRFS_STRIPE_LEN );btrfs_set_stack_chunk_type (chunk, map->type);btrfs_set_stack_chunk_num_stripes (chunk, map->num_stripes); -btrfs_set_stack_chunk_io_align (chunk, map->stripe_len); -btrfs_set_stack_chunk_io_width (chunk, map->stripe_len); +btrfs_set_stack_chunk_io_align (chunk,BTRFS_STRIPE_LEN ); +btrfs_set_stack_chunk_io_width (chunk,BTRFS_STRIPE_LEN );btrfs_set_stack_chunk_sector_size (chunk, fs_info->sectorsize);btrfs_set_stack_chunk_sub_stripes (chunk, map->sub_stripes);
@@ -5779,7 +5778,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,if (!WARN_ON (IS_ERR (em))) { map = em->map_lookup;if (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) - len = map->stripe_len *nr_data_stripes (map); + len =nr_data_stripes (map) <<BTRFS_STRIPE_LEN_SHIFT ;free_extent_map (em); }return len;
@@ -5945,7 +5944,6 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info,u64 stripe_nr_end;u64 stripe_end_offset;u64 stripe_cnt; -u64 stripe_len;u64 stripe_offset;u32 stripe_index;u32 factor =0 ;
@@ -5972,20 +5970,19 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info, length =min_t (u64, em->start + em->len - logical, length); *length_ret = length; - stripe_len = map->stripe_len;/* * stripe_nr counts the total number of stripes we have to stride * to get to this block */ - stripe_nr =div64_u64 (offset, stripe_len); + stripe_nr =div64_u64 (offset,BTRFS_STRIPE_LEN );/* stripe_offset is the offset of this block in its stripe */ - stripe_offset = offset - stripe_nr * stripe_len; + stripe_offset = offset - (stripe_nr <<BTRFS_STRIPE_LEN_SHIFT ); - stripe_nr_end =round_up (offset + length, map->stripe_len); - stripe_nr_end =div64_u64 (stripe_nr_end, map->stripe_len); + stripe_nr_end =round_up (offset + length,BTRFS_STRIPE_LEN ); + stripe_nr_end =div64_u64 (stripe_nr_end,BTRFS_STRIPE_LEN ); stripe_cnt = stripe_nr_end - stripe_nr; - stripe_end_offset = stripe_nr_end * map->stripe_len - + stripe_end_offset = (stripe_nr_end <<BTRFS_STRIPE_LEN_SHIFT ) - (offset + length);/* * after this, stripe_nr is the number of stripes on this
@@ -6027,15 +6024,15 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info,for (i =0 ; i < *num_stripes; i++) { stripes[i].physical = map->stripes[stripe_index].physical + - stripe_offset + stripe_nr * map->stripe_len; + stripe_offset + (stripe_nr <<BTRFS_STRIPE_LEN_SHIFT ); stripes[i].dev = map->stripes[stripe_index].dev;if (map->type & (BTRFS_BLOCK_GROUP_RAID0 |BTRFS_BLOCK_GROUP_RAID10 )) { - stripes[i].length = stripes_per_dev * map->stripe_len; + stripes[i].length = stripes_per_dev <<BTRFS_STRIPE_LEN_SHIFT ;if (i / sub_stripes < remaining_stripes) - stripes[i].length += map->stripe_len; + stripes[i].length +=BTRFS_STRIPE_LEN ;/* * Special for the first stripe and
@@ -6289,11 +6286,11 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *em, struct btrfs_io_geometry *io_geom) {struct map_lookup *map; +const u32 stripe_len =BTRFS_STRIPE_LEN ;u64 len;u64 offset;u64 stripe_offset;u64 stripe_nr; -u32 stripe_len;u64 raid56_full_stripe_start = (u64)-1 ;int data_stripes;
@@ -6302,8 +6299,6 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *em, map = em->map_lookup;/* Offset of this logical address in the chunk */ offset = logical - em->start; -/* Len of a stripe in a chunk */ - stripe_len = map->stripe_len;/* * Stripe_nr is where this block falls in * stripe_offset is the offset of this block in its stripe.
@@ -6362,7 +6357,7 @@ static void set_io_stripe(struct btrfs_io_stripe *dst, const struct map_lookup * { dst->dev = map->stripes[stripe_index].dev; dst->physical = map->stripes[stripe_index].physical + - stripe_offset + stripe_nr * map->stripe_len; + stripe_offset + (stripe_nr <<BTRFS_STRIPE_LEN_SHIFT ); } int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
@@ -6481,7 +6476,6 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, } }else if (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) { -ASSERT (map->stripe_len ==BTRFS_STRIPE_LEN );if (need_raid_map && (need_full_stripe (op) || mirror_num >1 )) {/* push stripe_nr back to the start of the full stripe */ stripe_nr = div64_u64(raid56_full_stripe_start,
@@ -6589,7 +6583,7 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, tmp = stripe_nr * data_stripes;for (i =0 ; i < data_stripes; i++) bioc->raid_map[(i + rot) % num_stripes] = - em->start + (tmp + i) * map->stripe_len; + em->start + ((tmp + i) <<BTRFS_STRIPE_LEN_SHIFT ); bioc->raid_map[(i + rot) % map->num_stripes] =RAID5_P_STRIPE ;if (map->type &BTRFS_BLOCK_GROUP_RAID6 )
@@ -6962,7 +6956,6 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf, map->num_stripes = num_stripes; map->io_width =btrfs_chunk_io_width (leaf, chunk); map->io_align =btrfs_chunk_io_align (leaf, chunk); - map->stripe_len =btrfs_chunk_stripe_len (leaf, chunk); map->type = type;/* * We can't use the sub_stripes value, as for profiles other than
fs/btrfs/volumes.h +4 -1
@@ -19,6 +19,10 @@ extern struct mutex uuid_mutex;#define BTRFS_STRIPE_LEN SZ_64K +#define BTRFS_STRIPE_LEN_SHIFT (16) + +static_assert ((1 <<BTRFS_STRIPE_LEN_SHIFT ) ==BTRFS_STRIPE_LEN ); +/* Used by sanity check for btrfs_raid_types. */ #define const_ffs (n) (__builtin_ctzll(n) + 1)
@@ -461,7 +465,6 @@ struct map_lookup {u64 type;int io_align;int io_width; -u32 stripe_len;int num_stripes;int sub_stripes;int verified_stripes;/* For mount time dev extent verification */
Signature · 1 line
2.39.1
PATCH v2 2/2 btrfs: reduce div64 calls by limiting the number of stripes of a chunk to u32
In reply to Qu WenruoThere are quite some div64 calls inside btrfs_map_block() and its variants.
One of such calls are for @stripe_nr, where @stripe_nr is the number of stripes before our logical bytenr inside a chunk.
However we can eliminate such div64 calls by just reducing the width of @stripe_nr from 64 to 32.
This can be done because our chunk size limit is already 10G, with fixed stripe length 64K.
Thus a U32 is definitely enough to contain the number of stripes.
With such width reduction, we can get rid of slower div64, and extra warning for certain 32bit arch.
This patch would do:
- Reduce the width of various stripe_nr variables
- Add a new tree-checker chunk validation on chunk length Make sure no chunk can reach 256G, which can also act as a bitflip checker.
- Replace unnecessary div64 calls with regular modulo and division 32bit division and modulo are much faster than 64bit operations, and we are finally free of the div64 fear at least in those involved functions.
--- fs/btrfs/block-group.c | 18 +++++----- fs/btrfs/tree-checker.c | 14 ++++++++ fs/btrfs/volumes.c | 79 ++++++++++++++++++++++------------------- fs/btrfs/volumes.h | 2 +- 4 files changed, 67 insertions(+), 46 deletions(-)
fs/btrfs/block-group.c +9 -9
@@ -2009,8 +2009,8 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, for (i = 0; i < map->num_stripes; i++) { bool already_inserted = false; - u64 stripe_nr; - u64 offset; + u32 stripe_nr; + u32 offset; int j; if (!in_range(physical, map->stripes[i].physical,
@@ -2020,20 +2020,20 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,if (bdev && map->stripes[i].dev->bdev != bdev)continue ; - stripe_nr = physical - map->stripes[i].physical; - stripe_nr =div64_u64_rem (stripe_nr,BTRFS_STRIPE_LEN , &offset); + stripe_nr = (physical - map->stripes[i].physical) >> +BTRFS_STRIPE_LEN_SHIFT ; + offset = (physical - map->stripes[i].physical) & + ((1 <<BTRFS_STRIPE_LEN_SHIFT ) -1 );if (map->type & (BTRFS_BLOCK_GROUP_RAID0 | -BTRFS_BLOCK_GROUP_RAID10 )) { - stripe_nr = stripe_nr * map->num_stripes + i; - stripe_nr =div_u64 (stripe_nr, map->sub_stripes); - } +BTRFS_BLOCK_GROUP_RAID10 )) + stripe_nr =div_u64 (stripe_nr * map->num_stripes +1 , + map->sub_stripes);/* * The remaining case would be for RAID56, multiply by * nr_data_stripes(). Alternatively, just use rmap_len below * instead of map->stripe_len */ - bytenr = chunk_start + stripe_nr * io_stripe_size + offset;/* Ensure we don't add duplicate addresses */
fs/btrfs/tree-checker.c +14 -0
@@ -849,6 +849,20 @@ int btrfs_check_chunk_valid(struct extent_buffer *leaf, stripe_len);return -EUCLEAN ; } +/* +* We artificially limit the chunk size, so that the number of stripes +* inside a chunk can be fit into a U32. +* The current limit (256G) would be way too large for real world usage +* anyway, and it's already way larger than our existing limit (10G). +* +* Thus it should be a good way to catch obvious bitflip. +*/ +if (unlikely (((u64 )U32_MAX <<BTRFS_STRIPE_LEN_SHIFT ) <= length)) { +chunk_err (leaf, chunk, logical, +"chunk length too large: have %llu limit %llu" , + length, (u64 )U32_MAX <<BTRFS_STRIPE_LEN_SHIFT ); +return -EUCLEAN ; + }if (unlikely (type & ~(BTRFS_BLOCK_GROUP_TYPE_MASK |BTRFS_BLOCK_GROUP_PROFILE_MASK ))) { chunk_err(leaf, chunk, logical,
fs/btrfs/volumes.c +43 -36
206 lines not on this page · raw message
fs/btrfs/volumes.h +1 -1
@@ -67,7 +67,7 @@ struct btrfs_io_geometry {/* offset of address in stripe */ u32 stripe_offset;/* number of stripe where address falls */ -u64 stripe_nr; +u32 stripe_nr;/* offset of raid56 stripe into the chunk */ u64 raid56_stripe_offset; };
Signature · 1 line
2.39.1
Re: [PATCH v2 2/2] btrfs: reduce div64 calls by limiting the number of stripes of a chunk to u32
Quoted 20 lines · Qu Wenruo
There are quite some div64 calls inside
btrfs_map_block()and its variants.One of such calls are for @stripe_nr, where @stripe_nr is the number of stripes before our logical bytenr inside a chunk.
However we can eliminate such div64 calls by just reducing the width of @stripe_nr from 64 to 32.
This can be done because our chunk size limit is already 10G, with fixed stripe length 64K.
Thus a U32 is definitely enough to contain the number of stripes.With such width reduction, we can get rid of slower div64, and extra warning for certain 32bit arch.
This patch would do:
- Reduce the width of various
stripe_nrvariables
Quoted 9 lines
- Add a new tree-checker chunk validation on chunk length Make sure no chunk can reach 256G, which can also act as a bitflip checker.
- Replace unnecessary div64 calls with regular modulo and division 32bit division and modulo are much faster than 64bit operations, and we are finally free of the div64 fear at least in those involved functions.
Sound good. However, it appears that some of the changes should have been part of the patch 1; for instance, the %full_stripe_len in the function btrfs_get_io_geometry().
Thanks, Anand
Quoted 313 lines
Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/block-group.c | 18 +++++----- fs/btrfs/tree-checker.c | 14 ++++++++ fs/btrfs/volumes.c | 79 ++++++++++++++++++++++------------------- fs/btrfs/volumes.h | 2 +- 4 files changed, 67 insertions(+), 46 deletions(-)fs/btrfs/block-group.c +9
-9@@ -2009,8 +2009,8 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, for (i = 0; i < map->num_stripes; i++) { bool already_inserted = false; - u64 stripe_nr; - u64 offset; + u32 stripe_nr; + u32 offset; int j; if (!in_range(physical, map->stripes[i].physical,@@ -2020,20 +2020,20 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,if (bdev && map->stripes[i].dev->bdev != bdev)continue ; - stripe_nr = physical - map->stripes[i].physical; - stripe_nr =div64_u64_rem (stripe_nr,BTRFS_STRIPE_LEN , &offset); + stripe_nr = (physical - map->stripes[i].physical) >> +BTRFS_STRIPE_LEN_SHIFT ; + offset = (physical - map->stripes[i].physical) & + ((1 <<BTRFS_STRIPE_LEN_SHIFT ) -1 );if (map->type & (BTRFS_BLOCK_GROUP_RAID0 | -BTRFS_BLOCK_GROUP_RAID10 )) { - stripe_nr = stripe_nr * map->num_stripes + i; - stripe_nr =div_u64 (stripe_nr, map->sub_stripes); - } +BTRFS_BLOCK_GROUP_RAID10 )) + stripe_nr =div_u64 (stripe_nr * map->num_stripes +1 , + map->sub_stripes);/* * The remaining case would be for RAID56, multiply by * nr_data_stripes(). Alternatively, just use rmap_len below * instead of map->stripe_len */ - bytenr = chunk_start + stripe_nr * io_stripe_size + offset;/* Ensure we don't add duplicate addresses */ fs/btrfs/tree-checker.c +14
-0@@ -849,6 +849,20 @@ int btrfs_check_chunk_valid(struct extent_buffer *leaf, stripe_len);return -EUCLEAN ; } +/* +* We artificially limit the chunk size, so that the number of stripes +* inside a chunk can be fit into a U32. +* The current limit (256G) would be way too large for real world usage +* anyway, and it's already way larger than our existing limit (10G). +* +* Thus it should be a good way to catch obvious bitflip. +*/ +if (unlikely (((u64 )U32_MAX <<BTRFS_STRIPE_LEN_SHIFT ) <= length)) { +chunk_err (leaf, chunk, logical, +"chunk length too large: have %llu limit %llu" , + length, (u64 )U32_MAX <<BTRFS_STRIPE_LEN_SHIFT ); +return -EUCLEAN ; + }if (unlikely (type & ~(BTRFS_BLOCK_GROUP_TYPE_MASK |BTRFS_BLOCK_GROUP_PROFILE_MASK ))) { chunk_err(leaf, chunk, logical,fs/btrfs/volumes.c +43
-36@@ -5940,15 +5940,15 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info,struct btrfs_discard_stripe *stripes;u64 length = *length_ret;u64 offset; -u64 stripe_nr; -u64 stripe_nr_end; +u32 stripe_nr; +u32 stripe_nr_end; +u32 stripe_cnt;u64 stripe_end_offset; -u64 stripe_cnt;u64 stripe_offset;u32 stripe_index;u32 factor =0 ;u32 sub_stripes =0 ; -u64 stripes_per_dev =0 ; +u32 stripes_per_dev =0 ;u32 remaining_stripes =0 ;u32 last_stripe =0 ;int ret;@@ -5974,13 +5974,13 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info,* stripe_nr counts the total number of stripes we have to stride * to get to this block */ - stripe_nr =div64_u64 (offset,BTRFS_STRIPE_LEN ); + stripe_nr = offset >>BTRFS_STRIPE_LEN_SHIFT ;/* stripe_offset is the offset of this block in its stripe */ stripe_offset = offset - (stripe_nr <<BTRFS_STRIPE_LEN_SHIFT ); - stripe_nr_end =round_up (offset + length,BTRFS_STRIPE_LEN ); - stripe_nr_end =div64_u64 (stripe_nr_end,BTRFS_STRIPE_LEN ); + stripe_nr_end =round_up (offset + length,BTRFS_STRIPE_LEN ) >> +BTRFS_STRIPE_LEN_SHIFT ; stripe_cnt = stripe_nr_end - stripe_nr; stripe_end_offset = (stripe_nr_end <<BTRFS_STRIPE_LEN_SHIFT ) - (offset + length);@@ -6001,18 +6001,18 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info, factor = map->num_stripes / sub_stripes; *num_stripes =min_t (u64, map->num_stripes, sub_stripes * stripe_cnt); - stripe_nr =div_u64_rem (stripe_nr, factor, &stripe_index); + stripe_index = stripe_nr % factor; + stripe_nr /= factor; stripe_index *= sub_stripes; stripes_per_dev =div_u64_rem (stripe_cnt, factor, &remaining_stripes); -div_u64_rem (stripe_nr_end -1 , factor, &last_stripe); - last_stripe *= sub_stripes; + last_stripe = (stripe_nr_end -1 ) % factor * sub_stripes; }else if (map->type & (BTRFS_BLOCK_GROUP_RAID1_MASK |BTRFS_BLOCK_GROUP_DUP )) { *num_stripes = map->num_stripes; }else { - stripe_nr =div_u64_rem (stripe_nr, map->num_stripes, - &stripe_index); + stripe_index = stripe_nr % map->num_stripes; + stripe_nr /= map->num_stripes; } stripes =kcalloc (*num_stripes,sizeof (*stripes),GFP_NOFS );@@ -6286,11 +6286,10 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *em, struct btrfs_io_geometry *io_geom) {struct map_lookup *map; -const u32 stripe_len =BTRFS_STRIPE_LEN ;u64 len;u64 offset;u64 stripe_offset; -u64 stripe_nr; +u32 stripe_nr;u64 raid56_full_stripe_start = (u64)-1 ;int data_stripes;@@ -6303,20 +6302,22 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *em,* Stripe_nr is where this block falls in * stripe_offset is the offset of this block in its stripe. */ - stripe_nr =div64_u64_rem (offset, stripe_len, &stripe_offset); + stripe_offset = offset & ((1 <<BTRFS_STRIPE_LEN_SHIFT ) -1 ); + stripe_nr = offset >>BTRFS_STRIPE_LEN_SHIFT ;ASSERT (stripe_offset <U32_MAX ); data_stripes =nr_data_stripes (map);/* Only stripe based profiles needs to check against stripe length. */ if (map->type &BTRFS_BLOCK_GROUP_STRIPE_MASK ) { -u64 max_len = stripe_len - stripe_offset; +u64 max_len =BTRFS_STRIPE_LEN - stripe_offset;/* * In case of raid56, we need to know the stripe aligned start */ if (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) { -unsigned long full_stripe_len = stripe_len * data_stripes; +unsigned long full_stripe_len = data_stripes << +BTRFS_STRIPE_LEN_SHIFT ; raid56_full_stripe_start = offset;/* @@ -6333,7 +6334,7 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *em,* reads, just allow a single stripe (on a single disk). */ if (op ==BTRFS_MAP_WRITE ) { - max_len = stripe_len * data_stripes - + max_len = (data_stripes <<BTRFS_STRIPE_LEN_SHIFT ) - (offset - raid56_full_stripe_start); } }@@ -6344,7 +6345,7 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *em, io_geom->len = len; io_geom->offset = offset; - io_geom->stripe_len = stripe_len; + io_geom->stripe_len =BTRFS_STRIPE_LEN ; io_geom->stripe_nr = stripe_nr; io_geom->stripe_offset = stripe_offset; io_geom->raid56_stripe_offset = raid56_full_stripe_start;@@ -6353,7 +6354,7 @@ int btrfs_get_io_geometry(struct btrfs_fs_info *fs_info, struct extent_map *em, }static void set_io_stripe (struct btrfs_io_stripe *dst,const struct map_lookup *map, -u32 stripe_index,u64 stripe_offset,u64 stripe_nr) +u32 stripe_index,u64 stripe_offset,u32 stripe_nr) { dst->dev = map->stripes[stripe_index].dev; dst->physical = map->stripes[stripe_index].physical +@@ -6369,8 +6370,8 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,struct extent_map *em;struct map_lookup *map;u64 stripe_offset; -u64 stripe_nr;u64 stripe_len; +u32 stripe_nr;u32 stripe_index;int data_stripes;int i;@@ -6433,8 +6434,8 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, num_stripes =1 ; stripe_index =0 ;if (map->type &BTRFS_BLOCK_GROUP_RAID0 ) { - stripe_nr =div_u64_rem (stripe_nr, map->num_stripes, - &stripe_index); + stripe_index = stripe_nr % map->num_stripes; + stripe_nr /= map->num_stripes;if (!need_full_stripe (op)) mirror_num =1 ; }else if (map->type &BTRFS_BLOCK_GROUP_RAID1_MASK ) {@@ -6460,8 +6461,8 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, }else if (map->type &BTRFS_BLOCK_GROUP_RAID10 ) {u32 factor = map->num_stripes / map->sub_stripes; - stripe_nr =div_u64_rem (stripe_nr, factor, &stripe_index); - stripe_index *= map->sub_stripes; + stripe_index = stripe_nr % factor * map->sub_stripes; + stripe_nr /= factor;if (need_full_stripe (op)) num_stripes = map->sub_stripes;@@ -6477,9 +6478,16 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, }else if (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) {if (need_raid_map && (need_full_stripe (op) || mirror_num >1 )) { -/* push stripe_nr back to the start of the full stripe */ - stripe_nr =div64_u64 (raid56_full_stripe_start, - stripe_len * data_stripes); +/* +* Push stripe_nr back to the start of the full stripe +* For those cases needing a full stripe, @stripe_nr +* is the full stripe number. +* +* Original we go raid56_full_stripe_start / full_stripe_len, +* but that can be expensive. +* Here we just divide @stripe_nr with @data_stripes. +*/ + stripe_nr /= data_stripes;/* RAID[56] write or recovery. Return all stripes */ num_stripes = map->num_stripes;@@ -6497,25 +6505,24 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,* Mirror #2 is RAID5 parity block. * Mirror #3 is RAID6 Q block. */ - stripe_nr =div_u64_rem (stripe_nr, - data_stripes, &stripe_index); + stripe_index = stripe_nr % data_stripes; + stripe_nr /= data_stripes;if (mirror_num >1 ) stripe_index = data_stripes + mirror_num -2 ;/* We distribute the parity blocks across stripes */ -div_u64_rem (stripe_nr + stripe_index, map->num_stripes, - &stripe_index); + stripe_index = (stripe_nr + stripe_index) % map->num_stripes;if (!need_full_stripe (op) && mirror_num <=1 ) mirror_num =1 ; } }else {/* -* after this, stripe_nr is the number of stripes on this +* After this, stripe_nr is the number of stripes on this * device we have to walk to find the data, and stripe_index is * the number of our device in the stripe array */ - stripe_nr =div_u64_rem (stripe_nr, map->num_stripes, - &stripe_index); + stripe_index = stripe_nr % map->num_stripes; + stripe_nr /= map->num_stripes; mirror_num = stripe_index +1 ; }if (stripe_index >= map->num_stripes) {@@ -6577,7 +6584,7 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,unsigned rot;/* Work out the disk rotation on this stripe-set */ -div_u64_rem (stripe_nr, num_stripes, &rot); + rot = stripe_nr % num_stripes;/* Fill in the logical address of each stripe */ tmp = stripe_nr * data_stripes;fs/btrfs/volumes.h +1
-1@@ -67,7 +67,7 @@ struct btrfs_io_geometry {/* offset of address in stripe */ u32 stripe_offset;/* number of stripe where address falls */ -u64 stripe_nr; +u32 stripe_nr;/* offset of raid56 stripe into the chunk */ u64 raid56_stripe_offset; };