f2fs: add f2fs_destroy_trace_ios to free radix tree
authorJaegeuk Kim <jaegeuk@kernel.org>
Wed, 7 Jan 2015 22:09:48 +0000 (14:09 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 10 Jan 2015 01:02:28 +0000 (17:02 -0800)
This patch removes radix tree after finishing tracing IOs.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/super.c
fs/f2fs/trace.c
fs/f2fs/trace.h

index e6f035c868d3a0cbe7f8161d2493e607e4df27b8..0e97974bbbbdca71196109d80f40a814b5648ced 100644 (file)
@@ -1272,6 +1272,7 @@ static void __exit exit_f2fs_fs(void)
        destroy_node_manager_caches();
        destroy_inodecache();
        kset_unregister(f2fs_kset);
+       f2fs_destroy_trace_ios();
 }
 
 module_init(init_f2fs_fs)
index 92fa38a47e638dd3a71064f531bbecc0b16b594e..b3570dcca945fa29d293b7e871d3a80a73b3cca9 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/fs.h>
 #include <linux/f2fs_fs.h>
 #include <linux/sched.h>
+#include <linux/radix-tree.h>
 
 #include "f2fs.h"
 #include "trace.h"
@@ -120,3 +121,39 @@ 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 == PIDVEC_SIZE)
+                       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);
+}
index eb39fa08cd45855c6df105d7e2eabcc0ea77673e..1041dbeb52ae4f2c73e36a06dc2c54611f074e40 100644 (file)
@@ -35,10 +35,12 @@ struct last_io_info {
 extern void f2fs_trace_pid(struct page *);
 extern void f2fs_trace_ios(struct page *, 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(p, i, n)
 #define f2fs_build_trace_ios()
+#define f2fs_destroy_trace_ios()
 
 #endif
 #endif /* __F2FS_TRACE_H__ */