]> www.infradead.org Git - users/willy/xarray.git/commitdiff
f2fs: Convert pids radix tree to XArray
authorMatthew Wilcox <willy@infradead.org>
Wed, 17 Oct 2018 19:32:57 +0000 (15:32 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 02:36:49 +0000 (22:36 -0400)
The XArray API works out rather well for this user.

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

index 78a1b873e48ade9259c2592bd263fb86f22fdf16..32a21e5d90ef7fab90c0775e1735831a9419e9ef 100644 (file)
@@ -3567,8 +3567,6 @@ static int __init init_f2fs_fs(void)
                return -EINVAL;
        }
 
-       f2fs_build_trace_ios();
-
        err = init_inodecache();
        if (err)
                goto fail;
index d0ab533a9ce89590450d509b5a6270b82343d3a5..c45fdbb96b99c248bf5f84d6cb103d74de48c2c8 100644 (file)
@@ -8,13 +8,12 @@
 #include <linux/fs.h>
 #include <linux/f2fs_fs.h>
 #include <linux/sched.h>
-#include <linux/radix-tree.h>
+#include <linux/xarray.h>
 
 #include "f2fs.h"
 #include "trace.h"
 
-static RADIX_TREE(pids, GFP_ATOMIC);
-static spinlock_t pids_lock;
+static DEFINE_XARRAY(pids);
 static struct last_io_info last_io;
 
 static inline void __print_last_io(void)
@@ -54,34 +53,13 @@ void f2fs_trace_pid(struct page *page)
 {
        struct inode *inode = page->mapping->host;
        pid_t pid = task_pid_nr(current);
-       void *p;
 
        set_page_private(page, (unsigned long)pid);
 
-retry:
-       if (radix_tree_preload(GFP_NOFS))
-               return;
-
-       spin_lock(&pids_lock);
-       p = radix_tree_lookup(&pids, pid);
-       if (p == current)
-               goto out;
-       if (p)
-               radix_tree_delete(&pids, pid);
-
-       if (radix_tree_insert(&pids, pid, current)) {
-               spin_unlock(&pids_lock);
-               radix_tree_preload_end();
-               cond_resched();
-               goto retry;
-       }
-
-       trace_printk("%3x:%3x %4x %-16s\n",
+       if (xa_store(&pids, pid, current, GFP_NOFS) != current)
+               trace_printk("%3x:%3x %4x %-16s\n",
                        MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
                        pid, current->comm);
-out:
-       spin_unlock(&pids_lock);
-       radix_tree_preload_end();
 }
 
 void f2fs_trace_ios(struct f2fs_io_info *fio, int flush)
@@ -123,43 +101,7 @@ void f2fs_trace_ios(struct f2fs_io_info *fio, int flush)
        return;
 }
 
-void f2fs_build_trace_ios(void)
-{
-       spin_lock_init(&pids_lock);
-}
-
-#define PIDVEC_SIZE    128
-static unsigned int gang_lookup_pids(pid_t *results, unsigned long first_index,
-                                                       unsigned int max_items)
-{
-       struct radix_tree_iter iter;
-       void **slot;
-       unsigned int ret = 0;
-
-       if (unlikely(!max_items))
-               return 0;
-
-       radix_tree_for_each_slot(slot, &pids, &iter, first_index) {
-               results[ret] = iter.index;
-               if (++ret == max_items)
-                       break;
-       }
-       return ret;
-}
-
 void f2fs_destroy_trace_ios(void)
 {
-       pid_t pid[PIDVEC_SIZE];
-       pid_t next_pid = 0;
-       unsigned int found;
-
-       spin_lock(&pids_lock);
-       while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) {
-               unsigned idx;
-
-               next_pid = pid[found - 1] + 1;
-               for (idx = 0; idx < found; idx++)
-                       radix_tree_delete(&pids, pid[idx]);
-       }
-       spin_unlock(&pids_lock);
+       xa_destroy(&pids);
 }
index e8075fc5b2284e9a00564d4d416c4115ef1df566..c49dc0f4f849bf0d04a359802ab4768d1f4736e9 100644 (file)
@@ -31,12 +31,10 @@ struct last_io_info {
 
 extern void f2fs_trace_pid(struct page *);
 extern void f2fs_trace_ios(struct f2fs_io_info *, int);
-extern void f2fs_build_trace_ios(void);
 extern void f2fs_destroy_trace_ios(void);
 #else
 #define f2fs_trace_pid(p)
 #define f2fs_trace_ios(i, n)
-#define f2fs_build_trace_ios()
 #define f2fs_destroy_trace_ios()
 
 #endif