mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-01-30 15:43:30 +00:00
f2fs: introduce zombie list for fast shrinking extent trees
This patch removes refcount, and instead, adds zombie_list to shrink directly without radix tree traverse. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
c00ba55485
commit
137d09f002
@ -68,13 +68,13 @@ static struct extent_tree *__grab_extent_tree(struct inode *inode)
|
|||||||
et->root = RB_ROOT;
|
et->root = RB_ROOT;
|
||||||
et->cached_en = NULL;
|
et->cached_en = NULL;
|
||||||
rwlock_init(&et->lock);
|
rwlock_init(&et->lock);
|
||||||
atomic_set(&et->refcount, 0);
|
INIT_LIST_HEAD(&et->list);
|
||||||
et->count = 0;
|
et->count = 0;
|
||||||
atomic_inc(&sbi->total_ext_tree);
|
atomic_inc(&sbi->total_ext_tree);
|
||||||
} else {
|
} else {
|
||||||
atomic_dec(&sbi->total_zombie_tree);
|
atomic_dec(&sbi->total_zombie_tree);
|
||||||
|
list_del_init(&et->list);
|
||||||
}
|
}
|
||||||
atomic_inc(&et->refcount);
|
|
||||||
up_write(&sbi->extent_tree_lock);
|
up_write(&sbi->extent_tree_lock);
|
||||||
|
|
||||||
/* never died until evict_inode */
|
/* never died until evict_inode */
|
||||||
@ -551,9 +551,9 @@ static unsigned int f2fs_update_extent_tree_range(struct inode *inode,
|
|||||||
unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
|
unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
|
||||||
{
|
{
|
||||||
struct extent_tree *treevec[EXT_TREE_VEC_SIZE];
|
struct extent_tree *treevec[EXT_TREE_VEC_SIZE];
|
||||||
|
struct extent_tree *et, *next;
|
||||||
struct extent_node *en, *tmp;
|
struct extent_node *en, *tmp;
|
||||||
unsigned long ino = F2FS_ROOT_INO(sbi);
|
unsigned long ino = F2FS_ROOT_INO(sbi);
|
||||||
struct radix_tree_root *root = &sbi->extent_tree_root;
|
|
||||||
unsigned int found;
|
unsigned int found;
|
||||||
unsigned int node_cnt = 0, tree_cnt = 0;
|
unsigned int node_cnt = 0, tree_cnt = 0;
|
||||||
int remained;
|
int remained;
|
||||||
@ -569,29 +569,20 @@ unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* 1. remove unreferenced extent tree */
|
/* 1. remove unreferenced extent tree */
|
||||||
while ((found = radix_tree_gang_lookup(root,
|
list_for_each_entry_safe(et, next, &sbi->zombie_list, list) {
|
||||||
(void **)treevec, ino, EXT_TREE_VEC_SIZE))) {
|
write_lock(&et->lock);
|
||||||
unsigned i;
|
node_cnt += __free_extent_tree(sbi, et, true);
|
||||||
|
write_unlock(&et->lock);
|
||||||
|
|
||||||
ino = treevec[found - 1]->ino + 1;
|
list_del_init(&et->list);
|
||||||
for (i = 0; i < found; i++) {
|
radix_tree_delete(&sbi->extent_tree_root, et->ino);
|
||||||
struct extent_tree *et = treevec[i];
|
kmem_cache_free(extent_tree_slab, et);
|
||||||
|
atomic_dec(&sbi->total_ext_tree);
|
||||||
|
atomic_dec(&sbi->total_zombie_tree);
|
||||||
|
tree_cnt++;
|
||||||
|
|
||||||
if (!atomic_read(&et->refcount)) {
|
if (node_cnt + tree_cnt >= nr_shrink)
|
||||||
write_lock(&et->lock);
|
goto unlock_out;
|
||||||
node_cnt += __free_extent_tree(sbi, et, true);
|
|
||||||
write_unlock(&et->lock);
|
|
||||||
|
|
||||||
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)
|
|
||||||
goto unlock_out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
up_write(&sbi->extent_tree_lock);
|
up_write(&sbi->extent_tree_lock);
|
||||||
|
|
||||||
@ -619,7 +610,7 @@ free_node:
|
|||||||
*/
|
*/
|
||||||
ino = F2FS_ROOT_INO(sbi);
|
ino = F2FS_ROOT_INO(sbi);
|
||||||
|
|
||||||
while ((found = radix_tree_gang_lookup(root,
|
while ((found = radix_tree_gang_lookup(&sbi->extent_tree_root,
|
||||||
(void **)treevec, ino, EXT_TREE_VEC_SIZE))) {
|
(void **)treevec, ino, EXT_TREE_VEC_SIZE))) {
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
@ -670,8 +661,10 @@ void f2fs_destroy_extent_tree(struct inode *inode)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (inode->i_nlink && !is_bad_inode(inode) && et->count) {
|
if (inode->i_nlink && !is_bad_inode(inode) && et->count) {
|
||||||
atomic_dec(&et->refcount);
|
down_write(&sbi->extent_tree_lock);
|
||||||
|
list_add_tail(&et->list, &sbi->zombie_list);
|
||||||
atomic_inc(&sbi->total_zombie_tree);
|
atomic_inc(&sbi->total_zombie_tree);
|
||||||
|
up_write(&sbi->extent_tree_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -680,8 +673,7 @@ void f2fs_destroy_extent_tree(struct inode *inode)
|
|||||||
|
|
||||||
/* delete extent tree entry in radix tree */
|
/* delete extent tree entry in radix tree */
|
||||||
down_write(&sbi->extent_tree_lock);
|
down_write(&sbi->extent_tree_lock);
|
||||||
atomic_dec(&et->refcount);
|
f2fs_bug_on(sbi, et->count);
|
||||||
f2fs_bug_on(sbi, atomic_read(&et->refcount) || et->count);
|
|
||||||
radix_tree_delete(&sbi->extent_tree_root, inode->i_ino);
|
radix_tree_delete(&sbi->extent_tree_root, inode->i_ino);
|
||||||
kmem_cache_free(extent_tree_slab, et);
|
kmem_cache_free(extent_tree_slab, et);
|
||||||
atomic_dec(&sbi->total_ext_tree);
|
atomic_dec(&sbi->total_ext_tree);
|
||||||
@ -737,6 +729,7 @@ void init_extent_cache_info(struct f2fs_sb_info *sbi)
|
|||||||
INIT_LIST_HEAD(&sbi->extent_list);
|
INIT_LIST_HEAD(&sbi->extent_list);
|
||||||
spin_lock_init(&sbi->extent_lock);
|
spin_lock_init(&sbi->extent_lock);
|
||||||
atomic_set(&sbi->total_ext_tree, 0);
|
atomic_set(&sbi->total_ext_tree, 0);
|
||||||
|
INIT_LIST_HEAD(&sbi->zombie_list);
|
||||||
atomic_set(&sbi->total_zombie_tree, 0);
|
atomic_set(&sbi->total_zombie_tree, 0);
|
||||||
atomic_set(&sbi->total_ext_node, 0);
|
atomic_set(&sbi->total_ext_node, 0);
|
||||||
}
|
}
|
||||||
|
@ -359,8 +359,8 @@ struct extent_tree {
|
|||||||
struct rb_root root; /* root of extent info rb-tree */
|
struct rb_root root; /* root of extent info rb-tree */
|
||||||
struct extent_node *cached_en; /* recently accessed extent node */
|
struct extent_node *cached_en; /* recently accessed extent node */
|
||||||
struct extent_info largest; /* largested extent info */
|
struct extent_info largest; /* largested extent info */
|
||||||
|
struct list_head list; /* to be used by sbi->zombie_list */
|
||||||
rwlock_t lock; /* protect extent info rb-tree */
|
rwlock_t lock; /* protect extent info rb-tree */
|
||||||
atomic_t refcount; /* reference count of rb-tree */
|
|
||||||
unsigned int count; /* # of extent node in rb-tree*/
|
unsigned int count; /* # of extent node in rb-tree*/
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -764,6 +764,7 @@ struct f2fs_sb_info {
|
|||||||
struct list_head extent_list; /* lru list for shrinker */
|
struct list_head extent_list; /* lru list for shrinker */
|
||||||
spinlock_t extent_lock; /* locking extent lru list */
|
spinlock_t extent_lock; /* locking extent lru list */
|
||||||
atomic_t total_ext_tree; /* extent tree count */
|
atomic_t total_ext_tree; /* extent tree count */
|
||||||
|
struct list_head zombie_list; /* extent zombie tree list */
|
||||||
atomic_t total_zombie_tree; /* extent zombie tree count */
|
atomic_t total_zombie_tree; /* extent zombie tree count */
|
||||||
atomic_t total_ext_node; /* extent info count */
|
atomic_t total_ext_node; /* extent info count */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user