btrfs: async block group caching
PATCH 1/1 btrfs: async block group caching
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 16 seconds on my box, with these changes it now takes 6 seconds. Still not great, but we're getting closer.
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.
--- fs/btrfs/ctree.h | 15 +++- fs/btrfs/disk-io.c | 1 + fs/btrfs/extent-tree.c | 226 +++++++++++++++++++++++++++++------------- fs/btrfs/free-space-cache.c | 3 + 4 files changed, 173 insertions(+), 72 deletions(-)
fs/btrfs/ctree.h +13 -2
@@ -658,24 +658,34 @@ 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; -int cached;int ro;int dirty; +/* caching crap */ +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_bytes;struct rb_root free_space_offset; +u64 free_space;/* block group cache stuff */ struct rb_node cache_node;
@@ -1883,6 +1893,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_previous_item(struct btrfs_root *root, struct btrfs_path *path, u64 min_objectid,
fs/btrfs/disk-io.c +1 -0
@@ -2316,6 +2316,7 @@ int close_ctree(struct btrfs_root *root)free_extent_buffer (root->fs_info->csum_root->node);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 +156 -70
387 lines not on this page · raw message
fs/btrfs/free-space-cache.c +3 -0
@@ -180,6 +180,7 @@ static struct btrfs_free_space *tree_search_bytes(struct rb_root *root,static void unlink_free_space (struct btrfs_block_group_cache *block_group,struct btrfs_free_space *info) { + block_group->free_space -= info->bytes;rb_erase (&info->offset_index, &block_group->free_space_offset);rb_erase (&info->bytes_index, &block_group->free_space_bytes); }
@@ -201,6 +202,8 @@ static int link_free_space(struct btrfs_block_group_cache *block_group,if (ret)return ret; + block_group->free_space += info->bytes; +return ret; }
Signature · 1 line
1.5.4.3