4 * Copyright (c) 2014 Motorola Mobility
5 * Copyright (c) 2014 Jaegeuk Kim <jaegeuk@kernel.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/f2fs_fs.h>
13 #include <linux/sched.h>
14 #include <linux/radix-tree.h>
19 static RADIX_TREE(pids, GFP_ATOMIC);
20 static spinlock_t pids_lock;
21 static struct last_io_info last_io;
23 static inline void __print_last_io(void)
28 trace_printk("%3x:%3x %4x %-16s %2x %5x %5x %12x %4x\n",
29 last_io.major, last_io.minor,
30 last_io.pid, "----------------",
32 last_io.fio.op, last_io.fio.op_flags,
33 last_io.fio.new_blkaddr,
35 memset(&last_io, 0, sizeof(last_io));
38 static int __file_type(struct inode *inode, pid_t pid)
40 if (f2fs_is_atomic_file(inode))
42 else if (f2fs_is_volatile_file(inode))
43 return __VOLATILE_FILE;
44 else if (S_ISDIR(inode->i_mode))
46 else if (inode->i_ino == F2FS_NODE_INO(F2FS_I_SB(inode)))
48 else if (inode->i_ino == F2FS_META_INO(F2FS_I_SB(inode)))
56 void f2fs_trace_pid(struct page *page)
58 struct inode *inode = page->mapping->host;
59 pid_t pid = task_pid_nr(current);
65 if (radix_tree_preload(GFP_NOFS))
68 spin_lock(&pids_lock);
69 p = radix_tree_lookup(&pids, pid);
73 radix_tree_delete(&pids, pid);
75 if (radix_tree_insert(&pids, pid, current)) {
76 spin_unlock(&pids_lock);
77 radix_tree_preload_end();
82 trace_printk("%3x:%3x %4x %-16s\n",
83 MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
86 spin_unlock(&pids_lock);
87 radix_tree_preload_end();
90 void f2fs_trace_ios(struct f2fs_io_info *fio, int flush)
101 inode = fio->page->mapping->host;
102 pid = page_private(fio->page);
104 major = MAJOR(inode->i_sb->s_dev);
105 minor = MINOR(inode->i_sb->s_dev);
107 if (last_io.major == major && last_io.minor == minor &&
108 last_io.pid == pid &&
109 last_io.type == __file_type(inode, pid) &&
110 last_io.fio.op == fio->op &&
111 last_io.fio.op_flags == fio->op_flags &&
112 last_io.fio.new_blkaddr + last_io.len ==
120 last_io.major = major;
121 last_io.minor = minor;
123 last_io.type = __file_type(inode, pid);
129 void f2fs_build_trace_ios(void)
131 spin_lock_init(&pids_lock);
134 #define PIDVEC_SIZE 128
135 static unsigned int gang_lookup_pids(pid_t *results, unsigned long first_index,
136 unsigned int max_items)
138 struct radix_tree_iter iter;
140 unsigned int ret = 0;
142 if (unlikely(!max_items))
145 radix_tree_for_each_slot(slot, &pids, &iter, first_index) {
146 results[ret] = iter.index;
147 if (++ret == PIDVEC_SIZE)
153 void f2fs_destroy_trace_ios(void)
155 pid_t pid[PIDVEC_SIZE];
159 spin_lock(&pids_lock);
160 while ((found = gang_lookup_pids(pid, next_pid, PIDVEC_SIZE))) {
163 next_pid = pid[found - 1] + 1;
164 for (idx = 0; idx < found; idx++)
165 radix_tree_delete(&pids, pid[idx]);
167 spin_unlock(&pids_lock);