]> www.infradead.org Git - users/jedix/linux-maple.git/commit
btrfs: avoid extra tree search at btrfs_clear_extent_bit_changeset()
authorFilipe Manana <fdmanana@suse.com>
Wed, 9 Apr 2025 16:15:35 +0000 (17:15 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:51 +0000 (14:30 +0200)
commit6c28102f9ac4eea321e5421c248ca17983a9760d
tree6169abb0139d47e388a6ec9390454b55cf2b444e
parentc832378622d53e0516d7688cbb2e76786e854d1e
btrfs: avoid extra tree search at btrfs_clear_extent_bit_changeset()

When we find an extent state that starts before our range's start we
split it and jump into the 'search_again' label with our start offset
remaining the same, making us then go to the 'again' label and search
again for an extent state that contains the 'start' offset, and this
time it finds the same extent state but with its start offset set to
our range's start offset (due to the split). This is because we have
consumed the preallocated extent state record and we may need to split
again, and by jumping to 'again' we release the spinlock, allocate a new
prealloc state and restart the search.

However we may not need to restart and allocate a new extent state in
case we don't find extent states that cross our end offset, therefore
no need for further extent state splits, or we may be able to do an
atomic allocation (which is quick even if it fails). In these cases
it's a waste to restart the search.

So change the behaviour to do the restart only if we need to reschedule,
otherwise fall through - if we need to allocate an extent state for split
operations, we will try an atomic allocation and if that fails we will do
the restart as before.

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-io-tree.c