Skip to contentSkip to conversation

Btrfs: group metadata allocations with the root

PATCH New Josef Bacik 1 participant 1 message Mar 4, 2009 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: group metadata allocations with the root

This patch lets each root keep track of a small area of contigous space from which to allocate from in order to keep blocks for different roots interleaving themselves on disk. This happens in two parts

1) If we have not already reserved some space for the root, we go into the normal allocator. Here we try and allocate a cluster of free space. If we are successfull we give the current allocation what it needs, and then set the offset and size to the cluster we have found, and remove the entire section from the free space cache. Of course if we can't find space this ends up being just a normal allocation.

2) If we have some reserved space in the root we just use that chunk for the allocation and return.

This also cleans up some of allocation code. There will be another patch coming later to clean it up some more. Testing the cold-cache read speed we aren't actually doing anything faster, but we are definitely seeking less, so there is a clear win there.

---
 fs/btrfs/ctree.h       |    4 +
 fs/btrfs/disk-io.c     |    3 +
 fs/btrfs/extent-tree.c |  167 ++++++++++++++++++++++++------------------------
 3 files changed, 91 insertions(+), 83 deletions(-)
fs/btrfs/ctree.h +4 -0
index 82491ba..bdf826c 100644
@@ -878,6 +878,10 @@ struct btrfs_root {
 	 * for stat.  It may be used for more later
 	 */
 	struct super_block anon_super;
+
+	spinlock_t alloc_lock;
+	u64 alloc_bytes;
+	u64 alloc_offset;
 };
 
 /*
fs/btrfs/disk-io.c +3 -0
index adda739..057fe07 100644
@@ -926,6 +926,9 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
 	INIT_LIST_HEAD(&root->anon_super.s_list);
 	INIT_LIST_HEAD(&root->anon_super.s_instances);
 	init_rwsem(&root->anon_super.s_umount);
+	spin_lock_init(&root->alloc_lock);
+	root->alloc_bytes = 0;
+	root->alloc_offset = 0;
 
 	return 0;
 }
fs/btrfs/extent-tree.c +84 -83

266 lines not on this page · raw message

Signature · 1 line
1.5.4.3