OSDN Git Service

f2fs: add key functions for f2fs_io_tracer
authorJaegeuk Kim <jaegeuk@kernel.org>
Thu, 18 Dec 2014 03:51:57 +0000 (19:51 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 10 Jan 2015 01:02:24 +0000 (17:02 -0800)
This patch adds two key functions to trace process ids and IOs.
The basic idea is to
1. remain process ids, pids, in page->private.
2. show pids in IO traces.

So, later we can retrieve process information according to IO traces.

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

index 4e4a069..19f5216 100644 (file)
 #include "f2fs.h"
 #include "trace.h"
 
+RADIX_TREE(pids, GFP_NOIO);
+struct last_io_info last_io;
+
+static inline void __print_last_io(void)
+{
+       if (!last_io.len)
+               return;
+
+       trace_printk("%3x:%3x %4x %-16s %2x %5x %12x %4x\n",
+                       last_io.major, last_io.minor,
+                       last_io.pid, "----------------",
+                       last_io.type,
+                       last_io.fio.rw, last_io.fio.blk_addr,
+                       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;
+}
+
 void f2fs_trace_pid(struct page *page)
 {
+       struct inode *inode = page->mapping->host;
+       pid_t pid = task_pid_nr(current);
+       void *p;
+
+       page->private = pid;
+
+       p = radix_tree_lookup(&pids, pid);
+       if (p == current)
+               return;
+       if (p)
+               radix_tree_delete(&pids, pid);
+
+       f2fs_radix_tree_insert(&pids, pid, current);
+
+       trace_printk("%3x:%3x %4x %-16s\n",
+                       MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
+                       pid, current->comm);
+
 }
 
 void f2fs_trace_ios(struct page *page, struct f2fs_io_info *fio, int flush)
 {
+       struct inode *inode;
+       pid_t pid;
+       int major, minor;
+
+       if (flush) {
+               __print_last_io();
+               return;
+       }
+
+       inode = page->mapping->host;
+       pid = page_private(page);
+
+       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) &&
+                       last_io.fio.rw == fio->rw &&
+                       last_io.fio.blk_addr + last_io.len == fio->blk_addr) {
+               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;
 }
index 08856a9..aa6663b 100644 (file)
 #ifdef CONFIG_F2FS_IO_TRACE
 #include <trace/events/f2fs.h>
 
+enum file_type {
+       __NORMAL_FILE,
+       __DIR_FILE,
+       __NODE_FILE,
+       __META_FILE,
+       __ATOMIC_FILE,
+       __VOLATILE_FILE,
+       __MISC_FILE,
+};
+
+struct last_io_info {
+       int major, minor;
+       pid_t pid;
+       enum file_type type;
+       struct f2fs_io_info fio;
+       block_t len;
+};
+
 extern void f2fs_trace_pid(struct page *);
 extern void f2fs_trace_ios(struct page *, struct f2fs_io_info *, int);
 #else