f2fs: speed up shrinking extent tree entries
authorJaegeuk Kim <jaegeuk@kernel.org>
Tue, 22 Dec 2015 03:25:50 +0000 (19:25 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 30 Dec 2015 18:13:00 +0000 (10:13 -0800)
If there is no candidates for shrinking slab entries, we don't need to traverse
any trees at all.

Reviewed-by: Chao Yu <chao2.yu@samsung.com>
[Jaegeuk Kim: fix missing initialization reported by Yunlei He]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/extent_cache.c
fs/f2fs/f2fs.h
fs/f2fs/shrinker.c

index 0e97d6af9885843a4a98039f12bd0682c34f950f..5305a29f91a33514ca20ec2b9f00917087b21016 100644 (file)
@@ -71,6 +71,8 @@ static struct extent_tree *__grab_extent_tree(struct inode *inode)
                atomic_set(&et->refcount, 0);
                et->count = 0;
                atomic_inc(&sbi->total_ext_tree);
+       } else {
+               atomic_dec(&sbi->total_zombie_tree);
        }
        atomic_inc(&et->refcount);
        up_write(&sbi->extent_tree_lock);
@@ -547,10 +549,14 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
        unsigned int found;
        unsigned int node_cnt = 0, tree_cnt = 0;
        int remained;
+       bool do_free = false;
 
        if (!test_opt(sbi, EXTENT_CACHE))
                return 0;
 
+       if (!atomic_read(&sbi->total_zombie_tree))
+               goto free_node;
+
        if (!down_write_trylock(&sbi->extent_tree_lock))
                goto out;
 
@@ -571,6 +577,7 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
                                radix_tree_delete(root, et->ino);
                                kmem_cache_free(extent_tree_slab, et);
                                atomic_dec(&sbi->total_ext_tree);
+                               atomic_dec(&sbi->total_zombie_tree);
                                tree_cnt++;
 
                                if (node_cnt + tree_cnt >= nr_shrink)
@@ -580,6 +587,7 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
        }
        up_write(&sbi->extent_tree_lock);
 
+free_node:
        /* 2. remove LRU extent entries */
        if (!down_write_trylock(&sbi->extent_tree_lock))
                goto out;
@@ -591,9 +599,13 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
                if (!remained--)
                        break;
                list_del_init(&en->list);
+               do_free = true;
        }
        spin_unlock(&sbi->extent_lock);
 
+       if (do_free == false)
+               goto unlock_out;
+
        /*
         * reset ino for searching victims from beginning of global extent tree.
         */
@@ -651,6 +663,7 @@ void f2fs_destroy_extent_tree(struct inode *inode)
 
        if (inode->i_nlink && !is_bad_inode(inode) && et->count) {
                atomic_dec(&et->refcount);
+               atomic_inc(&sbi->total_zombie_tree);
                return;
        }
 
@@ -716,6 +729,7 @@ void init_extent_cache_info(struct f2fs_sb_info *sbi)
        INIT_LIST_HEAD(&sbi->extent_list);
        spin_lock_init(&sbi->extent_lock);
        atomic_set(&sbi->total_ext_tree, 0);
+       atomic_set(&sbi->total_zombie_tree, 0);
        atomic_set(&sbi->total_ext_node, 0);
 }
 
index a7f619182cece3d840a6e95a8da0c41bf522ffcd..90fb970e2b98da615168ec62414d7cd9193e2422 100644 (file)
@@ -763,6 +763,7 @@ struct f2fs_sb_info {
        struct list_head extent_list;           /* lru list for shrinker */
        spinlock_t extent_lock;                 /* locking extent lru list */
        atomic_t total_ext_tree;                /* extent tree count */
+       atomic_t total_zombie_tree;             /* extent zombie tree count */
        atomic_t total_ext_node;                /* extent info count */
 
        /* basic filesystem units */
index a11e099cbddc6316a75e84208a96c0e426037393..93606f281bf9c50f21b4206ea553561463f71a04 100644 (file)
@@ -32,7 +32,7 @@ static unsigned long __count_free_nids(struct f2fs_sb_info *sbi)
 
 static unsigned long __count_extent_cache(struct f2fs_sb_info *sbi)
 {
-       return atomic_read(&sbi->total_ext_tree) +
+       return atomic_read(&sbi->total_zombie_tree) +
                                atomic_read(&sbi->total_ext_node);
 }