Cannot prioritize processes in Ubuntu 12.04 - niceness level has no effect

Asked by Roman

I cannot control the process scheduling priority by means of setting its nice level.
I can set any niceness I wish, and it is recorded correctly in the process table after that,
but it just has no real effect.
At the moment, for example, I have six processes running on two cpu cores, and all of
them get equal cpu resources (33% of a single CPU). I would like to distribute the CPU time
in an unequal manner between these tasks, but I cannot do so because setting lower or higher
priority to any of them have absolutely no effect.

What might be wrong? I even have no idea where to dig. I have never seen such behaviour
previously. Apparently this issue appeared first in the Ubuntu 12.04. Seemingly, this issue
appears only on multi-core cpus, while my old single-core laptop schedules my tasks
normally.

I normally run the kernel with the option "noautogroup" (I never liked this autogrouping
scheduler feature, because it leaded to a similar problem), and restoring this option via
"sysctl -w kernel.sched_child_runs_first=1" did not change anything.
Maybe the kernel of Ubuntu 12.04 was also equipped by some new scheduling feature
that must be turned off?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu nice Edit question
Assignee:
No assignee Edit question
Solved by:
Roman
Solved:
Last query:
Last reply:
Revision history for this message
Roman (m01brv) said :
#1

Ohm, sorry, I mean that I used the command "sysctl -w kernel.sched_autogroup_enabled=1", not "kernel.sched_child_runs_first=1", to restore the autogroup scheduling option. But this option
seems not responsible for the issue.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

If you run:

nice --19 gedit

Do you notice other apps now run slowly?

Revision history for this message
Roman (m01brv) said :
#3

I am not sure about gedit, since it launches quickly, and I have no chance to catch any difference. But I have wrote a simple test in C with an infinite loop, and I noted that running it with negative niceness makes other my processes run slowly indeed.

After some more thinking, I guessed that this unusual behaviour might be because my tasks that I tried to set to low priority are all multi-threaded. Each has a main thread and two spawned threads where all computation is done (the main thread only waits while others complete their job). It seems as if setting these processes to low priority affects only the main thread, which is anyway waiting, while the other two threads, where all stuff is executed, do not get reniced and remain at their old (zero) niceness.

It seems that for multi-threaded processes this should be expected behaviour, I just did not expect it. I checked that renicing of the usual single-thread processes is working in the usual way.

Therefore my original question is solved now, thanks for the idea about negative niceness. To renice all threads of a process I use a command like "renice +n -g PGID" (where PGID is the process group ID, taken from "ps -Aj", in practice it is usually equal to the main process PID).