Commit 96009762 authored by Wang Sheng-Hui's avatar Wang Sheng-Hui Committed by Chris Mason

Btrfs: use ctl->unit for free space calculation instead of block_group->sectorsize

We should use ctl->unit for free space calculation instead of block_group->sectorsize
even though for free space use_bitmap or free space cluster we only have sectorsize assigned to ctl->unit currently. Also, we can keep it consisten in code style.
Signed-off-by: default avatarWang Sheng-Hui <shhuiw@gmail.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 43baa579
...@@ -1353,7 +1353,7 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) ...@@ -1353,7 +1353,7 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl)
u64 bitmap_bytes; u64 bitmap_bytes;
u64 extent_bytes; u64 extent_bytes;
u64 size = block_group->key.offset; u64 size = block_group->key.offset;
u64 bytes_per_bg = BITS_PER_BITMAP * block_group->sectorsize; u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit;
int max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg); int max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg);
BUG_ON(ctl->total_bitmaps > max_bitmaps); BUG_ON(ctl->total_bitmaps > max_bitmaps);
...@@ -1639,8 +1639,7 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl, ...@@ -1639,8 +1639,7 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl,
* some block groups are so tiny they can't be enveloped by a bitmap, so * some block groups are so tiny they can't be enveloped by a bitmap, so
* don't even bother to create a bitmap for this * don't even bother to create a bitmap for this
*/ */
if (BITS_PER_BITMAP * block_group->sectorsize > if (BITS_PER_BITMAP * ctl->unit > block_group->key.offset)
block_group->key.offset)
return false; return false;
return true; return true;
...@@ -2287,10 +2286,10 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group, ...@@ -2287,10 +2286,10 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group,
unsigned long total_found = 0; unsigned long total_found = 0;
int ret; int ret;
i = offset_to_bit(entry->offset, block_group->sectorsize, i = offset_to_bit(entry->offset, ctl->unit,
max_t(u64, offset, entry->offset)); max_t(u64, offset, entry->offset));
want_bits = bytes_to_bits(bytes, block_group->sectorsize); want_bits = bytes_to_bits(bytes, ctl->unit);
min_bits = bytes_to_bits(min_bytes, block_group->sectorsize); min_bits = bytes_to_bits(min_bytes, ctl->unit);
again: again:
found_bits = 0; found_bits = 0;
...@@ -2314,23 +2313,22 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group, ...@@ -2314,23 +2313,22 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group,
total_found += found_bits; total_found += found_bits;
if (cluster->max_size < found_bits * block_group->sectorsize) if (cluster->max_size < found_bits * ctl->unit)
cluster->max_size = found_bits * block_group->sectorsize; cluster->max_size = found_bits * ctl->unit;
if (total_found < want_bits || cluster->max_size < cont1_bytes) { if (total_found < want_bits || cluster->max_size < cont1_bytes) {
i = next_zero + 1; i = next_zero + 1;
goto again; goto again;
} }
cluster->window_start = start * block_group->sectorsize + cluster->window_start = start * ctl->unit + entry->offset;
entry->offset;
rb_erase(&entry->offset_index, &ctl->free_space_offset); rb_erase(&entry->offset_index, &ctl->free_space_offset);
ret = tree_insert_offset(&cluster->root, entry->offset, ret = tree_insert_offset(&cluster->root, entry->offset,
&entry->offset_index, 1); &entry->offset_index, 1);
BUG_ON(ret); /* -EEXIST; Logic error */ BUG_ON(ret); /* -EEXIST; Logic error */
trace_btrfs_setup_cluster(block_group, cluster, trace_btrfs_setup_cluster(block_group, cluster,
total_found * block_group->sectorsize, 1); total_found * ctl->unit, 1);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment