The reason is:
- The per-cpu counter has its own lock to protect itself.
- Here we need get a exact value.

Signed-off-by: Miao Xie <[email protected]>
---
 fs/btrfs/extent-tree.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 45d98d0..12a5b6d 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4142,13 +4142,9 @@ static int may_commit_transaction(struct btrfs_root 
*root,
                goto commit;
 
        /* See if there is enough pinned space to make this reservation */
-       spin_lock(&space_info->lock);
        if (percpu_counter_compare(&space_info->total_bytes_pinned,
-                                  bytes) >= 0) {
-               spin_unlock(&space_info->lock);
+                                  bytes) >= 0)
                goto commit;
-       }
-       spin_unlock(&space_info->lock);
 
        /*
         * See if there is some space in the delayed insertion reservation for
@@ -4157,16 +4153,13 @@ static int may_commit_transaction(struct btrfs_root 
*root,
        if (space_info != delayed_rsv->space_info)
                return -ENOSPC;
 
-       spin_lock(&space_info->lock);
        spin_lock(&delayed_rsv->lock);
        if (percpu_counter_compare(&space_info->total_bytes_pinned,
                                   bytes - delayed_rsv->size) >= 0) {
                spin_unlock(&delayed_rsv->lock);
-               spin_unlock(&space_info->lock);
                return -ENOSPC;
        }
        spin_unlock(&delayed_rsv->lock);
-       spin_unlock(&space_info->lock);
 
 commit:
        trans = btrfs_join_transaction(root);
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to