Skip to contentSkip to conversation

Btrfs: check free space in block group before searching for a cluster

PATCH In review Josef Bacik 2 participants 2 messages Mar 18, 2011 – Mar 21, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: check free space in block group before searching for a cluster

The free space cluster stuff is heavy duty, so there is no sense in going through the entire song and dance if there isn't enough space in the block group to begin with. Thanks,

---
 fs/btrfs/free-space-cache.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
fs/btrfs/free-space-cache.c +10 -0
index 0282033..f631df8 100644
@@ -1999,6 +1999,16 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
 		min_bytes = max(bytes, (bytes + empty_size) >> 2);
 
 	spin_lock(&block_group->tree_lock);
+
+	/*
+	 * If we know we don't have enough space to make a cluster don't even
+	 * bother doing all the work to try and find one.
+	 */
+	if (block_group->free_space < min_bytes) {
+		spin_unlock(&block_group->tree_lock);
+		return -ENOSPC;
+	}
+
 	spin_lock(&cluster->lock);
 
 	/* someone already found a cluster, hooray */
Signature · 1 line
1.7.2.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Josef Bacik

The free space cluster stuff is heavy duty, so there is no sense in going through the entire song and dance if there isn't enough space in the block group to begin with. Thanks,

Quoted 25 lines
---
 fs/btrfs/free-space-cache.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
fs/btrfs/free-space-cache.c +10 -0
index 0282033..f631df8 100644
@@ -1999,6 +1999,16 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
 		min_bytes = max(bytes, (bytes + empty_size) >> 2);
 
 	spin_lock(&block_group->tree_lock);
+
+	/*
+	 * If we know we don't have enough space to make a cluster don't even
+	 * bother doing all the work to try and find one.
+	 */
+	if (block_group->free_space < min_bytes) {
+		spin_unlock(&block_group->tree_lock);
+		return -ENOSPC;
+	}
+
 	spin_lock(&cluster->lock);
 
 	/* someone already found a cluster, hooray */