Skip to contentSkip to conversation

btrfs: async block group caching v4.

PATCH New Josef Bacik 1 participant 1 message Jun 19, 2009 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: async block group caching v4.

This patch moves the caching of the block group off to a kthread in order to allow people to allocate sooner. Instead of blocking up behind the caching mutex, we instead kick of the caching kthread, and then attempt to make an allocation. If we cannot, we wait on the block groups caching waitqueue, which the caching kthread will wake the waiting threads up everytime it finds 2 meg worth of space, and then again when its finished caching. This is how I tested the speedup from this

mkfs the disk
mount the disk
fill the disk up with fs_mark
unmount the disk
mount the disk
time touch /mnt/foo

Without my changes this took 11 seconds on my box, with these changes it now takes 1 second.

Another change thats been put in place is we lock the super mirror's in the pinned extent map in order to keep us from adding that stuff as free space when caching the block group. This doesn't really change anything else as far as the pinned extent map is concerned, since for actual pinned extents we use EXTENT_DIRTY, but it does mean that when we unmount we have to go in and unlock those extents to keep from leaking memory.

I've also added a check where when we are reading block groups from disk, if the amount of space used == the size of the block group, we go ahead and mark the block group as cached. This drastically reduces the amount of time it takes to cache the block groups. Using the same test as above, except doing a dd to a file and then unmounting, it used to take 33 seconds to umount, now it takes 3 seconds.

There was a compile problem with the previous version, that has been fixed. Thanks,

---
 fs/btrfs/ctree.c            |   10 ++
 fs/btrfs/ctree.h            |   15 ++-
 fs/btrfs/disk-io.c          |    1 +
 fs/btrfs/extent-tree.c      |  300 ++++++++++++++++++++++++++++++++-----------
 fs/btrfs/free-space-cache.c |   41 +++---
 5 files changed, 269 insertions(+), 98 deletions(-)
fs/btrfs/ctree.c +10 -0
index 60a45f3..6b46d87 100644
@@ -1752,6 +1752,11 @@ again:
 			wret = btrfs_cow_block(trans, root, b,
 					       p->nodes[level + 1],
 					       p->slots[level + 1], &b);
+			if (wret == -EAGAIN) {
+				btrfs_release_path(root, p);
+				goto again;
+			}
+
 			if (wret) {
 				free_extent_buffer(b);
 				ret = wret;
@@ -1844,6 +1849,11 @@ cow_done:
 						      p, ins_len, ret == 0);
 				btrfs_clear_path_blocking(p, NULL);
 
+				if (sret == -EAGAIN) {
+					btrfs_release_path(root, p);
+					goto again;
+				}
+
 				BUG_ON(sret > 0);
 				if (sret) {
 					ret = sret;
fs/btrfs/ctree.h +13 -2
index eb6639c..14f8d88 100644
@@ -721,11 +721,17 @@ struct btrfs_free_cluster {
 	struct list_head block_group_list;
 };
 
+enum btrfs_caching_type {
+	BTRFS_CACHE_NO		= 0,
+	BTRFS_CACHE_STARTED	= 1,
+	BTRFS_CACHE_FINISHED	= 2,
+};
+
 struct btrfs_block_group_cache {
 	struct btrfs_key key;
 	struct btrfs_block_group_item item;
+	struct btrfs_fs_info *fs_info;
 	spinlock_t lock;
-	struct mutex cache_mutex;
 	u64 pinned;
 	u64 reserved;
 	u64 flags;
@@ -733,15 +739,19 @@ struct btrfs_block_group_cache {
 	int extents_thresh;
 	int free_extents;
 	int total_bitmaps;
-	int cached;
 	int ro;
 	int dirty;
 
+	/* cache tracking stuff */
+	wait_queue_head_t caching_q;
+	int cached;
+
 	struct btrfs_space_info *space_info;
 
 	/* free space cache stuff */
 	spinlock_t tree_lock;
 	struct rb_root free_space_offset;
+	u64 free_space;
 
 	/* block group cache stuff */
 	struct rb_node cache_node;
@@ -1996,6 +2006,7 @@ void btrfs_delalloc_reserve_space(struct btrfs_root *root, struct inode *inode,
 				 u64 bytes);
 void btrfs_delalloc_free_space(struct btrfs_root *root, struct inode *inode,
 			      u64 bytes);
+void btrfs_free_super_mirror_extents(struct btrfs_fs_info *info);
 /* ctree.c */
 int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key,
 		     int level, int *slot);
fs/btrfs/disk-io.c +1 -0
index 0d50d49..41f8bf3 100644
@@ -2327,6 +2327,7 @@ int close_ctree(struct btrfs_root *root)
 	free_extent_buffer(root->fs_info->csum_root->commit_root);
 
 	btrfs_free_block_groups(root->fs_info);
+	btrfs_free_super_mirror_extents(root->fs_info);
 
 	del_fs_roots(fs_info);
 
fs/btrfs/extent-tree.c +223 -77

513 lines not on this page · raw message

fs/btrfs/free-space-cache.c +22 -19

112 lines not on this page · raw message

Signature · 1 line
1.5.4.3