Skip to content

Commit 52621cb

Browse files
Li Zefanchrismason-xx
authored andcommitted
Btrfs: avoid unnecessary bitmap search for cluster setup
setup_cluster_no_bitmap() searches all the extents and bitmaps starting from offset. Therefore if it returns -ENOSPC, all the bitmaps starting from offset are in the bitmaps list, so it's sufficient to search from this list in setup_cluser_bitmap(). Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 0f0fbf1 commit 52621cb

1 file changed

Lines changed: 4 additions & 38 deletions

File tree

‎fs/btrfs/free-space-cache.c‎

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,7 +2451,6 @@ setup_cluster_bitmap(struct btrfs_block_group_cache *block_group,
24512451
{
24522452
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
24532453
struct btrfs_free_space *entry;
2454-
struct rb_node *node;
24552454
int ret = -ENOSPC;
24562455
u64 bitmap_offset = offset_to_bitmap(ctl, offset);
24572456

@@ -2469,10 +2468,6 @@ setup_cluster_bitmap(struct btrfs_block_group_cache *block_group,
24692468
list_add(&entry->list, bitmaps);
24702469
}
24712470

2472-
/*
2473-
* First check our cached list of bitmaps and see if there is an entry
2474-
* here that will work.
2475-
*/
24762471
list_for_each_entry(entry, bitmaps, list) {
24772472
if (entry->bytes < min_bytes)
24782473
continue;
@@ -2483,38 +2478,10 @@ setup_cluster_bitmap(struct btrfs_block_group_cache *block_group,
24832478
}
24842479

24852480
/*
2486-
* If we do have entries on our list and we are here then we didn't find
2487-
* anything, so go ahead and get the next entry after the last entry in
2488-
* this list and start the search from there.
2481+
* The bitmaps list has all the bitmaps that record free space
2482+
* starting after offset, so no more search is required.
24892483
*/
2490-
if (!list_empty(bitmaps)) {
2491-
entry = list_entry(bitmaps->prev, struct btrfs_free_space,
2492-
list);
2493-
node = rb_next(&entry->offset_index);
2494-
if (!node)
2495-
return -ENOSPC;
2496-
entry = rb_entry(node, struct btrfs_free_space, offset_index);
2497-
goto search;
2498-
}
2499-
2500-
entry = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), 0, 1);
2501-
if (!entry)
2502-
return -ENOSPC;
2503-
2504-
search:
2505-
node = &entry->offset_index;
2506-
do {
2507-
entry = rb_entry(node, struct btrfs_free_space, offset_index);
2508-
node = rb_next(&entry->offset_index);
2509-
if (!entry->bitmap)
2510-
continue;
2511-
if (entry->bytes < min_bytes)
2512-
continue;
2513-
ret = btrfs_bitmap_cluster(block_group, entry, cluster, offset,
2514-
bytes, min_bytes);
2515-
} while (ret && node);
2516-
2517-
return ret;
2484+
return -ENOSPC;
25182485
}
25192486

25202487
/*
@@ -2532,8 +2499,8 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
25322499
u64 offset, u64 bytes, u64 empty_size)
25332500
{
25342501
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
2535-
struct list_head bitmaps;
25362502
struct btrfs_free_space *entry, *tmp;
2503+
LIST_HEAD(bitmaps);
25372504
u64 min_bytes;
25382505
int ret;
25392506

@@ -2572,7 +2539,6 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
25722539
goto out;
25732540
}
25742541

2575-
INIT_LIST_HEAD(&bitmaps);
25762542
ret = setup_cluster_no_bitmap(block_group, cluster, &bitmaps, offset,
25772543
bytes, min_bytes);
25782544
if (ret)

0 commit comments

Comments
 (0)