]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
Btrfs: avoid unnecessarily locking inode when clearing a range
authorFilipe Manana <fdmanana@suse.com>
Thu, 27 Jul 2017 18:52:55 +0000 (19:52 +0100)
committerDavid Sterba <dsterba@suse.com>
Fri, 18 Aug 2017 14:36:29 +0000 (16:36 +0200)
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 <fdmanana@suse.com>
Reviewed-by: Chris Mason <clm@fb.com>
Reviewed-by: Wang Shilong <wangshilong1991@gmail.com>
Signed-off-by: Chris Mason <clm@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c

index fa4b2563dfd7103127ffc7019b0993f5abf56b5f..6747292d437e50eb4c8919bda9151f62be1f6893 100644 (file)
@@ -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