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?