用 ionice 降低磁盘 I/O 优先级

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

Linux进程磁盘I/O 优先级中风险
执行 sudo ionice -c 3 -p 进程号 把正在运行的任务降为空闲 I/O 级别,或用 ionice -c 3 tar -czf backup.tar.gz ~/Documents 直接以空闲级别启动。

01命令

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

02作用说明

ionice 把磁盘 I/O 分成三类:1 实时、2 尽力而为(默认)、3 空闲。空闲类任务只有在没有其他进程争用磁盘时才运行,非常适合备份和 updatedb 建索引。可以用 -p 修改运行中的进程,也可以直接包在命令前面。

03风险

风险中风险
使用条件ionice ships with util-linux on all major distros. I/O priority classes require the CFQ/BFQ scheduler; under none/mq-deadline the hint may have no effect.
!注意: I/O 优先级只在 CFQ/BFQ 等支持它的调度器下生效;新版内核默认的 none 或 mq-deadline 调度器基本会忽略它。实时类(1)可能饿死整个系统,除非确有流式需求否则别用。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • 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.

最后验证: 2026-09-19 · 分类: 系统与设置

06相关方案