btrfs: more efficient chunk map iteration when device replace finishes
authorFilipe Manana <fdmanana@suse.com>
Thu, 25 Jul 2024 10:48:10 +0000 (11:48 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 10 Sep 2024 14:51:17 +0000 (16:51 +0200)
commit68a505bb87f948f72e5d230dfd7b40debdb195ed
tree3c0188876c33af78da02b392e1fab9a1eec91b44
parentb79f1c2caadc5c6251241977c7987fefdeadc2d9
btrfs: more efficient chunk map iteration when device replace finishes

When iterating the chunk maps when a device replace finishes we are doing
a full rbtree search for each chunk map, which is not the most efficient
thing to do, wasting CPU time. As we are holding a write lock on the tree
during the whole iteration, we can simply start from the first node in the
tree and then move to the next chunk map by doing a rb_next() call - the
only exception is when we need to reschedule, in which case we have to do
a full rbtree search since we dropped the write lock and the tree may have
changed (chunk maps may have been removed and the tree got rebalanced).
So just do that.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dev-replace.c