nice and ionice: which one should come first?

6,670

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.

Share:
6,670

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    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 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?

    • Admin
      Admin almost 7 years
      It would only make a difference if ionice were very computational, or nice did lots of I/O. Neither is true.
    • Admin
      Admin almost 7 years
      @Barmar: If you create an answer based on your comment I'll accept it. Thank you.
  • TiberiusKirk
    TiberiusKirk over 3 years
    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 ....
  • Barmar
    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
    Nabheet about 3 years
    I just read somewhere that nice will also change the IO priority. Does that change this answer in any way?
  • Barmar
    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
    Nabheet about 3 years
    The 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 maybe nice doesn't change the IO priority, maybe the IO priority automatically changes based on CPU priority?
  • Barmar
    Barmar about 3 years
    That's only the relative priority within the Best Effort I/O priority class.
  • Barmar
    Barmar about 3 years
    @Nabheet You still have to use ionice to select the I/O class.