]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: optimize clearing all bits from the last extent record in an io tree
authorFilipe Manana <fdmanana@suse.com>
Tue, 10 Mar 2026 15:29:33 +0000 (15:29 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 16:56:02 +0000 (18:56 +0200)
commitaa40d5601e66d873d3095e07037fc070da16aab5
tree5de3e56d24bcc4c136ac22fd669f8ca60b558d9c
parent908ab5634751c4168e864d56a5270e251ce89ee3
btrfs: optimize clearing all bits from the last extent record in an io tree

When we are clearing all the bits from the last record that contains the
target range (i.e. the record starts before our target range and ends
beyond it), we are doing a lot of unnecessary work:

1) Allocating a prealloc state if we don't have one already;

2) Adjust that last record's start offset to the end of our range and
   make the prealloc state have a range going from the original start
   offset of that last record to the end offset of our target range and
   the same bits as the last record. Then we insert the prealloc extent
   in the rbtree - this is done in split_state();

3) Remove our prealloc state from the rbtree since all the bits were
   cleared - this is done in clear_state_bit().

This is only wasting time when we can simply trim the last record so
that it's start offset is adjust to the end of the target range. So
optimize for that case and avoid the prealloc state allocation, insertion
and deletion from 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-io-tree.c