]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: skip clearing EXTENT_DEFRAG for NOCOW ordered extents
authorDave Chen <davechen@synology.com>
Mon, 30 Mar 2026 03:31:48 +0000 (11:31 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 17:43:22 +0000 (19:43 +0200)
commite0dfaebb8f4a1de59a8b805d600e3b662b235efc
tree66b667b91fc7fc904d40c4a79f6c205f7588cc76
parente70e3f858e084aee34a2206e5f4dd49a47673f6a
btrfs: skip clearing EXTENT_DEFRAG for NOCOW ordered extents

In btrfs_finish_one_ordered(), clear_bits is unconditionally initialized
with EXTENT_DEFRAG.  For NOCOW ordered extents this is always a no-op
because should_nocow() already forces the COW path when EXTENT_DEFRAG is
set, so a NOCOW ordered extent can never have EXTENT_DEFRAG on its range.

Although harmless, the unconditional btrfs_clear_extent_bit() call still
performs a cold rbtree lookup under the io tree spinlock on every NOCOW
write completion.  Avoid this by only adding EXTENT_DEFRAG to clear_bits
for non-NOCOW ordered extents, and skip the call entirely when there are
no bits to clear.

Signed-off-by: Dave Chen <davechen@synology.com>
Signed-off-by: Robbie Ko <robbieko@synology.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c