From: Filipe Manana Date: Thu, 27 Jul 2017 18:52:55 +0000 (+0100) Subject: Btrfs: avoid unnecessarily locking inode when clearing a range X-Git-Tag: v6.6-pxa1908~15840^2~28 X-Git-Url: https://git.dujemihanovic.xyz/?a=commitdiff_plain;h=4a4b964f42fa5a70d0023d2f1d44a2764bd144f4;p=linux.git Btrfs: avoid unnecessarily locking inode when clearing a range If the range being cleared was not marked for defrag and we are not about to clear the range from the defrag status, we don't need to lock and unlock the inode. Signed-off-by: Filipe Manana Reviewed-by: Chris Mason Reviewed-by: Wang Shilong Signed-off-by: Chris Mason Signed-off-by: David Sterba --- diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index fa4b2563dfd7..6747292d437e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1801,10 +1801,11 @@ static void btrfs_clear_bit_hook(void *private_data, u64 len = state->end + 1 - state->start; u32 num_extents = count_max_extents(len); - spin_lock(&inode->lock); - if ((state->state & EXTENT_DEFRAG) && (*bits & EXTENT_DEFRAG)) + if ((state->state & EXTENT_DEFRAG) && (*bits & EXTENT_DEFRAG)) { + spin_lock(&inode->lock); inode->defrag_bytes -= len; - spin_unlock(&inode->lock); + spin_unlock(&inode->lock); + } /* * set_bit and clear bit hooks normally require _irqsave/restore