Iodump
iodump
Install / Use
/learn @os-health/IodumpREADME
iops dump使用手册
English | 中文
目录
- 一、工具介绍
- 二、工具特点
- 三、工具安装
- 四、使用说明
- 五、输出说明
- 六、结果有效性
- 七、使用案例
- 7.1、诊断磁盘io打满
- 7.2、内存颠簸型磁盘io打满
- 7.3、诊断元数据io
- 7.4、写类型的元数据io
- 7.5、获取元数据io的文件信息
- 7.6、读类型的元数据io
- 7.7、写系统调用触发元数据读io
- 7.8、存储io的双峰模式
- 八、性能开销
- 九、许可证
- 十、技术交流
<a name="工具介绍" ></a>
一、工具介绍
iops dump工具是利用内核tracepoint静态探针点技术实现的一个io问题排查工具。通过iops dump工具,我们可以获取每一个IOPS(w/s和r/s)的详细信息,不仅包括IO请求的size大小,还包括IO请求的扇区地址,同时还包含IO请求的发生时间、读写的文件全路径、产生IO请求的进程、产生IO请求的系统调用和扩展IO类型等信息。这其中最具有特色的就是读写的文件全路径功能。为了便于向大家介绍iops dump工具,下文将我们简称其为iodump。
<a name="工具特点" ></a>
二、工具特点
当我们要排查操作系统磁盘IO问题时,可以使用iostat扩展命令进行具体分析。当iostat工具显示此时磁盘IO并发很高,磁盘使用率接近饱和时,还需要依赖更多的工具进一步查看影响磁盘IO使用率高的进程信息和读写文件信息。
常见的工具或者方法有iotop、blktrace、ftrace和block_dump等。实际使用中,它们都有各种不足:
- iotop工具,可以细化到进程带宽信息,但缺乏进程级的IOPS信息,也没有对应的磁盘分区信息。
- blktrace工具,功能强大,但使用较复杂。获取sector信息后,进一步通过debugfs等其他方式解析文件路径也比较低效。
- ftrace工具,当跟踪块设备层静态探针点时,功能和blktrace工具类似,也需要通过debugfs等工具进一步解析文件路径。当跟踪文件系统层探针点函数时,无法精确对应IOPS数量。
- block_dump工具,也同样存在以上ftrace工具的2个不足。
相比其他磁盘io类工具,iodump有如下几个特色优势 :
- 支持自定义选择blk层探针点函数。
- 支持自定义输出字段信息,包括时间、进程名、进程ID、IO大小、扇区地址、磁盘分区、读写类型、扩展IO类型、IO来源、Inode号,文件全路径。
- 当采集进程异常退出后,支持内核态自动关闭探针。
- 支持从2.6.32以上的各内核版本。
- 当IOPS高时,支持抽样输出。
iodump功能虽然强大,<font color=red>但iodump本质上采用的是加载内核模块方式实现,可能会引起操作系统crash,请在重要的生产环境使用前,提前进行充分测试</font>。从计算平台的实际使用情况,未发生生产环境宕机。
<a name="工具安装" ></a>
三、工具安装
工具的安装,有如下几种方法:
<a name="rpm包打包方法1" ></a>
3.1、rpm包打包方法1
rpm包的打包方法如下,本方法适用于AnolisOS and CentOS等操作系统环境。
$ yum install rpm-build rpmdevtools git
$ cd /tmp/ # work dir
$ git clone https://gitee.com/anolis/iodump.git
$ rpmdev-setuptree
$ tar -zcvf ~/rpmbuild/SOURCES/iodump-$(cat iodump/spec/iodump.spec |grep Version |awk '{print $2}').tar.gz iodump
$ cp iodump/spec/iodump.spec ~/rpmbuild/SPECS/
$ rpmbuild -bb ~/rpmbuild/SPECS/iodump.spec
$ cd ~/rpmbuild/RPMS/x86_64/
$ sudo rpm -ivh $(ls)
$ sudo rpm -e iodump-$(uname -r) # remove package
iodump工具本质上是内核驱动模块,在一个特定内核版本上生成的rpm包在另外一个不同的内核版本上是不能正常工作的。在这里我们将内核版本信息加入到rpm包的name部分,用以识别不同内核版本的rpm包。这里我们推荐使用如下rpm的查询命令区分一个rpm包的name、version、release和arch四个部分的内容。我们使用连续的3横线来区隔不同的部分,结果一目了然。
$ rpm -qp iodump-4.19.91-24.8-1.0.1-1.an8.x86_64.rpm --queryformat="%{name}---%{version}---%{release}---%{arch}\n"
iodump-4.19.91-24.8---1.0.1---1.an8---x86_64
使用这个方法打rpm,默认会依赖当前机器上默认第一个kernel-devel包。如果想指定版本的kernel-devel包,可以使用如下rpmbuild命令通过宏参数传入内核版本信息。
$ rpmbuild -bb ~/rpmbuild/SPECS/iodump.spec --define "%kver $(uname -r)"
$ rpmbuild -bb ~/rpmbuild/SPECS/iodump.spec --define "%kver 4.19.91-24.8.an8.x86_64"
<a name="rpm包打包方法2" ></a>
3.2、rpm包打包方法2
有些情况下,在一个发行版下面,迭代了很多版本的内核,本方法适用于这种场景。
这里以Anolis 8为例,有Anolis8.2、8.4和8.6等多个小的发行版本,每个小版本也分别对应了不同的内核版本。
Release Kernel Version
8.2 ANCK 64位 4.19.91-25.8.an8.x86_64
8.4 ANCK 64位 4.19.91-26.an8.x86_64
8.6 ANCK 64位 4.19.91-26.1.an8.x86_64
此时,新版本的gcc版本通常也更新,会对低版本向下兼容。因此,我们选择最新版本Anolis8.6作为打包机。并且安装上所有需要支持的内核版本对应的kernel-devel的rpm包。
Release Kernel-devel
8.2 ANCK 64位 kernel-devel-4.19.91-25.8.an8.x86_64
8.4 ANCK 64位 kernel-devel-4.19.91-26.an8.x86_64
8.6 ANCK 64位 kernel-devel-4.19.91-26.1.an8.x86_64
相关版本的kernel-devel包,我们推荐在阿里巴巴开源镜像站进行搜索查找并下载。
https://developer.aliyun.com/packageSearch
具体打包方案如下:
$ rpm -ivh --force kernel-devel-4.19.91-25.8.an8.x86_64.rpm kernel-devel-4.19.91-26.an8.x86_64.rpm
$ yum install rpm-build rpmdevtools git
$ cd /tmp/ # work dir
$ git clone https://gitee.com/anolis/iodump.git
$ rpmdev-setuptree
$ tar -zcvf ~/rpmbuild/SOURCES/iodump-$(cat iodump/spec/distribution.spec |grep Version |awk '{print $2}').tar.gz iodump
$ cp iodump/spec/distribution.spec ~/rpmbuild/SPECS/
$ rpmbuild -bb ~/rpmbuild/SPECS/distribution.spec
$ cd ~/rpmbuild/RPMS/x86_64/
$ rpm -qpl $(ls) | grep kiodump # display all version kiodump
$ sudo rpm -ivh $(ls)
$ sudo rpm -e iodump # remove package
<a name="rpm包打包方法3" ></a>
3.3、rpm包打包方法3
在一些大型互联网公司,会在低版本发行版上使用较高版本内核的情况。比如centos7的原装内核版本是3.10,但是为了支持业务需求,在centos7的发行版上将内核升级为更高版本,如4.18内核。本方法适用于这种场景
这里以centos7为例,假设这里当前某公司同时使用了6个版本的内核,分别是3.10.0-1062、3.10.0-1127、3.10.0-1160、4.18.0-240、4.18.0-305和4.18.0-348。我们需要基于centos7发行版,制作2个docker镜像。
第一个docker镜像中包含3个3.10内核版本,需要安装如下软件包,命名为image-centos7。
$ yum install rpm-build
$ rpm -ivh --force kernel-devel-3.10.0-1062.el7.x86_64.rpm kernel-devel-3.10.0-1127.el7.x86_64.rpm kernel-devel-3.10.0-1160.el7.x86_64.rpm
第二个docker镜像中包含3个4.18内核版本,需要安装如下软件包,命名为image-centos8。
$ yum install rpm-build
$ rpm -ivh --force kernel-devel-4.18.0-240.el8.x86_64.rpm kernel-devel-4.18.0-305.el8.x86_64.rpm kernel-devel-4.18.0-348.el8.x86_64.rpm
$ rpm -Uvh gcc-8.5.0-4.el8_5.x86_64.rpm # 具体需要升级的gcc相关rpm包参考公司内部资料
然后,具体打包方案如下:
$ yum install rpmdevtools git docker
$ rpmdev-setuptree
$ cd ~/
$ git clone https://gitee.com/anolis/iodump.git
$ tar -zcvf ~/rpmbuild/SOURCES/iodump-$(cat iodump/spec/docker.spec |grep Version |awk '{print $2}').tar.gz iodump
$ cp iodump/spec/docker.spec ~/rpmbuild/SPECS/
$ docker run --net=host -u root -v ~/rpmbuild:/root/rpmbuild -w /root/rpmbuild -it image-centos8 /bin/bash -c "rpmbuild -bb /root/rpmbuild/SPECS/docker.spec"
$ docker run --net=host -u root -v ~/rpmbuild:/root/rpmbuild -w /root/rpmbuild -it image-centos7 /bin/bash -c "rpmbuild -bb /root/rpmbuild/SPECS/docker.spec"
$ rm -fr ~/rpmbuild/SPECS/kiodump/ # clear kiodump.ko
$ cd ~/rpmbuild/RPMS/x86_64/
$ rpm -qpl iodump-*.an8.x86_64.rpm | grep kiodump # display all version kiodump
$ sudo rpm -ivh iodump-*.an8.x86_64.rpm
$ sudo rpm -e iodump # remove package
<a name="deb包打包方法" ></a>
3.4、deb包打包方法
deb包的打包方法如下,本方法适用于Ubuntu等操作系统环境。
$ apt-get update
$ apt install git
$ cd ~/
$ git clone https://gitee.com/anolis/iodump.git
$ cd iodump/debian
$ ./build.sh
$ dpkg -i iodump-4.4.0-87-generic_1.0.1-1_amd64.deb
$ dpkg -r iodump-4.4.0-87-generic # remove package
<a name="源代码编译安装" ></a>
3.5、源代码编译安装
源代码安装方法。
$ cd ~/
$ git clone https://gitee.com/anolis/iodump.git
$ cd iodump
$ make
$ sudo make install
$ sudo make uninstall # remove
<a name="使用说明" ></a>
四、使用说明
<a name="基本使用" ></a>
4.1、基本使用
基本运命命令如下。并且运行时需要使用sudo进行提权。
$ sudo iodump -p sda
结束运行iodump,可以在运行过程中直接使用键盘的ctrl+c的组合,或在另外一个终端运行如下命令。
$ sudo killall iodump
$ sudo killall -9 iodump
当向iodump进程发送SIGHUP、SIGINT和SIGTERM等信号时,用户态的iodump进程会在退出前向内核模块发送关闭内核跟踪的消息。但是,当向iodump进程发送-9,即SIGKILL信号时,用户态进程iodump将强制退出,无法向内核模块发送关闭内核跟踪的消息。此时,kiodump内核模块会在用户态iodump进程异常退出后,自动关闭内核跟踪开关。其它的blktrace等工具并没有此功能。
<a name="参数说明" ></a>
4.2、参数说明
为了完整的了解使用方法,我们可以查看帮助信息。
$ iodump -h
Usage: iodump [OPTIONS]
Summary: this is a io tools. it can dump the details of struct request or struct bio.
Options:
-h Get the help information.
-H Hiding header information.
-a <G> Set blk tracepoint action which is fully compatible with blktrace, default G, See Actions.
-o <pid,comm> Set the output field, such as datetime,comm,pid, See Formats.
-p <sda2> Set partition parameter, this option is necessary.
-s <filepath> Set saving output to the file. if not set, it will output to standard output.
-t <time> Set tracing last time, default last time is 300 second, default 300 seconds.
-O <ino> Set the extra output field, such as tid,ino, See Formats.
-S <number> Set sample number, Only 1/number output is displayed, default 1.
-c <comm> Just output exact match comm string record.
-C <comm> Just output record which comm contain the comm string.
-P <pid> Just output exact match pid record.
Major Actions:
ACTION TRACEPOINT UNIT
Q block_bio_queue bio
G block_getrq bio
I block_rq_insert request
D block_rq_issue request
C block_rq_complete request
Minor Actions:
B block_bio_bounce bio
F block_bio_frontmerge bio
M block_bio_backmerge bio
S block_sleeprq bio
X block_split bio
R block_rq_requeue request
Formats:
FIELD DESCRIPTION
datetime Such as 2022-03-23T16:42:05.315695, Precision millisecond.
timestamp Such as 1648025082259168, Precision millisecond.
comm Such as iodump, process short name.
pid tgid
tid task id
iosize IO size, the unit is byte.
sector Sector address on the disk.
partition Such as sda5.
rw The value list is R(read) or W(write).
rwsec The value list is A(ahead) E(secure) F(force unit access) M(meta) S(sync) V(vacant)
launcher The bottom function of the call stac
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
