Commit d0a365e8 authored by Josef Bacik's avatar Josef Bacik

Btrfs: deal with min_bytes appropriately when looking for a cluster

We do all this fun stuff with min_bytes, but either don't use it in the case of
just normal extents, or use it completely wrong in the case of bitmaps.  So fix
this for both cases

1) In the extent case, stop looking for space with window_free >= min_bytes
instead of bytes + empty_size.

2) In the bitmap case, we were looking for streches of free space that was at
least min_bytes in size, which was not right at all.  So instead search for
stretches of free space that are at least bytes in size (this will make a
difference when we have > page size blocks) and then only search for min_bytes
amount of free space.

Thanks,
Reviewed-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
parent 7d0d2e8e
...@@ -1910,8 +1910,8 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group, ...@@ -1910,8 +1910,8 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group,
i = offset_to_bit(entry->offset, block_group->sectorsize, i = offset_to_bit(entry->offset, block_group->sectorsize,
max_t(u64, offset, entry->offset)); max_t(u64, offset, entry->offset));
search_bits = bytes_to_bits(min_bytes, block_group->sectorsize); search_bits = bytes_to_bits(bytes, block_group->sectorsize);
total_bits = bytes_to_bits(bytes, block_group->sectorsize); total_bits = bytes_to_bits(min_bytes, block_group->sectorsize);
again: again:
found_bits = 0; found_bits = 0;
...@@ -2034,8 +2034,7 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans, ...@@ -2034,8 +2034,7 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
if (entry->bitmap && entry->bytes > bytes + empty_size) { if (entry->bitmap && entry->bytes > bytes + empty_size) {
ret = btrfs_bitmap_cluster(block_group, entry, cluster, ret = btrfs_bitmap_cluster(block_group, entry, cluster,
offset, bytes + empty_size, offset, bytes, min_bytes);
min_bytes);
if (!ret) if (!ret)
goto got_it; goto got_it;
} }
...@@ -2065,7 +2064,7 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans, ...@@ -2065,7 +2064,7 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
while (1) { while (1) {
/* out window is just right, lets fill it */ /* out window is just right, lets fill it */
if (window_free >= bytes + empty_size) if (window_free >= min_bytes)
break; break;
node = rb_next(&last->offset_index); node = rb_next(&last->offset_index);
......
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