Blame view
fs/f2fs/trace.c
3.47 KB
63f92ddc8 f2fs: add f2fs_io... |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* * f2fs IO tracer * * Copyright (c) 2014 Motorola Mobility * Copyright (c) 2014 Jaegeuk Kim <jaegeuk@kernel.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/fs.h> #include <linux/f2fs_fs.h> #include <linux/sched.h> |
351f4fba8 f2fs: add f2fs_de... |
14 |
#include <linux/radix-tree.h> |
63f92ddc8 f2fs: add f2fs_io... |
15 16 17 |
#include "f2fs.h" #include "trace.h" |
29e7043f4 f2fs: fix sparse ... |
18 |
static RADIX_TREE(pids, GFP_ATOMIC); |
08e4126e1 f2fs: pids_lock c... |
19 |
static spinlock_t pids_lock; |
29e7043f4 f2fs: fix sparse ... |
20 |
static struct last_io_info last_io; |
0e689d036 f2fs: add key fun... |
21 22 23 24 25 |
static inline void __print_last_io(void) { if (!last_io.len) return; |
04d328def f2fs: use bio op ... |
26 27 |
trace_printk("%3x:%3x %4x %-16s %2x %5x %5x %12x %4x ", |
0e689d036 f2fs: add key fun... |
28 29 30 |
last_io.major, last_io.minor, last_io.pid, "----------------", last_io.type, |
04d328def f2fs: use bio op ... |
31 |
last_io.fio.op, last_io.fio.op_flags, |
7a9d75481 f2fs: trace old b... |
32 |
last_io.fio.new_blkaddr, |
0e689d036 f2fs: add key fun... |
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
last_io.len); memset(&last_io, 0, sizeof(last_io)); } static int __file_type(struct inode *inode, pid_t pid) { if (f2fs_is_atomic_file(inode)) return __ATOMIC_FILE; else if (f2fs_is_volatile_file(inode)) return __VOLATILE_FILE; else if (S_ISDIR(inode->i_mode)) return __DIR_FILE; else if (inode->i_ino == F2FS_NODE_INO(F2FS_I_SB(inode))) return __NODE_FILE; else if (inode->i_ino == F2FS_META_INO(F2FS_I_SB(inode))) return __META_FILE; else if (pid) return __NORMAL_FILE; else return __MISC_FILE; } |
63f92ddc8 f2fs: add f2fs_io... |
54 55 |
void f2fs_trace_pid(struct page *page) { |
0e689d036 f2fs: add key fun... |
56 57 58 |
struct inode *inode = page->mapping->host; pid_t pid = task_pid_nr(current); void *p; |
5f4c3dec2 f2fs: use set_pag... |
59 |
set_page_private(page, (unsigned long)pid); |
0e689d036 f2fs: add key fun... |
60 |
|
c05086506 f2fs: add spin_lo... |
61 62 63 64 |
if (radix_tree_preload(GFP_NOFS)) return; spin_lock(&pids_lock); |
0e689d036 f2fs: add key fun... |
65 66 |
p = radix_tree_lookup(&pids, pid); if (p == current) |
c05086506 f2fs: add spin_lo... |
67 |
goto out; |
0e689d036 f2fs: add key fun... |
68 69 70 71 72 73 74 75 76 |
if (p) radix_tree_delete(&pids, pid); f2fs_radix_tree_insert(&pids, pid, current); trace_printk("%3x:%3x %4x %-16s ", MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), pid, current->comm); |
c05086506 f2fs: add spin_lo... |
77 78 79 |
out: spin_unlock(&pids_lock); radix_tree_preload_end(); |
63f92ddc8 f2fs: add f2fs_io... |
80 |
} |
05ca3632e f2fs: add sbi and... |
81 |
void f2fs_trace_ios(struct f2fs_io_info *fio, int flush) |
63f92ddc8 f2fs: add f2fs_io... |
82 |
{ |
0e689d036 f2fs: add key fun... |
83 84 85 86 87 88 89 90 |
struct inode *inode; pid_t pid; int major, minor; if (flush) { __print_last_io(); return; } |
05ca3632e f2fs: add sbi and... |
91 92 |
inode = fio->page->mapping->host; pid = page_private(fio->page); |
0e689d036 f2fs: add key fun... |
93 94 95 96 97 98 99 |
major = MAJOR(inode->i_sb->s_dev); minor = MINOR(inode->i_sb->s_dev); if (last_io.major == major && last_io.minor == minor && last_io.pid == pid && last_io.type == __file_type(inode, pid) && |
04d328def f2fs: use bio op ... |
100 101 |
last_io.fio.op == fio->op && last_io.fio.op_flags == fio->op_flags && |
7a9d75481 f2fs: trace old b... |
102 103 |
last_io.fio.new_blkaddr + last_io.len == fio->new_blkaddr) { |
0e689d036 f2fs: add key fun... |
104 105 106 107 108 109 110 111 112 113 114 115 116 |
last_io.len++; return; } __print_last_io(); last_io.major = major; last_io.minor = minor; last_io.pid = pid; last_io.type = __file_type(inode, pid); last_io.fio = *fio; last_io.len = 1; return; |
63f92ddc8 f2fs: add f2fs_io... |
117 |
} |
c05086506 f2fs: add spin_lo... |
118 119 120 121 122 |
void f2fs_build_trace_ios(void) { spin_lock_init(&pids_lock); } |
351f4fba8 f2fs: add f2fs_de... |
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
#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; |
b0beab501 f2fs: use paramet... |
137 |
if (++ret == max_items) |
351f4fba8 f2fs: add f2fs_de... |
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
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); } |