]> www.infradead.org Git - users/willy/xarray.git/commitdiff
f2fs: Convert ino_root to XArray
authorMatthew Wilcox <willy@infradead.org>
Wed, 17 Oct 2018 19:34:20 +0000 (15:34 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 02:36:49 +0000 (22:36 -0400)
I did a fairly major rewrite of __add_ino_entry(); please check carefully.
Also, we can remove ino_list unless it's important to write out orphan
inodes in the order they were orphaned.  It may also make more sense to
combine the array of inode_management structures into a single XArray
with tags, but that would be a job for someone who understands this
filesystem better than I do.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
fs/f2fs/checkpoint.c
fs/f2fs/f2fs.h

index a0eef95b9e0ed0760b3bc56056c7a71a3b766ea3..441d4d6e4de57fdaa05a3509027c1e9e26ab4b3f 100644 (file)
@@ -461,33 +461,30 @@ static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino,
        struct inode_management *im = &sbi->im[type];
        struct ino_entry *e, *tmp;
 
-       tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS);
-
-       radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
-
-       spin_lock(&im->ino_lock);
-       e = radix_tree_lookup(&im->ino_root, ino);
-       if (!e) {
-               e = tmp;
-               if (unlikely(radix_tree_insert(&im->ino_root, ino, e)))
-                       f2fs_bug_on(sbi, 1);
-
-               memset(e, 0, sizeof(struct ino_entry));
-               e->ino = ino;
-
-               list_add_tail(&e->list, &im->ino_list);
-               if (type != ORPHAN_INO)
-                       im->ino_num++;
+       xa_lock(&im->ino_root);
+       e = xa_load(&im->ino_root, ino);
+       if (e)
+               goto found;
+       xa_unlock(&im->ino_root);
+
+       tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS | __GFP_ZERO);
+       xa_lock(&im->ino_root);
+       e = __xa_cmpxchg(&im->ino_root, ino, NULL, tmp,
+                                               GFP_NOFS | __GFP_NOFAIL);
+       if (e) {
+               kmem_cache_free(ino_entry_slab, tmp);
+               goto found;
        }
+       e = tmp;
 
+       e->ino = ino;
+       list_add_tail(&e->list, &im->ino_list);
+       if (type != ORPHAN_INO)
+               im->ino_num++;
+found:
        if (type == FLUSH_INO)
                f2fs_set_bit(devidx, (char *)&e->dirty_device);
-
-       spin_unlock(&im->ino_lock);
-       radix_tree_preload_end();
-
-       if (e != tmp)
-               kmem_cache_free(ino_entry_slab, tmp);
+       xa_unlock(&im->ino_root);
 }
 
 static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
@@ -495,17 +492,14 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
        struct inode_management *im = &sbi->im[type];
        struct ino_entry *e;
 
-       spin_lock(&im->ino_lock);
-       e = radix_tree_lookup(&im->ino_root, ino);
+       xa_lock(&im->ino_root);
+       e = __xa_erase(&im->ino_root, ino);
        if (e) {
                list_del(&e->list);
-               radix_tree_delete(&im->ino_root, ino);
                im->ino_num--;
-               spin_unlock(&im->ino_lock);
                kmem_cache_free(ino_entry_slab, e);
-               return;
        }
-       spin_unlock(&im->ino_lock);
+       xa_unlock(&im->ino_root);
 }
 
 void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
@@ -524,12 +518,8 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
 bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode)
 {
        struct inode_management *im = &sbi->im[mode];
-       struct ino_entry *e;
 
-       spin_lock(&im->ino_lock);
-       e = radix_tree_lookup(&im->ino_root, ino);
-       spin_unlock(&im->ino_lock);
-       return e ? true : false;
+       return xa_load(&im->ino_root, ino) ? true : false;
 }
 
 void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all)
@@ -540,14 +530,14 @@ void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all)
        for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) {
                struct inode_management *im = &sbi->im[i];
 
-               spin_lock(&im->ino_lock);
+               xa_lock(&im->ino_root);
                list_for_each_entry_safe(e, tmp, &im->ino_list, list) {
                        list_del(&e->list);
-                       radix_tree_delete(&im->ino_root, e->ino);
+                       __xa_erase(&im->ino_root, e->ino);
                        kmem_cache_free(ino_entry_slab, e);
                        im->ino_num--;
                }
-               spin_unlock(&im->ino_lock);
+               xa_unlock(&im->ino_root);
        }
 }
 
@@ -564,11 +554,11 @@ bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
        struct ino_entry *e;
        bool is_dirty = false;
 
-       spin_lock(&im->ino_lock);
-       e = radix_tree_lookup(&im->ino_root, ino);
+       xa_lock(&im->ino_root);
+       e = xa_load(&im->ino_root, ino);
        if (e && f2fs_test_bit(devidx, (char *)&e->dirty_device))
                is_dirty = true;
-       spin_unlock(&im->ino_lock);
+       xa_unlock(&im->ino_root);
        return is_dirty;
 }
 
@@ -577,10 +567,10 @@ int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi)
        struct inode_management *im = &sbi->im[ORPHAN_INO];
        int err = 0;
 
-       spin_lock(&im->ino_lock);
+       xa_lock(&im->ino_root);
 
        if (time_to_inject(sbi, FAULT_ORPHAN)) {
-               spin_unlock(&im->ino_lock);
+               xa_unlock(&im->ino_root);
                f2fs_show_injection_info(FAULT_ORPHAN);
                return -ENOSPC;
        }
@@ -589,7 +579,7 @@ int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi)
                err = -ENOSPC;
        else
                im->ino_num++;
-       spin_unlock(&im->ino_lock);
+       xa_unlock(&im->ino_root);
 
        return err;
 }
@@ -598,10 +588,10 @@ void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi)
 {
        struct inode_management *im = &sbi->im[ORPHAN_INO];
 
-       spin_lock(&im->ino_lock);
+       xa_lock(&im->ino_root);
        f2fs_bug_on(sbi, im->ino_num == 0);
        im->ino_num--;
-       spin_unlock(&im->ino_lock);
+       xa_unlock(&im->ino_root);
 }
 
 void f2fs_add_orphan_inode(struct inode *inode)
@@ -750,7 +740,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
        orphan_blocks = GET_ORPHAN_BLOCKS(im->ino_num);
 
        /*
-        * we don't need to do spin_lock(&im->ino_lock) here, since all the
+        * we don't need to lock the ino_root here, since all the
         * orphan inode operations are covered under f2fs_lock_op().
         * And, spin_lock should be avoided due to page operations below.
         */
@@ -1641,8 +1631,7 @@ void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi)
        for (i = 0; i < MAX_INO_ENTRY; i++) {
                struct inode_management *im = &sbi->im[i];
 
-               INIT_RADIX_TREE(&im->ino_root, GFP_ATOMIC);
-               spin_lock_init(&im->ino_lock);
+               xa_init(&im->ino_root);
                INIT_LIST_HEAD(&im->ino_list);
                im->ino_num = 0;
        }
index 17382da7f0bd934bc9de9cc5c96e7d06a151e86e..2780c6237b0796191873c33601aa73a3fddcb111 100644 (file)
@@ -1096,8 +1096,7 @@ enum inode_type {
 
 /* for inner inode cache management */
 struct inode_management {
-       struct radix_tree_root ino_root;        /* ino entry array */
-       spinlock_t ino_lock;                    /* for ino entry lock */
+       struct xarray ino_root;                 /* ino entry array */
        struct list_head ino_list;              /* inode list head */
        unsigned long ino_num;                  /* number of entries */
 };