Btrfs: fix unnecessary while loop when search the free space, cache

When we find a bitmap free space entry, we may check the previous extent
entry covers the offset or not. But if we find this entry is also a bitmap
entry, we will continue to check the previous entry of the current one by
a while loop. It is unnecessary because it is impossible that the extent
entry which is in front of a bitmap entry can cover the offset of the entry
after that bitmap entry.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit is contained in:
Miao Xie 2012-10-18 08:18:01 +00:00 committed by Josef Bacik
parent de1ee92ac3
commit de6c4115a2

View File

@ -1250,18 +1250,13 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl,
* if previous extent entry covers the offset, * if previous extent entry covers the offset,
* we should return it instead of the bitmap entry * we should return it instead of the bitmap entry
*/ */
n = &entry->offset_index; n = rb_prev(&entry->offset_index);
while (1) { if (n) {
n = rb_prev(n);
if (!n)
break;
prev = rb_entry(n, struct btrfs_free_space, prev = rb_entry(n, struct btrfs_free_space,
offset_index); offset_index);
if (!prev->bitmap) { if (!prev->bitmap &&
if (prev->offset + prev->bytes > offset) prev->offset + prev->bytes > offset)
entry = prev; entry = prev;
break;
}
} }
} }
return entry; return entry;
@ -1287,18 +1282,13 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl,
} }
if (entry->bitmap) { if (entry->bitmap) {
n = &entry->offset_index; n = rb_prev(&entry->offset_index);
while (1) { if (n) {
n = rb_prev(n);
if (!n)
break;
prev = rb_entry(n, struct btrfs_free_space, prev = rb_entry(n, struct btrfs_free_space,
offset_index); offset_index);
if (!prev->bitmap) { if (!prev->bitmap &&
if (prev->offset + prev->bytes > offset) prev->offset + prev->bytes > offset)
return prev; return prev;
break;
}
} }
if (entry->offset + BITS_PER_BITMAP * ctl->unit > offset) if (entry->offset + BITS_PER_BITMAP * ctl->unit > offset)
return entry; return entry;