2

The Linux kernel implements two separate priority ranges. The first is the nice value, a number from –20 to +19 with a default of 0.

Nice values are the standard priority range used in all Unix systems, although different Unix systems apply them in different ways.

What I want to know is with which parameters is calculated the nice value to be assigned after the process.

Thanks for your time.

0

There is no a silver formula which tells you exactly the numbers behind. It all depends on particular implementation on kernel scheduler side.

If you're interested in details, you can check priority logic of default Linux kernel scheduler (Completely Fair Scheduler) e.g. here.

Copy-paste-for-the-future-visitors (in case the link will expire after a few years):

Priorities

Every process has two priorities associated with it. One is called as nice value of process. It ranges from -20 to 19, default being 0. Lower the nice value, higher the priority. If there are two processes having nice value as 5 (process 1)and 10 (process 2), process 1 has high priority.

We can check nice values of process’s nice values using ps -el command on shell. In Kernel space it is translated as MAX_RT_PRIORITY + 20 + nice value. It is stored in static_prio field of the task_struct.

Second priority is real-time priority. These have opposite notion, means higher the value, higher the priority of the process. It ranges from 0 to 100.

There is one more field which is present in task_struct called as prio, which in turn stores the effective priority of process which is being considered by scheduler to boost or thwart priority in order to avoid cases like priority inversion.

In earlier schedulers priority values were used in decided the next process and the time slice it gets on the processor. There were many short-comings in that approach , very well described in book “Linux Kernel Development” by Robet Love.

In CFS, instead of using priorities to decide absolute time a process gets on processor, portion of processor time a process ought to get on processor was calculated, based on the overall load of the system. If a process is getting less than what it should get, it will eventually move towards the left side of RB tree and get the processor time.

  • 1
    Do you have a license to copy-paste that content? – Stephen Kitt Apr 11 at 13:37
  • Thank you very much, but I think that at the kernel level there is a function that calculates this value, right? – Luigi Capogrosso Apr 11 at 13:49

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.