How do I increase the I/O priority of some processes on Red Hat Enterprise Linux 5?
Updated 2012年九月16日10:04 -
Release Found: Red Hat Enterprise Linux 5 and later
Introduction
The I/O priority and scheduling class of a process can be modified by the ionice
command. Linux supports three scheduling classes:
-
Idle: A program running with idle I/O priority will only get disk time when no other program has asked for disk io for a defined grace period.
-
Best effort: This is the default scheduling class for any process that hasn't asked for a specific I/O priority.
-
Real time: The Real Time (RT) scheduling class is given first access to the disk, regardless of what else is going on in the system.
A process by default is in the Best Effort class with a priority of 0, i.e. the highest priority in that class. The best use case for using ionice
to improve performance is when you need to do two classes of tasks at once: the ones that don’t use much disk I/O but demands fast response times, and the ones that do a lot of disk I/O but don’t need it done urgently.
Solution
To increase the I/O priority of a process you can use the following command:
# ionice -c1 -n0 -p<PID>
Where:
-
"-c1"
indicates Real time scheduling -
"-n0"
is for highest priority -
"-p <PID>
is the process ID
Also, you can lower the I/O priority of a process with the following:
# ionice -c2 -n4 -p<PID>
Where:
-
"-c2"
indicates best-effort scheduling -
"-n4"
is for priority 4
To check the current I/O priority of a process run the following command:
# ionice <PID>
For example:
# ionice 9709
realtime: prio 7
For more details on the ionice
command options, see the manual page by running "man ionice
".
Applications
One use case is rescheduling an entire parent shell to idle class, so that all commands executed from that shell are idle priority. You can get this from the $$ shell variable in bash
and sh
.
For example:
# echo $
29033
This output means that your current bash shell is process id 29033
. If you want to switch the whole shell to idle disk priority, you can run:
# ionice -c3 -p$
Now everything you do in this shell is in idle priority.
Another major application of the ionice
command would be during system backups. One would like to change the I/O priority of backup software, so that it has less interference with other operations of the system.
Note: This only works on kernels 2.6.13 and later using the CFQ I/O scheduler. You can check what scheduler is running by running cat /sys/block/[sh]d[a-z]*/queue/scheduler
in Red Hat Enterprise Linux 5. The word outlined in brackets is currently selected.
For example, the following output shows the the CFQ scheduler is in use:
$ cat /sys/block/[sh]d[a-z]*/queue/scheduler
noop anticipatory deadline [cfq]