Skip to content

Commit a97699d

Browse files
adam900710kdave
authored andcommitted
btrfs: replace map_lookup->stripe_len by BTRFS_STRIPE_LEN
Currently btrfs doesn't support stripe lengths other than 64KiB. This is already set in the tree-checker. There is really no meaning to record that fixed value in map_lookup for now, and can all be replaced with BTRFS_STRIPE_LEN. Furthermore we can use the fix stripe length to do the following optimization: - Use BTRFS_STRIPE_LEN_SHIFT to replace some 64bit division Now we only need to do a right shift. And the value of BTRFS_STRIPE_LEN itself is already too large for bit shift, thus if we accidentally use BTRFS_STRIPE_LEN to do bit shift, a compiler warning would be triggered. Thus this bit shift optimization would be safe. - Use BTRFS_STRIPE_LEN_MASK to calculate the offset inside a stripe Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent dcb2137 commit a97699d

File tree

5 files changed

+66
-60
lines changed

5 files changed

+66
-60
lines changed

fs/btrfs/block-group.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,12 +1977,12 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
19771977

19781978
map = em->map_lookup;
19791979
data_stripe_length = em->orig_block_len;
1980-
io_stripe_size = map->stripe_len;
1980+
io_stripe_size = BTRFS_STRIPE_LEN;
19811981
chunk_start = em->start;
19821982

19831983
/* For RAID5/6 adjust to a full IO stripe length */
19841984
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
1985-
io_stripe_size = map->stripe_len * nr_data_stripes(map);
1985+
io_stripe_size = nr_data_stripes(map) << BTRFS_STRIPE_LEN_SHIFT;
19861986

19871987
buf = kcalloc(map->num_stripes, sizeof(u64), GFP_NOFS);
19881988
if (!buf) {
@@ -2000,8 +2000,10 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
20002000
data_stripe_length))
20012001
continue;
20022002

2003-
stripe_nr = physical - map->stripes[i].physical;
2004-
stripe_nr = div64_u64_rem(stripe_nr, map->stripe_len, &offset);
2003+
stripe_nr = (physical - map->stripes[i].physical) >>
2004+
BTRFS_STRIPE_LEN_SHIFT;
2005+
offset = (physical - map->stripes[i].physical) &
2006+
BTRFS_STRIPE_LEN_MASK;
20052007

