LinuxCommandLibrary

ionice

Set I/O scheduling priority for a process

TLDR

Run a command with the given scheduling class and priority

$ ionice [[-c|--class]] [scheduling_class] [[-n|--classdata]] [priority] [command]
copy

Set I/O scheduling class of a running process with a specific [p]id, [P]gid, or [u]id
$ ionice [[-c|--class]] [scheduling_class] -[p|P|u] [id]
copy

Run a command with custom I/O scheduling class and priority
$ ionice [[-c|--class]] [scheduling_class] [[-n|--classdata]] [priority] [command]
copy

Ignore failure to set the requested priority
$ ionice [[-t|--ignore]] [[-n|--classdata]] [priority] [[-p|--pid]] [pid]
copy

Run the command even in case it was not possible to set the desired priority (this can happen due to insufficient privileges or an old kernel version)
$ ionice [[-t|--ignore]] [[-n|--classdata]] [priority] [[-p|--pid]] [pid]
copy

Print the I/O scheduling class and priority of a running process
$ ionice [[-p|--pid]] [pid]
copy

SYNOPSIS

ionice [-c class] [-n level] [-t] -p PID...
ionice [-c class] [-n level] [-t] COMMAND [ARG...]

PARAMETERS

-c, --class=class
    Set I/O class: 0(none), 1(realtime), 2(best-effort, default), 3(idle); or names realtime, best-effort, idle

-n, --classdata=level
    Set priority level 0-7 (0 highest); ignored for idle class

-p, --pid=PID...
    Target existing process ID(s)

-t, --ignore
    Ignore errors setting target class (e.g., non-root realtime)

-h, --help
    Display usage help

-V, --version
    Output version information

DESCRIPTION

The ionice command manages the I/O priority and scheduling class of Linux processes, influencing how disk I/O operations are handled by the kernel's I/O scheduler, primarily CFQ (Completely Fair Queuing) or compatible schedulers like BFQ. It allows users to prioritize I/O requests to ensure critical tasks get preferential access to block devices, preventing low-priority jobs from starving high-priority ones.

Processes are assigned to one of three I/O classes:

  • Realtime (1): Highest priority; I/O requests serviced first, levels 0-7 (0 best).
  • Best-effort (2): Default class; fair sharing with priority levels 0-7 (0 highest).
  • Idle (3): Lowest priority; I/O only when idle, no level needed.
Class 0 reverts to kernel default (usually best-effort).

Use -p PID to adjust running processes or invoke a command directly for new ones. Without arguments, it displays the current shell process's I/O class and priority. This is useful for batch jobs, backups, or multimedia to avoid I/O contention. Root privileges are typically required for realtime class or modifying other users' processes. Modern kernels extend support beyond CFQ, but effectiveness varies by scheduler and workload.

CAVEATS

Requires CFQ/BFQ-like I/O scheduler; ineffective with noop/deadline. Root needed for realtime class or foreign PIDs. Levels apply per-task; cgroup overrides possible. No effect on non-block I/O.

EXAMPLES

ionice -c 3 dd if=/dev/zero of=bigfile bs=1M
Run dd as idle class.

ionice -c 1 -n 0 -p $(pidof mysqld)
Set realtime I/O priority 0 for MySQL.

QUERY CURRENT

Run ionice without args to print shell's class/priority: e.g., "best-effort: prio 4".

HISTORY

Added in Linux 2.6.13 (2005) by Balbir Singh; part of util-linux since v2.13. Kernel I/O scheduler interface stabilized later.

SEE ALSO

nice(1), renice(1), chrt(1), ioprio_get(1)

Copied to clipboard