Question

I'm trying to give an CPU-bound application the lowest scheduling priority with renice 19 (Linux 3.11). However, it doesn't seem to work as expected or I have an understanding problem.

Let me describe two ways how I've tried it. I expected that in both ways I'd get the same results, but I don't. Consider the application loop to be a busy loop: int main() { for(;;) ; return 0; }.

Experiment 1

  • opened a terminal
  • ran ./loop & as many times as CPUs (eg, I have 4 CPUs).
  • ran a further instance of loop and reniced it to 19

Result was as expected. The non-reniced loop instances have almost 100% CPU each, and the reniced instance has about 1%.

Experiment 2

  • opened two terminals
  • Terminal 1: ran ./loop & as many times as CPUs.
  • Terminal 2: ran a further instance of loop and renice it to 19

Result was not as expected. The loop instance started in Terminal 2 had 100% (although with niceness 19), whereas the loop instances in Terminal 1 shared the rest of the resources.

Question

Why does not experiment 2 behave as experiment 1?

Was it helpful?

Solution

You probably have autogroups enabled.

In that case, in experiment 2 at the top level you have 2 control groups (one per session) competing for CPU, and inside each control group processes compete for CPU.

You can see the current control group and its niceness with:

cat /proc/$$/autogroup

And you can set the niceness with:

echo 19 > /proc/$$/autogroup
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top