Commit 39efac41 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: use radix_tree for ino management

For better ino management, this patch replaces the data structure from list
to radix tree.
Reviewed-by: default avatarChao Yu <chao2.yu@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 6451e041
...@@ -284,24 +284,27 @@ const struct address_space_operations f2fs_meta_aops = { ...@@ -284,24 +284,27 @@ const struct address_space_operations f2fs_meta_aops = {
static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
{ {
struct ino_entry *new, *e; struct ino_entry *e;
retry:
new = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_ATOMIC);
new->ino = ino;
spin_lock(&sbi->ino_lock[type]); spin_lock(&sbi->ino_lock[type]);
list_for_each_entry(e, &sbi->ino_list[type], list) {
if (e->ino == ino) { e = radix_tree_lookup(&sbi->ino_root[type], ino);
if (!e) {
e = kmem_cache_alloc(ino_entry_slab, GFP_ATOMIC);
if (!e) {
spin_unlock(&sbi->ino_lock[type]); spin_unlock(&sbi->ino_lock[type]);
kmem_cache_free(ino_entry_slab, new); goto retry;
return;
} }
if (e->ino > ino) if (radix_tree_insert(&sbi->ino_root[type], ino, e)) {
break; spin_unlock(&sbi->ino_lock[type]);
} kmem_cache_free(ino_entry_slab, e);
goto retry;
}
memset(e, 0, sizeof(struct ino_entry));
e->ino = ino;
/* add new entry into list which is sorted by inode number */ list_add_tail(&e->list, &sbi->ino_list[type]);
list_add_tail(&new->list, &e->list); }
spin_unlock(&sbi->ino_lock[type]); spin_unlock(&sbi->ino_lock[type]);
} }
...@@ -310,14 +313,15 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) ...@@ -310,14 +313,15 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
struct ino_entry *e; struct ino_entry *e;
spin_lock(&sbi->ino_lock[type]); spin_lock(&sbi->ino_lock[type]);
list_for_each_entry(e, &sbi->ino_list[type], list) { e = radix_tree_lookup(&sbi->ino_root[type], ino);
if (e->ino == ino) { if (e) {
list_del(&e->list); list_del(&e->list);
radix_tree_delete(&sbi->ino_root[type], ino);
if (type == ORPHAN_INO)
sbi->n_orphans--; sbi->n_orphans--;
spin_unlock(&sbi->ino_lock[type]); spin_unlock(&sbi->ino_lock[type]);
kmem_cache_free(ino_entry_slab, e); kmem_cache_free(ino_entry_slab, e);
return; return;
}
} }
spin_unlock(&sbi->ino_lock[type]); spin_unlock(&sbi->ino_lock[type]);
} }
...@@ -346,7 +350,7 @@ void release_orphan_inode(struct f2fs_sb_info *sbi) ...@@ -346,7 +350,7 @@ void release_orphan_inode(struct f2fs_sb_info *sbi)
void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
{ {
/* add new orphan entry into list which is sorted by inode number */ /* add new orphan ino entry into list */
__add_ino_entry(sbi, ino, ORPHAN_INO); __add_ino_entry(sbi, ino, ORPHAN_INO);
} }
...@@ -943,6 +947,7 @@ void init_ino_entry_info(struct f2fs_sb_info *sbi) ...@@ -943,6 +947,7 @@ void init_ino_entry_info(struct f2fs_sb_info *sbi)
int i; int i;
for (i = 0; i < MAX_INO_ENTRY; i++) { for (i = 0; i < MAX_INO_ENTRY; i++) {
INIT_RADIX_TREE(&sbi->ino_root[i], GFP_ATOMIC);
spin_lock_init(&sbi->ino_lock[i]); spin_lock_init(&sbi->ino_lock[i]);
INIT_LIST_HEAD(&sbi->ino_list[i]); INIT_LIST_HEAD(&sbi->ino_list[i]);
} }
......
...@@ -456,6 +456,7 @@ struct f2fs_sb_info { ...@@ -456,6 +456,7 @@ struct f2fs_sb_info {
wait_queue_head_t cp_wait; wait_queue_head_t cp_wait;
/* for inode management */ /* for inode management */
struct radix_tree_root ino_root[MAX_INO_ENTRY]; /* ino entry array */
spinlock_t ino_lock[MAX_INO_ENTRY]; /* for ino entry lock */ spinlock_t ino_lock[MAX_INO_ENTRY]; /* for ino entry lock */
struct list_head ino_list[MAX_INO_ENTRY]; /* inode list head */ struct list_head ino_list[MAX_INO_ENTRY]; /* inode list head */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment