5

I recently learned about the nice value of a process. If I am running a user program, should I set the nice value as low as possible and would that make my process run faster?

2 Answers 2

5

Programs that are started usually have a nice-value of zero, i.e. it's not higher or lower than the nice-values of most other processes running on the system. The nice-value modifies the scheduling priority of a process.

Unprivileged users may only specify nice-values that lower the scheduling priority of their own processes (i.e. makes them "nicer").

A process with a higher scheduling priority will not necessarily run faster than it would with a lower scheduling priority, but as the kernel's run queue becomes longer (when many concurrent processes are contesting for CPU time on a busy system) and the load (which is a measure of the length of the run queue) increases, it would have greater chance, compared to other processes in the queue, to get scheduled for execution. It would have the possibility to run more often.

On an otherwise idle system, running a process with high nice-value would be no different from running it with a low nice-value. It would get 100%, or near 100%, of the CPU regardless. It would not run faster or slower.

For an unprivileged user, the nice and renice utilities are utilities for lowering the scheduling priority of one's processes, to be nice to others.

The root user may increase the scheduling priority for a running process, or start processes with an elevated value.

On my (OpenBSD) system, the only process that is running with an elevated scheduling priority is ntpd (the time keeping daemon) and sndiod (the audio/MIDI server on OpenBSD), i.e. processes that needs to be able to run in "real time" or close to it, without having to wait for other processes to do their job.

3
  • It might be useful to mention early in the answer that lowering the nice value corresponds to making the scheduling priority higher. (Unless you did and I missed it.)
    – David Z
    Feb 11, 2018 at 12:44
  • @DavidZ I'm avoiding talking about high or low nice values as these values usually range from -20 to +20, and these modify the priority, which are called "the highest (priority)" (-20) and "the lowest (priority)" (+20), which is confusing. Also a command like nice -5, which some nice implementations allow and which is the same as nice -n 5, confuses the matter further. I have already mentioned that the nice-value modifies scheduling priority, and that the priority only may be lowered (by non-root users).
    – Kusalananda
    Feb 11, 2018 at 12:49
  • Sure, but from the way the OP asked their question, I sense the potential for confusion between the nice value and the scheduling priority. I'm just thinking that the OP or other readers may not realize that these are different things.
    – David Z
    Feb 11, 2018 at 23:00
4

Short answer

You can't (as a normal user), because it is a bad idea.

Long answer

Most of the time it will make no difference (if it is the only process running, or if the total number of threads running is less than number of cpu cores).

When it does make a difference the process will not be nice. It will hog your processor. The computer will start to become unresponsive.

Longer answer:

The only time when it makes sense to reduce nicenese is for real-time processes. That is for processes that need to get things done within a time-frame. These processes need to be written to be nice (not nice). That is to do there job and then give up the processor. You probably don't want to be fiddling with this. It is probably not needed as processes that behave nicely have their dynamic priority increased, anyway. (note there is also real-time priorities (see real time scheduler), that are even more extreme. You probably don't want to touch these ever. Especially on a production system. That is one that is doing something important. )

3
  • When doing real-time work, one should use real-time scheduling. Feb 11, 2018 at 14:14
  • 2
    @JonasWielicki added a note to say that real-time priorities, are part of the real-time scheduler. Feb 11, 2018 at 15:16
  • There are a few things that make use of real time priorities such as audio players. In most cases, this has to do with hardware and execution of code that needs to happen at a precise time. It is certainly used much in embedded systems (although even there, it's often not necessary except for the few parts that drive the hardware in some way). Oct 11, 2021 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .