Understanding renice

落花浮王杯 提交于 2019-12-01 11:42:58

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/22090126/understanding-renice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!