aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fb.com>2015-10-02 16:12:23 -0400
committerChris Mason <clm@fb.com>2015-10-21 21:55:41 -0400
commit0584f718ed1f351fca5047a4b1ebba9b5ea41215 (patch)
tree201ced5ececf47ac59e358973b73fd376388e8a1
parentcef404837002103584c7c82f1e3fc3ec5961f47b (diff)
Btrfs: don't do extra bitmap search in one bit case
When we make ctl->unit allocations from a bitmap there is no point in searching for the next 0 in the bitmap. If we've found a bit we're done and can just exit the loop. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r--fs/btrfs/free-space-cache.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index e10c9668e4fd..0948d34cb84a 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1730,7 +1730,7 @@ static void bitmap_set_bits(struct btrfs_free_space_ctl *ctl,
1730 */ 1730 */
1731static int search_bitmap(struct btrfs_free_space_ctl *ctl, 1731static int search_bitmap(struct btrfs_free_space_ctl *ctl,
1732 struct btrfs_free_space *bitmap_info, u64 *offset, 1732 struct btrfs_free_space *bitmap_info, u64 *offset,
1733 u64 *bytes) 1733 u64 *bytes, bool for_alloc)
1734{ 1734{
1735 unsigned long found_bits = 0; 1735 unsigned long found_bits = 0;
1736 unsigned long max_bits = 0; 1736 unsigned long max_bits = 0;
@@ -1742,7 +1742,8 @@ static int search_bitmap(struct btrfs_free_space_ctl *ctl,
1742 * Skip searching the bitmap if we don't have a contiguous section that 1742 * Skip searching the bitmap if we don't have a contiguous section that
1743 * is large enough for this allocation. 1743 * is large enough for this allocation.
1744 */ 1744 */
1745 if (bitmap_info->max_extent_size && 1745 if (for_alloc &&
1746 bitmap_info->max_extent_size &&
1746 bitmap_info->max_extent_size < *bytes) { 1747 bitmap_info->max_extent_size < *bytes) {
1747 *bytes = bitmap_info->max_extent_size; 1748 *bytes = bitmap_info->max_extent_size;
1748 return -1; 1749 return -1;
@@ -1753,6 +1754,10 @@ static int search_bitmap(struct btrfs_free_space_ctl *ctl,
1753 bits = bytes_to_bits(*bytes, ctl->unit); 1754 bits = bytes_to_bits(*bytes, ctl->unit);
1754 1755
1755 for_each_set_bit_from(i, bitmap_info->bitmap, BITS_PER_BITMAP) { 1756 for_each_set_bit_from(i, bitmap_info->bitmap, BITS_PER_BITMAP) {
1757 if (for_alloc && bits == 1) {
1758 found_bits = 1;
1759 break;
1760 }
1756 next_zero = find_next_zero_bit(bitmap_info->bitmap, 1761 next_zero = find_next_zero_bit(bitmap_info->bitmap,
1757 BITS_PER_BITMAP, i); 1762 BITS_PER_BITMAP, i);
1758 extent_bits = next_zero - i; 1763 extent_bits = next_zero - i;
@@ -1824,7 +1829,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,
1824 if (entry->bitmap) { 1829 if (entry->bitmap) {
1825 u64 size = *bytes; 1830 u64 size = *bytes;
1826 1831
1827 ret = search_bitmap(ctl, entry, &tmp, &size); 1832 ret = search_bitmap(ctl, entry, &tmp, &size, true);
1828 if (!ret) { 1833 if (!ret) {
1829 *offset = tmp; 1834 *offset = tmp;
1830 *bytes = size; 1835 *bytes = size;
@@ -1885,7 +1890,8 @@ again:
1885 search_start = *offset; 1890 search_start = *offset;
1886 search_bytes = ctl->unit; 1891 search_bytes = ctl->unit;
1887 search_bytes = min(search_bytes, end - search_start + 1); 1892 search_bytes = min(search_bytes, end - search_start + 1);
1888 ret = search_bitmap(ctl, bitmap_info, &search_start, &search_bytes); 1893 ret = search_bitmap(ctl, bitmap_info, &search_start, &search_bytes,
1894 false);
1889 if (ret < 0 || search_start != *offset) 1895 if (ret < 0 || search_start != *offset)
1890 return -EINVAL; 1896 return -EINVAL;
1891 1897
@@ -1930,7 +1936,7 @@ again:
1930 search_start = *offset; 1936 search_start = *offset;
1931 search_bytes = ctl->unit; 1937 search_bytes = ctl->unit;
1932 ret = search_bitmap(ctl, bitmap_info, &search_start, 1938 ret = search_bitmap(ctl, bitmap_info, &search_start,
1933 &search_bytes); 1939 &search_bytes, false);
1934 if (ret < 0 || search_start != *offset) 1940 if (ret < 0 || search_start != *offset)
1935 return -EAGAIN; 1941 return -EAGAIN;
1936 1942
@@ -2685,7 +2691,7 @@ static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group_cache *block_group,
2685 search_start = min_start; 2691 search_start = min_start;
2686 search_bytes = bytes; 2692 search_bytes = bytes;
2687 2693
2688 err = search_bitmap(ctl, entry, &search_start, &search_bytes); 2694 err = search_bitmap(ctl, entry, &search_start, &search_bytes, true);
2689 if (err) { 2695 if (err) {
2690 if (search_bytes > *max_extent_size) 2696 if (search_bytes > *max_extent_size)
2691 *max_extent_size = search_bytes; 2697 *max_extent_size = search_bytes;
@@ -3262,7 +3268,7 @@ static int trim_bitmaps(struct btrfs_block_group_cache *block_group,
3262 } 3268 }
3263 3269
3264 bytes = minlen; 3270 bytes = minlen;
3265 ret2 = search_bitmap(ctl, entry, &start, &bytes); 3271 ret2 = search_bitmap(ctl, entry, &start, &bytes, false);
3266 if (ret2 || start >= end) { 3272 if (ret2 || start >= end) {
3267 spin_unlock(&ctl->tree_lock); 3273 spin_unlock(&ctl->tree_lock);
3268 mutex_unlock(&ctl->cache_writeout_mutex); 3274 mutex_unlock(&ctl->cache_writeout_mutex);
@@ -3415,7 +3421,7 @@ u64 btrfs_find_ino_for_alloc(struct btrfs_root *fs_root)
3415 u64 count = 1; 3421 u64 count = 1;
3416 int ret; 3422 int ret;
3417 3423
3418 ret = search_bitmap(ctl, entry, &offset, &count); 3424 ret = search_bitmap(ctl, entry, &offset, &count, true);
3419 /* Logic error; Should be empty if it can't find anything */ 3425 /* Logic error; Should be empty if it can't find anything */
3420 ASSERT(!ret); 3426 ASSERT(!ret);
3421 3427
@@ -3600,10 +3606,6 @@ again:
3600 3606
3601 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes); 3607 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes);
3602 3608
3603 /* We used the newly allocated info, set the max_extent_size to bytes */
3604 if (!info)
3605 bitmap_info->max_extent_size = bytes_added;
3606
3607 bytes -= bytes_added; 3609 bytes -= bytes_added;
3608 offset += bytes_added; 3610 offset += bytes_added;
3609 spin_unlock(&ctl->tree_lock); 3611 spin_unlock(&ctl->tree_lock);
@@ -3647,7 +3649,7 @@ have_info:
3647 3649
3648 bit_off = offset; 3650 bit_off = offset;
3649 bit_bytes = ctl->unit; 3651 bit_bytes = ctl->unit;
3650 ret = search_bitmap(ctl, info, &bit_off, &bit_bytes); 3652 ret = search_bitmap(ctl, info, &bit_off, &bit_bytes, false);
3651 if (!ret) { 3653 if (!ret) {
3652 if (bit_off == offset) { 3654 if (bit_off == offset) {
3653 ret = 1; 3655 ret = 1;