Relation between CPU nice and I/O nice
Tagged:  •    •    •    •    •  

I feel a bit ashamed about it, but after all those years of using Linux, I discovered the ionice(1) command only yesterday. Where nice(1) affects the CPU scheduler, ionice affects the disk scheduler. This article explains the command pretty well, so I'd recommend you to read it first.

So far so good. But now I was wondering, do I need to set the I/O priority explicitely for some process or is the I/O priority related to the CPU priority in some way? If the latter is true, it would be sufficient to start a process with the nice(1) command without hassling with ionice(1).

Fortunately, that relation exists. But only if you're using the CFQ I/O scheduler, which should be enabled by default on most Linux systems. To check, enter the command

cat /sys/block/[sh]d[a-z]*/queue/scheduler

and see if cfq is surrouned with square brackets.

The relation between CPU nice and I/O nice is expressed in this formula:

io_nice = (cpu_nice + 20) / 5

(well hidden in /usr/src/linux/Documentation/block/ioprio.txt)

That means that processes with nice 0 (default) have an I/O priority of 4, and all processes with nice value 15 or higher will have the lowest I/O priority available: 7.