20062008
if (map->type & (BTRFS_BLOCK_GROUP_RAID0 |
20072009
BTRFS_BLOCK_GROUP_RAID10)) {

fs/btrfs/scrub.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,7 +2722,7 @@ static int scrub_extent(struct scrub_ctx *sctx, struct map_lookup *map,
27222722

27232723
if (flags & BTRFS_EXTENT_FLAG_DATA) {
27242724
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
2725-
blocksize = map->stripe_len;
2725+
blocksize = BTRFS_STRIPE_LEN;
27262726
else
27272727
blocksize = sctx->fs_info->sectorsize;
27282728
spin_lock(&sctx->stat_lock);
@@ -2731,7 +2731,7 @@ static int scrub_extent(struct scrub_ctx *sctx, struct map_lookup *map,
27312731
spin_unlock(&sctx->stat_lock);
27322732
} else if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
27332733
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
2734-
blocksize = map->stripe_len;
2734+
blocksize = BTRFS_STRIPE_LEN;
27352735
else
27362736
blocksize = sctx->fs_info->nodesize;
27372737
spin_lock(&sctx->stat_lock);
@@ -2920,9 +2920,9 @@ static int get_raid56_logic_offset(u64 physical, int num,
29202920

29212921
*offset = last_offset;
29222922
for (i = 0; i < data_stripes; i++) {
2923-
*offset = last_offset + i * map->stripe_len;
2923+
*offset = last_offset + (i << BTRFS_STRIPE_LEN_SHIFT);
29242924

2925-
stripe_nr = div64_u64(*offset, map->stripe_len);
2925+
stripe_nr = *offset >> BTRFS_STRIPE_LEN_SHIFT;
29262926
stripe_nr = div_u64(stripe_nr, data_stripes);
29272927

29282928
/* Work out the disk rotation on this stripe-set */
@@ -2935,7 +2935,7 @@ static int get_raid56_logic_offset(u64 physical, int num,
29352935
if (stripe_index < num)
29362936
j++;
29372937
}
2938-
*offset = last_offset + j * map->stripe_len;
2938+
*offset = last_offset + (j << BTRFS_STRIPE_LEN_SHIFT);
29392939
return 1;
29402940
}
29412941

@@ -3205,7 +3205,7 @@ static int scrub_raid56_data_stripe_for_parity(struct scrub_ctx *sctx,
32053205
/* Path must not be populated */
32063206
ASSERT(!path->nodes[0]);
32073207

3208-
while (cur_logical < logical + map->stripe_len) {
3208+
while (cur_logical < logical + BTRFS_STRIPE_LEN) {
32093209
struct btrfs_io_context *bioc = NULL;
32103210
struct btrfs_device *extent_dev;
32113211
u64 extent_start;
@@ -3217,7 +3217,7 @@ static int scrub_raid56_data_stripe_for_parity(struct scrub_ctx *sctx,
32173217
u64 extent_mirror_num;
32183218

32193219
ret = find_first_extent_item(extent_root, path, cur_logical,
3220-
logical + map->stripe_len - cur_logical);
3220+
logical + BTRFS_STRIPE_LEN - cur_logical);
32213221
/* No more extent item in this data stripe */
32223222
if (ret > 0) {
32233223
ret = 0;
@@ -3231,7 +3231,7 @@ static int scrub_raid56_data_stripe_for_parity(struct scrub_ctx *sctx,
32313231
/* Metadata should not cross stripe boundaries */
32323232
if ((extent_flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) &&
32333233
does_range_cross_boundary(extent_start, extent_size,
3234-
logical, map->stripe_len)) {
3234+
logical, BTRFS_STRIPE_LEN)) {
32353235
btrfs_err(fs_info,
32363236
"scrub: tree block %llu spanning stripes, ignored. logical=%llu",
32373237
extent_start, logical);
@@ -3247,7 +3247,7 @@ static int scrub_raid56_data_stripe_for_parity(struct scrub_ctx *sctx,
32473247

32483248
/* Truncate the range inside this data stripe */
32493249
extent_size = min(extent_start + extent_size,
3250-
logical + map->stripe_len) - cur_logical;
3250+
logical + BTRFS_STRIPE_LEN) - cur_logical;
32513251
extent_start = cur_logical;
32523252
ASSERT(extent_size <= U32_MAX);
32533253

@@ -3320,8 +3320,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
33203320
path->search_commit_root = 1;
33213321
path->skip_locking = 1;
33223322

3323-
ASSERT(map->stripe_len <= U32_MAX);
3324-
nsectors = map->stripe_len >> fs_info->sectorsize_bits;
3323+
nsectors = BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits;
33253324
ASSERT(nsectors <= BITS_PER_LONG);
33263325
sparity = kzalloc(sizeof(struct scrub_parity), GFP_NOFS);
33273326
if (!sparity) {
@@ -3332,8 +3331,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
33323331
return -ENOMEM;
33333332
}
33343333

3335-
ASSERT(map->stripe_len <= U32_MAX);
3336-
sparity->stripe_len = map->stripe_len;
3334+
sparity->stripe_len = BTRFS_STRIPE_LEN;
33373335
sparity->nsectors = nsectors;
33383336
sparity->sctx = sctx;
33393337
sparity->scrub_dev = sdev;
@@ -3344,7 +3342,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
33443342

33453343
ret = 0;
33463344
for (cur_logical = logic_start; cur_logical < logic_end;
3347-
cur_logical += map->stripe_len) {
3345+
cur_logical += BTRFS_STRIPE_LEN) {
33483346
ret = scrub_raid56_data_stripe_for_parity(sctx, sparity, map,
33493347
sdev, path, cur_logical);
33503348
if (ret < 0)
@@ -3536,7 +3534,7 @@ static u64 simple_stripe_full_stripe_len(const struct map_lookup *map)
35363534
ASSERT(map->type & (BTRFS_BLOCK_GROUP_RAID0 |
35373535
BTRFS_BLOCK_GROUP_RAID10));
35383536

3539-
return map->num_stripes / map->sub_stripes * map->stripe_len;
3537+
return (map->num_stripes / map->sub_stripes) << BTRFS_STRIPE_LEN_SHIFT;
35403538
}
35413539

35423540
/* Get the logical bytenr for the stripe */
@@ -3552,7 +3550,8 @@ static u64 simple_stripe_get_logical(struct map_lookup *map,
35523550
* (stripe_index / sub_stripes) gives how many data stripes we need to
35533551
* skip.
35543552
*/
3555-
return (stripe_index / map->sub_stripes) * map->stripe_len + bg->start;
3553+
return ((stripe_index / map->sub_stripes) << BTRFS_STRIPE_LEN_SHIFT) +
3554+
bg->start;
35563555
}
35573556

35583557
/* Get the mirror number for the stripe */
@@ -3589,14 +3588,14 @@ static int scrub_simple_stripe(struct scrub_ctx *sctx,
35893588
* this stripe.
35903589
*/
35913590
ret = scrub_simple_mirror(sctx, extent_root, csum_root, bg, map,
3592-
cur_logical, map->stripe_len, device,
3591+
cur_logical, BTRFS_STRIPE_LEN, device,
35933592
cur_physical, mirror_num);
35943593
if (ret)
35953594
return ret;
35963595
/* Skip to next stripe which belongs to the target device */
35973596
cur_logical += logical_increment;
35983597
/* For physical offset, we just go to next stripe */
3599-
cur_physical += map->stripe_len;
3598+
cur_physical += BTRFS_STRIPE_LEN;
36003599
}
36013600
return ret;
36023601
}
@@ -3690,7 +3689,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
36903689
if (profile & (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID10)) {
36913690
ret = scrub_simple_stripe(sctx, root, csum_root, bg, map,
36923691
scrub_dev, stripe_index);
3693-
offset = map->stripe_len * (stripe_index / map->sub_stripes);
3692+
offset = (stripe_index / map->sub_stripes) << BTRFS_STRIPE_LEN_SHIFT;
36943693
goto out;
36953694
}
36963695

@@ -3705,7 +3704,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
37053704

37063705
/* Initialize @offset in case we need to go to out: label */
37073706
get_raid56_logic_offset(physical, stripe_index, map, &offset, NULL);
3708-
increment = map->stripe_len * nr_data_stripes(map);
3707+
increment = nr_data_stripes(map) << BTRFS_STRIPE_LEN_SHIFT;
37093708

37103709
/*
37113710
* Due to the rotation, for RAID56 it's better to iterate each stripe
@@ -3736,13 +3735,13 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
37363735
* is still based on @mirror_num.
37373736
*/
37383737
ret = scrub_simple_mirror(sctx, root, csum_root, bg, map,
3739-
logical, map->stripe_len,
3738+
logical, BTRFS_STRIPE_LEN,
37403739
scrub_dev, physical, 1);
37413740
if (ret < 0)
37423741
goto out;
37433742
next:
37443743
logical += increment;
3745-
physical += map->stripe_len;
3744+
physical += BTRFS_STRIPE_LEN;
37463745
spin_lock(&sctx->stat_lock);
37473746
if (stop_loop)
37483747
sctx->stat.last_physical =

fs/btrfs/tests/extent-map-tests.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ static int test_rmap_block(struct btrfs_fs_info *fs_info,
486486
em->map_lookup = map;
487487

488488
map->num_stripes = test->num_stripes;
489-
map->stripe_len = BTRFS_STRIPE_LEN;
490489
map->type = test->raid_type;
491490

492491
for (i = 0; i < map->num_stripes; i++) {

0 commit comments

Comments
 (0)