nice and ionice: which one should come first?
Solution 1
If nice
caused lots of I/O, you would want to do:
ionice -c 3 nice ...
so that the impact of the I/O would be minimized.
Conversely, if ionice
performed lots of computation, you would want to do
nice -n 19 ionice ...
to minimize its CPU impact.
But neither of these is true, they're both very simple commands (they just make a system call to change a process parameter, then execute the command). So the difference should be negligible.
And just to be complete, if both were true, you can't really win -- the impact of one of them can't be reduced.
Solution 2
There is no practical difference between the two.
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
I need to run some long and heavy commands but at the same time I'd like to keep my desktop system responsive. Examples: btrfs deduplication, btrfs balance, etc. I don't mind if such commands take longer to finish if I give them a lower priority, but my system should be responsive at all times. Using
nice -n 19
andionice -c 3
should solve my problem, but I'm not sure which command should come first for maximum benefit.Option A:
# nice -n 19 ionice -c 3 btrfs balance start --full-balance /
Option B:
# ionice -c 3 nice -n 19 btrfs balance start --full-balance /
Is there some subtle difference between options A and B? Are they equivalent perhaps?
-
Admin almost 7 yearsIt would only make a difference if
ionice
were very computational, ornice
did lots of I/O. Neither is true. -
Admin almost 7 years@Barmar: If you create an answer based on your comment I'll accept it. Thank you.
-
-
TiberiusKirk over 3 yearsSo what you are saying is in the case of
nice -n 19 ionice ...
nice modifies the priority of ionice; and in the case ofionice -c 3 nice ...
ionice modifies the priority of nice. And in neither case do both commands modify the priorities ofbtrfs balance ...
. I believe the desire is to have both commands affect the niceness ofbtrfs balance ...
. -
Barmar over 3 years@TiberiusKirk The priorities are inherited, so
btrfs balance
gets both priority adjustments. I was only addressing the difference between the order of the two adjustment commands. -
Nabheet about 3 yearsI just read somewhere that nice will also change the IO priority. Does that change this answer in any way?
-
Barmar about 3 years@Nabheet I haven't found that in any of the online man pages. Can you find a reference that confirms that?
-
Nabheet about 3 yearsThe man page for ionice implies that the default io priority is
io_priority = (cpu_nice + 20) / 5
. unix.stackexchange.com/a/153636/134331. linux.die.net/man/1/ionice. I guess maybenice
doesn't change the IO priority, maybe the IO priority automatically changes based on CPU priority? -
Barmar about 3 yearsThat's only the relative priority within the Best Effort I/O priority class.
-
Barmar about 3 years@Nabheet You still have to use
ionice
to select the I/O class.