Skip to content

Commit e0dfaeb

Browse files
fcmaplekdave
authored andcommitted
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>
1 parent e70e3f8 commit e0dfaeb

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

fs/btrfs/inode.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,7 +3197,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
31973197
bool freespace_inode;
31983198
bool truncated = false;
31993199
bool clear_reserved_extent = true;
3200-
unsigned int clear_bits = EXTENT_DEFRAG;
3200+
unsigned int clear_bits = 0;
32013201

32023202
start = ordered_extent->file_offset;
32033203
end = start + ordered_extent->num_bytes - 1;
@@ -3208,6 +3208,9 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
32083208
!test_bit(BTRFS_ORDERED_ENCODED, &ordered_extent->flags))
32093209
clear_bits |= EXTENT_DELALLOC_NEW;
32103210

3211+
if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags))
3212+
clear_bits |= EXTENT_DEFRAG;
3213+
32113214
freespace_inode = btrfs_is_free_space_inode(inode);
32123215
if (!freespace_inode)
32133216
btrfs_lockdep_acquire(fs_info, btrfs_ordered_extent);
@@ -3339,8 +3342,9 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
33393342
goto out;
33403343
}
33413344
out:
3342-
btrfs_clear_extent_bit(&inode->io_tree, start, end, clear_bits,
3343-
&cached_state);
3345+
if (clear_bits)
3346+
btrfs_clear_extent_bit(&inode->io_tree, start, end, clear_bits,
3347+
&cached_state);
33443348

33453349
if (trans)
33463350
btrfs_end_transaction(trans);

0 commit comments

Comments
 (0)