aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2014-07-24 21:15:17 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2014-07-29 10:46:11 -0400
commit39efac41fbe44343cac29472320a1d502fcff66b (patch)
treeeda670e78ffeda82faf2a26f423f84929e092804 /fs/f2fs
parent6451e041c8d39daf39c71eefe839641c2093713e (diff)
f2fs: use radix_tree for ino management
For better ino management, this patch replaces the data structure from list to radix tree. Reviewed-by: Chao Yu <chao2.yu@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r--fs/f2fs/checkpoint.c49
-rw-r--r--fs/f2fs/f2fs.h1
2 files changed, 28 insertions, 22 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index f93d154e2770..4bf203756cf8 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -284,24 +284,27 @@ const struct address_space_operations f2fs_meta_aops = {
284 284
285static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type) 285static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
286{ 286{
287 struct ino_entry *new, *e; 287 struct ino_entry *e;
288 288retry:
289 new = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_ATOMIC);
290 new->ino = ino;
291
292 spin_lock(&sbi->ino_lock[type]); 289 spin_lock(&sbi->ino_lock[type]);
293 list_for_each_entry(e, &sbi->ino_list[type], list) { 290
294 if (e->ino == ino) { 291 e = radix_tree_lookup(&sbi->ino_root[type], ino);
292 if (!e) {
293 e = kmem_cache_alloc(ino_entry_slab, GFP_ATOMIC);
294 if (!e) {
295 spin_unlock(&sbi->ino_lock[type]); 295 spin_unlock(&sbi->ino_lock[type]);
296 kmem_cache_free(ino_entry_slab, new); 296 goto retry;
297 return;
298 } 297 }
299 if (e->ino > ino) 298 if (radix_tree_insert(&sbi->ino_root[type], ino, e)) {
300 break; 299 spin_unlock(&sbi->ino_lock[type]);
301 } 300 kmem_cache_free(ino_entry_slab, e);
301 goto retry;
302 }
303 memset(e, 0, sizeof(struct ino_entry));
304 e->ino = ino;
302 305
303 /* add new entry into list which is sorted by inode number */ 306 list_add_tail(&e->list, &sbi->ino_list[type]);
304 list_add_tail(&new->list, &e->list); 307 }
305 spin_unlock(&sbi->ino_lock[type]); 308 spin_unlock(&sbi->ino_lock[type]);
306} 309}
307 310
@@ -310,14 +313,15 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
310 struct ino_entry *e; 313 struct ino_entry *e;
311 314
312 spin_lock(&sbi->ino_lock[type]); 315 spin_lock(&sbi->ino_lock[type]);
313 list_for_each_entry(e, &sbi->ino_list[type], list) { 316 e = radix_tree_lookup(&sbi->ino_root[type], ino);
314 if (e->ino == ino) { 317 if (e) {
315 list_del(&e->list); 318 list_del(&e->list);
319 radix_tree_delete(&sbi->ino_root[type], ino);
320 if (type == ORPHAN_INO)
316 sbi->n_orphans--; 321 sbi->n_orphans--;
317 spin_unlock(&sbi->ino_lock[type]); 322 spin_unlock(&sbi->ino_lock[type]);
318 kmem_cache_free(ino_entry_slab, e); 323 kmem_cache_free(ino_entry_slab, e);
319 return; 324 return;
320 }
321 } 325 }
322 spin_unlock(&sbi->ino_lock[type]); 326 spin_unlock(&sbi->ino_lock[type]);
323} 327}
@@ -346,7 +350,7 @@ void release_orphan_inode(struct f2fs_sb_info *sbi)
346 350
347void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) 351void add_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
348{ 352{
349 /* add new orphan entry into list which is sorted by inode number */ 353 /* add new orphan ino entry into list */
350 __add_ino_entry(sbi, ino, ORPHAN_INO); 354 __add_ino_entry(sbi, ino, ORPHAN_INO);
351} 355}
352 356
@@ -943,6 +947,7 @@ void init_ino_entry_info(struct f2fs_sb_info *sbi)
943 int i; 947 int i;
944 948
945 for (i = 0; i < MAX_INO_ENTRY; i++) { 949 for (i = 0; i < MAX_INO_ENTRY; i++) {
950 INIT_RADIX_TREE(&sbi->ino_root[i], GFP_ATOMIC);
946 spin_lock_init(&sbi->ino_lock[i]); 951 spin_lock_init(&sbi->ino_lock[i]);
947 INIT_LIST_HEAD(&sbi->ino_list[i]); 952 INIT_LIST_HEAD(&sbi->ino_list[i]);
948 } 953 }
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index b6fa6ec54f98..4454caa8a253 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -456,6 +456,7 @@ struct f2fs_sb_info {
456 wait_queue_head_t cp_wait; 456 wait_queue_head_t cp_wait;
457 457
458 /* for inode management */ 458 /* for inode management */
459 struct radix_tree_root ino_root[MAX_INO_ENTRY]; /* ino entry array */
459 spinlock_t ino_lock[MAX_INO_ENTRY]; /* for ino entry lock */ 460 spinlock_t ino_lock[MAX_INO_ENTRY]; /* for ino entry lock */
460 struct list_head ino_list[MAX_INO_ENTRY]; /* inode list head */ 461 struct list_head ino_list[MAX_INO_ENTRY]; /* inode list head */
461 462