From: Matthew Wilcox <mawilcox@xxxxxxxxxxxxx> The XArray API works out rather well for this user. Signed-off-by: Matthew Wilcox <mawilcox@xxxxxxxxxxxxx> --- fs/f2fs/super.c | 2 -- fs/f2fs/trace.c | 60 ++++----------------------------------------------------- fs/f2fs/trace.h | 2 -- 3 files changed, 4 insertions(+), 60 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 708155d9c2e4..d608edffe69e 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2831,8 +2831,6 @@ static int __init init_f2fs_fs(void) { int err; - f2fs_build_trace_ios(); - err = init_inodecache(); if (err) goto fail; diff --git a/fs/f2fs/trace.c b/fs/f2fs/trace.c index bccbbf2616d2..f316a42c547f 100644 --- a/fs/f2fs/trace.c +++ b/fs/f2fs/trace.c @@ -16,8 +16,7 @@ #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) @@ -57,28 +56,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); - 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); - - f2fs_radix_tree_insert(&pids, pid, current); - - 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) @@ -120,43 +104,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); } diff --git a/fs/f2fs/trace.h b/fs/f2fs/trace.h index 67db24ac1e85..157e4564e48b 100644 --- a/fs/f2fs/trace.h +++ b/fs/f2fs/trace.h @@ -34,12 +34,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 -- 2.15.1 -- To unsubscribe from this list: send the line "unsubscribe cgroups" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html