0

In one of my Linux experiments, I occasionally found that my WSL system gives a default nice value of 5, rather than what everybody says, 0 by default.

Here's how I find the default nice value:

First, make an infinite loop process to take up all CPU time:

while True:
    pass
python3 ./loop.py &

Second, check out the time usage of this process by the sar command:

sar -P ALL 1 1

And we got:

sar -P ALL 1 1

Output:

Linux 5.15.90.1-microsoft-standard-WSL2 (DESKTOP-50KS4PV)       08/31/23        _x86_64_        (16 CPU)
20:31:21        CPU     %user     %nice   %system   %iowait    %steal     %idle
20:31:22        all      0.37      6.23      0.00      0.00      0.00     93.40
...
20:31:22         10      0.00    100.00      0.00      0.00      0.00      0.00
20:31:22         11      0.99      0.00      0.00      0.00      0.00     99.01
...

Here, I find %nice is recorded rather than %user, meaning that the command python ./loop.py has some kind of niceness without specifying(?).

Another top command confirmed my assumption:

top - 20:33:19 up  1:04,  0 users,  load average: 0.89, 0.64, 0.90
Tasks:  24 total,   2 running,  21 sleeping,   0 stopped,   1 zombie
%Cpu(s):  0.1 us,  0.1 sy,  6.2 ni, 93.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   7834.3 total,    574.9 free,   1606.9 used,   5652.5 buff/cache
MiB Swap:   2048.0 total,   2046.2 free,      1.8 used.   5928.2 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 9682 gorun     25   5   15828   9044   5700 R 100.0   0.1   2:01.38 python
...

We found that python has 5 niceness rather than 0.


Additionally, I've checked out /etc/security/limits.conf, and that file contains nothing but # leading comments. And, I've checked out the Advanced Settings section of the Microsoft WSL manual, and found nothing related to the default nice value.

How can I set the default niceness value back to 0, and why does Microsoft make such a decision of setting an irregular default 'nice' value?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gorun
  • 134
  • 6
  • 1
    A really good question, albeit *probably* just slightly off topic. If you are running Ubuntu, I'd recommend reposting this on [Ask Ubuntu](//askubuntu.com) (and make it clear that you are on Ubuntu). Otherwise, consider [Unix & Linux](//unix.stackexchange.com) or [Super User](//superuser.com). I don't have an answer for you at the moment, but I'll try to keep an eye out there. – NotTheDr01ds Sep 01 '23 at 12:45
  • I cannot reproduce. It is odd to jump to conclusions and blame so fast after only observing the behavior. There are so many elements. What is the niceness of your shell? What is the niceness of any python program? What is the niceness in ps output? Finally, why _exactly_ do _you_ think microsoft _has made_ such behavior? – KamilCuk Sep 01 '23 at 13:51
  • @KamilCuk Thanks for your guide! Before I came across this comment, I thought the only way to change niceness of a process is using `nice` or `renice` command. Your comment bring me more information that other things exists in terms of default niceness value. Also, I'm lack of more investigation, and omit more things in my question such as `top` command's output, making things more confusing. I will try to be better next time, thanks for your generious guide. – Gorun Sep 02 '23 at 05:31
  • @KamilCuk After more experiment, I use another WSL installation, and find the source of this problem: when I'm using default `bash` shell, the default nice value = 0. But when I'm using `zsh` shell, the shell I'm using in this question, the default nice value = 5. In this comparison, I believe that `zsh` is the source of the problem. – Gorun Sep 02 '23 at 05:35
  • @NotTheDr01ds Thanks for your generious guide! See the comment below to find my answer. – Gorun Sep 02 '23 at 05:36

0 Answers0