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 and ionice -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?

  • 3
    It would only make a difference if ionice were very computational, or nice did lots of I/O. Neither is true. – Barmar Sep 5 '17 at 17:21
  • @Barmar: If you create an answer based on your comment I'll accept it. Thank you. – user22304 Sep 6 '17 at 9:56

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.

  • So what you are saying is in the case of nice -n 19 ionice ... nice modifies the priority of ionice; and in the case of ionice -c 3 nice ... ionice modifies the priority of nice. And in neither case do both commands modify the priorities of btrfs balance .... I believe the desire is to have both commands affect the niceness of btrfs balance .... – TiberiusKirk Dec 25 '20 at 0:49
  • @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. – Barmar Dec 25 '20 at 2:39
  • I just read somewhere that nice will also change the IO priority. Does that change this answer in any way? – Nabheet 2 days ago
  • 1
    That's only the relative priority within the Best Effort I/O priority class. – Barmar yesterday
  • 1
    @Nabheet You still have to use ionice to select the I/O class. – Barmar yesterday

There is no practical difference between the two.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy