I have large file I need to mv and even with nice -n19 it seems to affect the server performance.

I think an option would be to run the process in "chunks" whereby I run the command for a few seconds, then sleep for a few, then resume the process.

Is there a way to do this from the command line or a better alternative ? Currently I do a Ctrl Z and fg manually.

  • I'd intuitively say if you resort to such tricks then chances are there is a system parameter somewhere that needs some fixing, cgroups being the first to come to my mind (though I need to figure out how). It might help to inspect what the source of congestion really is. – user86969 Sep 5 '15 at 18:46
  • 1
    If all you do is mv then I believe bottleneck lies in input/output, not processor. In that case you should try ionice, not nice. – jimmij Sep 5 '15 at 18:51
  • Do you really need to move it? Why not ln -s? Much faster. – ott-- Sep 5 '15 at 21:26

Your performance impact is likely caused by a I/O bottleneck because mv does not normally require a lot of CPU cycles (unless encryption/decryption is involved). nice changes the scheduling priority of the task in the task list, which get to run on the CPU.

Therefore, instead of nice, try (for kernel > 2.6.25)

ionice -c3 mv <src> <dest>

From ionice -h

 ionice [options] <command>
   -c, --class <class>    name or number of scheduling class,
                      0: none, 1: realtime, 2: best-effort, 3: idle

From man ionice

 Idle   A program running with idle I/O priority will only get disk time 
        when no other program has asked for disk I/O for a defined grace 
        period.  The impact of an idle I/O process on normal system activity
        should be zero.

Something like:

$command & pid=$!
while kill -STP -$pid && sleep $interval && kill -CONT -$pid && sleep $interval; do :; done

could do it.

Job control is really about sending these two signals (SIGSTP and SIGCONT) so this is basically job control done manually.

  • Depending on the sleep interval and what the process is doing, this can couse problems. For example if a network connection times out. – Thomas Erker Sep 5 '15 at 19:10
  • Ionice is undoubtedly the better solution. This simply gives the OP exactly what he was asking for. – PSkocik Sep 8 '15 at 9:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.