btrfs: Read stripe len directly in btrfs_rmap_block
PATCH RESEND 1/2 btrfs: Read stripe len directly in btrfs_rmap_block
extent_map::orig_block_len contains the size of a physical stripe when it's used to describe block groups (calculated in read_one_chunk via calc_stripe_length or calculated in decide_stripe_size and then assigned to extent_map::orig_block_len in create_chunk). Exploit this fact to get the size directly rather than opencoding the calculations. No functional changes.
---
Hello David,
You had some reservations for this patch but now I've expanded the changelog to explain why it's safe to do so.
fs/btrfs/block-group.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
fs/btrfs/block-group.c +3 -10
@@ -1628,19 +1628,12 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,return -EIO ; map = em->map_lookup; - data_stripe_length = em->len; + data_stripe_length = em->orig_block_len; io_stripe_size = map->stripe_len; -if (map->type &BTRFS_BLOCK_GROUP_RAID10 ) - data_stripe_length =div_u64 (data_stripe_length, - map->num_stripes / map->sub_stripes); -else if (map->type &BTRFS_BLOCK_GROUP_RAID0 ) - data_stripe_length =div_u64 (data_stripe_length, map->num_stripes); -else if (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) { - data_stripe_length =div_u64 (data_stripe_length, -nr_data_stripes (map)); +/* 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); - } buf =kcalloc (map->num_stripes,sizeof (u64),GFP_NOFS );if (!buf) {
--
2.17.1
PATCH RESEND 2/2 btrfs: Remove dead code exclude_super_stripes
Adresses held in 'logical' array are always guaranteed to fall within the boundaries of the block group. That is, 'start' can never be smaller than cache->start. This invariant follows from the way the address are calculated in btrfs_rmap_block:
stripe_nr = physical - map->stripes[i].physical;
stripe_nr = div64_u64(stripe_nr, map->stripe_len);
bytenr = chunk_start + stripe_nr * io_stripe_size;I.e it's always some IO stripe within the given chunk.
Exploit this invariant to simplify the body of the loop by removing the unnecessary 'if' since its 'else' part is the one always executed.
--- fs/btrfs/block-group.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
fs/btrfs/block-group.c +4 -17
@@ -1712,25 +1712,12 @@ static int exclude_super_stripes(struct btrfs_block_group *cache)return ret;while (nr--) { -u64 start, len; - -if (logical[nr] > cache->start + cache->length) -continue ; - -if (logical[nr] + stripe_len <= cache->start) -continue ; - - start = logical[nr]; -if (start < cache->start) { - start = cache->start; - len = (logical[nr] + stripe_len) - start; - }else { - len =min_t (u64, stripe_len, - cache->start + cache->length - start); - } +u64 len =min_t (u64, stripe_len, + cache->start + cache->length - logical[nr]); cache->bytes_super += len; - ret =btrfs_add_excluded_extent (fs_info, start, len); + ret =btrfs_add_excluded_extent (fs_info, logical[nr], + len);if (ret) {kfree (logical);return ret;
--
2.17.1
Quoted 33 lines · Nikolay Borisov
extent_map::orig_block_lencontains the size of a physical stripe when it's used to describe block groups (calculated inread_one_chunkviacalc_stripe_lengthor calculated indecide_stripe_sizeand then assigned toextent_map::orig_block_lenincreate_chunk). Exploit this fact to get the size directly rather than opencoding the calculations. No functional changes.Signed-off-by Nikolay Borisov <[email protected]>---
Hello David,
You had some reservations for this patch but now I've expanded the changelog to explain why it's safe to do so.
fs/btrfs/block-group.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)fs/btrfs/block-group.c +1
-4@@ -1628,19 +1628,12 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,return -EIO ; map = em->map_lookup; - data_stripe_length = em->len; + data_stripe_length = em->orig_block_len; io_stripe_size = map->stripe_len; -if (map->type &BTRFS_BLOCK_GROUP_RAID10 ) - data_stripe_length =div_u64 (data_stripe_length, - map->num_stripes / map->sub_stripes);
fs/btrfs/block-group.c int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, · line 1637
Quoted 10 lines
fs/btrfs/block-group.c +2
-6-else if (map->type &BTRFS_BLOCK_GROUP_RAID0 ) - data_stripe_length =div_u64 (data_stripe_length, map->num_stripes); -else if (map->type &BTRFS_BLOCK_GROUP_RAID56_MASK ) { - data_stripe_length =div_u64 (data_stripe_length, -nr_data_stripes (map)); +/* 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); - }
So now data_stripe_length is different in the RAID1 case and the RAID1C* case, right? Is that ok? I *think* it is, but I'm a little drunk and can't really reason it out well. Thanks,
Josef
Quoted 45 lines · Josef Bacik
Quoted 44 lines · Nikolay Borisov
extent_map::orig_block_lencontains the size of a physical stripe when it's used to describe block groups (calculated inread_one_chunkviacalc_stripe_lengthor calculated indecide_stripe_sizeand then assigned toextent_map::orig_block_lenincreate_chunk). Exploit this fact to get the size directly rather than opencoding the calculations. No functional changes.Signed-off-by Nikolay Borisov <[email protected]>---
Hello David,
You had some reservations for this patch but now I've expanded the changelog to
explain why it's safe to do so.
fs/btrfs/block-group.c| 13 +++----------1 file changed, 3 insertions(+), 10 deletions(-)fs/btrfs/block-group.c +2
-9@@ -1628,19 +1628,12 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, return -EIO; map = em->map_lookup; - data_stripe_length = em->len; + data_stripe_length = em->orig_block_len; io_stripe_size = map->stripe_len; - if (map->type & BTRFS_BLOCK_GROUP_RAID10) - data_stripe_length = div_u64(data_stripe_length, - map->num_stripes / map->sub_stripes); - else if (map->type & BTRFS_BLOCK_GROUP_RAID0) - data_stripe_length = div_u64(data_stripe_length, map->num_stripes); - else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { - data_stripe_length = div_u64(data_stripe_length, - nr_data_stripes(map)); + /* For raid5/6 adjust to a full IO stripe length */
Quoted 8 lines
fs/btrfs/block-group.c int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, · line 1637
Quoted 4 lines
fs/btrfs/block-group.c +1
-1+ if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) io_stripe_size = map->stripe_len * nr_data_stripes(map); - }So now
data_stripe_lengthis different in the RAID1 case and the RAID1C* case, right? Is that ok? I *think* it is, but I'm a little drunk and can't really reason it out well. Thanks,
The stripe for RAID1C* is calculated in decide_stripe_size_regular based on the data in btrfs_raid_array. This patch only gets whatever was calculated at chunk allocation time.
Quoted 2 lines
Josef
Quoted 6 lines · Nikolay Borisov
extent_map::orig_block_lencontains the size of a physical stripe when it's used to describe block groups (calculated inread_one_chunkviacalc_stripe_lengthor calculated indecide_stripe_sizeand then assigned toextent_map::orig_block_lenincreate_chunk). Exploit this fact to get the size directly rather than opencoding the calculations. No functional changes.
Quoted 8 lines
Signed-off-by Nikolay Borisov <[email protected]>---
Hello David,
You had some reservations for this patch but now I've expanded the changelog to explain why it's safe to do so.
Ping
Quoted 6 lines · Nikolay Borisov
extent_map::orig_block_lencontains the size of a physical stripe when it's used to describe block groups (calculated inread_one_chunkviacalc_stripe_lengthor calculated indecide_stripe_sizeand then assigned toextent_map::orig_block_lenincreate_chunk). Exploit this fact to get the size directly rather than opencoding the calculations. No functional changes.
Quoted 7 lines
Signed-off-by Nikolay Borisov <[email protected]>---
Hello David,
You had some reservations for this patch but now I've expanded the changelog to explain why it's safe to do so.
I've applied the patches to misc-next, if something goes wrong we'll now. The patches look correct as long as I followed the changelog, but it's not code I know by heart so if there's something missing I'm relying on tests to catch it.