]> git.ipfire.org Git - thirdparty/linux.git/commit
btrfs: avoid useless rbtree iterations when attempting to merge extent map
authorFilipe Manana <fdmanana@suse.com>
Mon, 4 Dec 2023 16:20:30 +0000 (16:20 +0000)
committerDavid Sterba <dsterba@suse.com>
Fri, 15 Dec 2023 21:59:01 +0000 (22:59 +0100)
commit1a9fb16c60526253ecf9913b6ea48cfcdcb4c023
treea84ecca810ca83c5254cf903c5074effcba8af1f
parent00deaf04df35536d192544ea57b6da9a88519422
btrfs: avoid useless rbtree iterations when attempting to merge extent map

When trying to merge an extent map that was just inserted or unpinned, we
will try to merge it with any adjacent extent map that is suitable.

However we will only check if our extent map is mergeable after searching
for the previous and next extent maps in the rbtree, meaning that we are
doing unnecessary calls to rb_prev() and rb_next() in case our extent map
is not mergeable (it's compressed, in the list of modifed extents, being
logged or pinned), wasting CPU time chasing rbtree pointers and pulling
in unnecessary cache lines.

So change the logic to check first if an extent map is mergeable before
searching for the next and previous extent maps in the rbtree.

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/extent_map.c