Btrfs: track dirty block groups on their own list
PATCH 1/1 Btrfs: track dirty block groups on their own list
Currently any time we try to update the block groups on disk we will walk _all_ block groups and check for the ->dirty flag to see if it is set. This function can get called several times during a commit. So if you have several terabytes of data you will be a very sad panda as we will loop through _all_ of the block groups several times, which makes the commit take a while which slows down the rest of the file system operations.
This patch introduces a dirty list for the block groups that we get added to when we dirty the block group for the first time. Then we simply update any block groups that have been dirtied since the last time we called btrfs_write_dirty_block_groups. This allows us to clean up how we write the free space cache out so it is much cleaner. Thanks,
--- fs/btrfs/ctree.h | 5 +- fs/btrfs/extent-tree.c | 167 ++++++++++++++------------------------------ fs/btrfs/free-space-cache.c | 8 ++- fs/btrfs/transaction.c | 13 ++-- fs/btrfs/transaction.h | 2 + 5 files changed, 71 insertions(+), 124 deletions(-)
fs/btrfs/ctree.h +3 -2
@@ -1237,7 +1237,6 @@ enum btrfs_disk_cache_state {BTRFS_DC_ERROR =1 ,BTRFS_DC_CLEAR =2 , BTRFS_DC_SETUP = 3, - BTRFS_DC_NEED_WRITE = 4, }; struct btrfs_caching_control {
@@ -1275,7 +1274,6 @@ struct btrfs_block_group_cache {unsigned long full_stripe_len; unsigned int ro:1; - unsigned int dirty:1; unsigned int iref:1;int disk_cache_state;
@@ -1309,6 +1307,9 @@ struct btrfs_block_group_cache {/* For read-only block groups */ struct list_head ro_list; + +/* For dirty block groups */ +struct list_head dirty_list; };/* delayed seq elem */
fs/btrfs/extent-tree.c +53 -114
244 lines not on this page · raw message
fs/btrfs/free-space-cache.c +5 -3
@@ -1210,6 +1210,7 @@ int btrfs_write_out_cache(struct btrfs_root *root,struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;struct inode *inode;int ret =0 ; +enum btrfs_disk_cache_state dcs =BTRFS_DC_WRITTEN ; root = root->fs_info->tree_root;
@@ -1233,9 +1234,7 @@ int btrfs_write_out_cache(struct btrfs_root *root, ret =__btrfs_write_out_cache (root, inode, ctl, block_group, trans, path, block_group->key.objectid);if (ret) { -spin_lock (&block_group->lock); - block_group->disk_cache_state =BTRFS_DC_ERROR ; -spin_unlock (&block_group->lock); + dcs =BTRFS_DC_ERROR ; ret =0 ;#ifdef DEBUG btrfs_err(root->fs_info,
@@ -1244,6 +1243,9 @@ int btrfs_write_out_cache(struct btrfs_root *root,#endif } +spin_lock (&block_group->lock); + block_group->disk_cache_state = dcs; +spin_unlock (&block_group->lock);iput (inode);return ret; }
fs/btrfs/transaction.c +8 -5
@@ -220,6 +220,8 @@ loop:INIT_LIST_HEAD (&cur_trans->pending_snapshots);INIT_LIST_HEAD (&cur_trans->pending_chunks);INIT_LIST_HEAD (&cur_trans->switch_commits); +INIT_LIST_HEAD (&cur_trans->dirty_bgs); +spin_lock_init (&cur_trans->dirty_bgs_lock);list_add_tail (&cur_trans->list, &fs_info->trans_list);extent_io_tree_init (&cur_trans->dirty_pages, fs_info->btree_inode->i_mapping);
@@ -955,7 +957,8 @@ static int update_extent_root(struct btrfs_trans_handle *trans,while (1 ) { old_root_bytenr =btrfs_root_bytenr (&root->root_item);if (old_root_bytenr == root->node->start && - old_root_used ==btrfs_root_used (&root->root_item)) + old_root_used ==btrfs_root_used (&root->root_item) && +list_empty (&trans->transaction->dirty_bgs))break ;btrfs_set_root_node (&root->root_item, root->node);
@@ -969,6 +972,9 @@ static int update_extent_root(struct btrfs_trans_handle *trans, ret =btrfs_write_dirty_block_groups (trans, root);if (ret)return ret; + ret =btrfs_run_delayed_refs (trans, root, (unsigned long )-1 ); +if (ret) +return ret; }return 0 ;
@@ -990,10 +996,6 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans,struct extent_buffer *eb;int ret; - ret =btrfs_run_delayed_refs (trans, root, (unsigned long )-1 ); -if (ret) -return ret; - eb =btrfs_lock_root_node (fs_info->tree_root); ret =btrfs_cow_block (trans, fs_info->tree_root, eb,NULL ,0 , &eb);
@@ -1894,6 +1896,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,switch_commit_roots (cur_trans, root->fs_info);assert_qgroups_uptodate (trans); +ASSERT (list_empty (&cur_trans->dirty_bgs));update_super_roots (root);btrfs_set_super_log_root (root->fs_info->super_copy,0 );
fs/btrfs/transaction.h +2 -0
@@ -57,6 +57,8 @@ struct btrfs_transaction {struct list_head pending_snapshots;struct list_head pending_chunks;struct list_head switch_commits; +struct list_head dirty_bgs; +spinlock_t dirty_bgs_lock;struct btrfs_delayed_ref_root delayed_refs;int aborted; };
Signature · 1 line
1.8.3.1