我需要了解哪些文件消耗了我的硬盘的 iops。仅仅使用“strace”并不能解决我的问题。我想知道,哪些文件真正写入磁盘,而不是页面缓存。我尝试使用“systemtap”,但我不明白如何找出哪些文件(文件名或 inode)消耗了我的 iops。有什么工具可以解决我的问题吗?
2 回答
是的,您绝对可以使用SystemTap进行跟踪。当上层(通常是 VFS 子系统)要发出 I/O 操作时,它会调用submit_bio
和generic_make_request
函数。请注意,这些并不一定意味着单个物理 I/O 操作。例如,来自相邻扇区的写入可以由 I/O 调度程序合并。
诀窍是如何确定generic_make_request
. 读取非常简单,因为此函数将在与 call 相同的上下文中read()
调用。写入通常是异步的,因此write()
将简单地更新页面缓存条目并将其标记为脏,同时submit_bio
由没有原始调用进程信息的写回内核线程之一调用:
可以通过查看结构中的page
引用来推断写入bio
- 它mapping
具有struct address_space
. struct file
对应于打开的文件还包含f_mapping
指向相同的address_space实例,它还指向dentry
包含文件的名称(这可以通过使用来完成task_dentry_path
)
所以我们需要两个探针:一个捕获读取/写入文件和保存路径并保存address_space
到关联数组的尝试,第二个捕获generic_make_request
调用(这是由 probe 执行的ioblock.request
)。
这是一个计算 IOPS 的示例脚本:
// maps struct address_space to path name
global paths;
// IOPS per file
global iops;
// Capture attempts to read and write by VFS
probe kernel.function("vfs_read"),
kernel.function("vfs_write") {
mapping = $file->f_mapping;
// Assemble full path name for running task (task_current())
// from open file "$file" of type "struct file"
path = task_dentry_path(task_current(), $file->f_path->dentry,
$file->f_path->mnt);
paths[mapping] = path;
}
// Attach to generic_make_request()
probe ioblock.request {
for (i = 0; i < $bio->bi_vcnt ; i++) {
// Each BIO request may have more than one page
// to write
page = $bio->bi_io_vec[i]->bv_page;
mapping = @cast(page, "struct page")->mapping;
iops[paths[mapping], rw] <<< 1;
}
}
// Once per second drain iops statistics
probe timer.s(1) {
println(ctime());
foreach([path+, rw] in iops) {
printf("%3d %s %s\n", @count(iops[path, rw]),
bio_rw_str(rw), path);
}
delete iops
}
此示例脚本适用于 XFS,但需要更新以支持 AIO 和卷管理器(包括 btrfs)。另外,我不确定它将如何处理元数据读取和写入,但这是一个好的开始;)
如果您想了解更多关于 SystemTap 的信息,可以查看我的书: http: //myaut.github.io/dtrace-stap-book/kernel/async.html
Maybe iotop gives you a hint about which process are doing I/O, in consequence you have an idea about the related files.
iotop --only
the --only option is used to see only processes or threads actually doing I/O, instead of showing all processes or threads