为什么 Linux 磁盘很慢且 I/O wait 很高?

诊断 Linux 高 I/O wait:找出饱和的磁盘和占用 I/O 的进程,降低其 I/O 优先级,让系统恢复响应。

Linux进程iotop 磁盘 IO 监控监控性能磁盘iostat 磁盘 IO中风险
先运行 iostat -x 2 5 查看哪块磁盘已饱和,再用 iotop 找出占用 I/O 的进程。

快速开始

I/O wait 高说明 CPU 空闲但一直在等磁盘。解决思路是:先确认哪块磁盘忙,再找出占用 I/O 的进程,最后降低它的 I/O 优先级。本文按诊断、修复、验证的顺序说明。

症状

?系统明显变慢,负载很高但 CPU 使用率不高。top 或 vmstat 里 wa 数值很高,磁盘指示灯常亮,应用程序会卡住几秒。

用 iostat -x 查看哪块磁盘已饱和

I/O wait 高通常意味着某块磁盘利用率接近 100%。扩展的 iostat 统计会按设备显示 %util 和 await,帮你判断瓶颈是单块磁盘还是阵列。如果某设备的 %util 接近 100,且 await 远高于正常值,它就是导致卡顿的磁盘。

Linux用 iostat -x 分析磁盘 I/O低风险步骤 1

iostat -x 按设备输出扩展统计——r/s、w/s、await 和 %util——并按间隔刷新,方便观察饱和度。

命令
$ iostat -x 2 5

用 iotop 找出占用 I/O 的进程

知道哪块磁盘忙之后,还要找出是哪个进程在读写。iotop 实时显示每个进程的读写速率,能帮你找出备份、索引或失控的服务。需要 sudo 运行;-o 参数只显示真正产生 I/O 的进程。

实时找出是哪个进程在大量读写硬盘,定位系统变慢的原因。

命令
$ sudo iotop -o -a

用 ionice 降低 I/O 优先级

如果大量读写的进程不需要立刻完成,可以用 ionice 把它放入 idle I/O 类。这样交互操作和系统服务能优先获得磁盘时间,后台任务继续跑的同时机器不再卡顿。执行前确认 PID 正确;ionice 用 -p 指定 PID。

把备份、索引等重 I/O 任务降为“空闲时才运行”,系统不再一卡一卡。

命令
$ sudo ionice -c 3 -p $(pidof updatedb)

用 vmstat 确认 I/O wait 已下降

调整 I/O 优先级后,观察 vmstat 的 wa 列。它应回落到接近 0,同时系统操作恢复流畅。如果 wa 仍然很高,可能是磁盘本身故障或硬件性能不足;应检查磁盘健康并考虑调整任务计划。

vmstat 每秒输出一行 CPU、内存、swap 换入换出和 I/O 等待数据,比 top 更直观地判断瓶颈类型。

命令
$ vmstat 2 5
!ionice 只调整优先级,不能修复坏盘或硬件性能不足。对错误的 PID(尤其是关键系统进程)使用 sudo 可能拖慢必要服务。执行前请确认 PID 正确。

如何确认已解决

降低 I/O 优先级后,vmstat 的 wa 列应回落到接近 0,系统操作恢复流畅;iostat 显示之前饱和的设备 %util 明显下降。

来源

  • vmstat(8) - Linux manual page
    Ubuntu Manpages · technical · 2026-09-17
    依据: vmstat reports virtual memory statistics; the interval and count arguments run it repeatedly, and columns include si/so swap activity and wa I/O wait.
  • ionice(1) — Arch Manual Pages
    Arch Linux · community · 2026-09-17
    依据: Shows ionice [-c class] [-n level] [-t] -p pid usage and describes the idle class which only gets disk time when nobody else needs it.
  • ionice(1) — Debian bookworm
    Debian Manpages · community · 2026-09-17
    依据: SYNOPSIS ionice [-c class] [-n level] [-t] -p PID and options --class, --classdata, --pid are documented, including class 3 = idle.
  • iotop(8) — Arch Linux manual
    Arch Linux · community · 2026-09-17
    依据: Arch manual describes iotop's --only (-o) option to show only processes or threads actually doing I/O
  • iostat(1) - Report CPU statistics and I/O statistics for devices
    Ubuntu Manpages · technical · 2026-09-17
    依据: -x shows extended statistics; interval and count parameters report repeatedly; %util is the percentage of elapsed time during which the device was busy.
  • iotop(8) — Debian manpage
    Debian · community · 2026-09-17
    依据: Debian manpage for iotop documents -o (only show processes actually doing I/O) and -a (accumulated I/O) options

最后验证: 2026-09-22

相关指南