Btrfs: Avoid orphan inodes cleanup during replaying log
PATCH 5/12 Btrfs: Avoid orphan inodes cleanup during replaying log
We do log replay in a single transaction, so it's not good to do unbound operations during replaying log. This patch makes orphan inodes cleanup executed after replaying log. It also avoid doing other unbound operations such as truncating a file during replaying log. These unbound operations are postponed to the orphan inode cleanup stage.
Signed-off-by Yan Zheng <[email protected]>
--- fs/btrfs/ctree.h | 5 +++-- fs/btrfs/disk-io.c | 17 +++++++++++------ fs/btrfs/inode.c | 19 ++++++++++++++++--- fs/btrfs/relocation.c | 1 + fs/btrfs/tree-log.c | 49 ++++++++++++++++++++++++------------------------- 5 files changed, 55 insertions(+), 36 deletions(-)
fs/btrfs/ctree.h +3 -2
@@ -859,8 +859,9 @@ struct btrfs_fs_info {struct mutex ordered_operations_mutex;struct rw_semaphore extent_commit_sem; -struct rw_semaphore subvol_sem; +struct rw_semaphore cleanup_work_sem; +struct rw_semaphore subvol_sem;struct srcu_struct subvol_srcu;struct list_head trans_list;
@@ -1034,12 +1035,12 @@ struct btrfs_root {int ref_cows;int track_dirty;int in_radix; +int clean_orphans;u64 defrag_trans_start;struct btrfs_key defrag_progress;struct btrfs_key defrag_max;int defrag_running; -int defrag_level;char *name;int in_sysfs;
fs/btrfs/disk-io.c +11 -6
@@ -894,6 +894,8 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, root->stripesize = stripesize; root->ref_cows =0 ; root->track_dirty =0 ; + root->in_radix =0 ; + root->clean_orphans =0 ; root->fs_info = fs_info; root->objectid = objectid;
@@ -930,7 +932,6 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, root->defrag_trans_start = fs_info->generation;init_completion (&root->kobj_unregister); root->defrag_running =0 ; - root->defrag_level =0 ; root->root_key.objectid = objectid; root->anon_super.s_root =NULL ; root->anon_super.s_dev =0 ;
@@ -1212,8 +1213,10 @@ again: ret =radix_tree_insert (&fs_info->fs_roots_radix, (unsigned long )root->root_key.objectid, root); -if (ret ==0 ) +if (ret ==0 ) { root->in_radix =1 ; + root->clean_orphans =1 ; + }spin_unlock (&fs_info->fs_roots_radix_lock);radix_tree_preload_end ();if (ret) {
@@ -1227,10 +1230,6 @@ again: ret =btrfs_find_dead_roots (fs_info->tree_root, root->root_key.objectid);WARN_ON (ret); - -if (!(fs_info->sb->s_flags &MS_RDONLY )) -btrfs_orphan_cleanup (root); -return root; fail:free_fs_root (root);
@@ -1689,6 +1688,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,mutex_init (&fs_info->cleaner_mutex);mutex_init (&fs_info->volume_mutex);init_rwsem (&fs_info->extent_commit_sem); +init_rwsem (&fs_info->cleanup_work_sem);init_rwsem (&fs_info->subvol_sem);btrfs_init_free_cluster (&fs_info->meta_alloc_cluster);
@@ -2388,6 +2388,11 @@ int btrfs_commit_super(struct btrfs_root *root)mutex_lock (&root->fs_info->cleaner_mutex);btrfs_clean_old_snapshots (root);mutex_unlock (&root->fs_info->cleaner_mutex); + +/* wait until ongoing cleanup work done */ +down_write (&root->fs_info->cleanup_work_sem); +up_write (&root->fs_info->cleanup_work_sem); + trans =btrfs_start_transaction (root,1 ); ret =btrfs_commit_transaction (trans, root);BUG_ON (ret);
fs/btrfs/inode.c +16 -3
@@ -2088,16 +2088,17 @@ void btrfs_orphan_cleanup(struct btrfs_root *root)struct inode *inode;int ret =0 , nr_unlink =0 , nr_truncate =0 ; - path =btrfs_alloc_path (); -if (!path) +if (!xchg (&root->clean_orphans,0 ))return ; + + path =btrfs_alloc_path (); +BUG_ON (!path); path->reada =-1 ; key.objectid =BTRFS_ORPHAN_OBJECTID ;btrfs_set_key_type (&key,BTRFS_ORPHAN_ITEM_KEY ); key.offset = (u64)-1 ; -while (1 ) { ret =btrfs_search_slot (NULL , root, &key, path,0 ,0 );if (ret <0 ) {
@@ -3293,6 +3294,11 @@ void btrfs_delete_inode(struct inode *inode) }btrfs_wait_ordered_range (inode,0 , (u64)-1 ); +if (root->fs_info->log_root_recovering) { +BUG_ON (!list_empty (&BTRFS_I (inode)->i_orphan)); + goto no_delete; + } +if (inode->i_nlink >0 ) {BUG_ON (btrfs_root_refs (&root->root_item) !=0 ); goto no_delete;
@@ -3700,6 +3706,13 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) }srcu_read_unlock (&root->fs_info->subvol_srcu, index); +if (root != sub_root) { +down_read (&root->fs_info->cleanup_work_sem); +if (!(inode->i_sb->s_flags &MS_RDONLY )) +btrfs_orphan_cleanup (sub_root); +up_read (&root->fs_info->cleanup_work_sem); + } +return inode; }
fs/btrfs/relocation.c +1 -0
@@ -3755,6 +3755,7 @@ out: BTRFS_DATA_RELOC_TREE_OBJECTID);if (IS_ERR (fs_root)) err =PTR_ERR (fs_root); +btrfs_orphan_cleanup (fs_root); }return err; }
fs/btrfs/tree-log.c +24 -25
77 lines not on this page · raw message
Signature · 1 line
1.6.2.5