-
-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script _common.sh
fails to detect correct CPU count in WSL (Windows Subsystem for Linux) distro
#727
Comments
@trallnag Can you please confirm that |
@MaxymVlasov If confirmed, we can additionally check for absence of @trallnag I assume the |
@yermulnik both files exist in my WSL distribution (Ubuntu from Microsoft store, no customizations) pringles:~# cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us
-1
root@pringles:~# stat /sys/fs/cgroup/cpu/cpu.cfs_quota_us
File: /sys/fs/cgroup/cpu/cpu.cfs_quota_us
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 0,60 Inode: 10 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-10-25 19:53:10.198506900 +0200
Modify: 2024-10-25 19:53:10.198506900 +0200
Change: 2024-10-25 19:53:10.198506900 +0200
Birth: -
pringles:~# stat /proc/sys/fs/binfmt_misc/WSLInterop
File: /proc/sys/fs/binfmt_misc/WSLInterop
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 0,32 Inode: 18882 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-10-25 19:51:08.700467298 +0200
Modify: 2024-10-25 19:51:08.700467298 +0200
Change: 2024-10-25 19:51:08.700467298 +0200
Birth: - |
@MaxymVlasov I went ahead and created quick PR: #728 — please let me know what do you think. Thanks. |
@trallnag do you have Please let me know if any of them works in WSL. And if still nothing works - please send |
I don't have it: ❯ cat /sys/fs/cgroup/cpu.max
cat: /sys/fs/cgroup/cpu.max: No such file or directory
❯ ls -a /sys/fs/cgroup/
. blkio cpuacct cpuset freezer memory net_cls net_prio pids systemd
.. cpu cpu,cpuacct devices hugetlb misc net_cls,net_prio perf_event rdma unified
❯ ll /sys/fs/cgroup/
Permissions Links Size User Date Modified Name
dr-xr-xr-x 3 - root 2024-10-31 17:46 blkio/
dr-xr-xr-x 11 - root 2024-10-31 17:46 cpu/
drwxr-xr-x 2 - root 2024-10-31 17:46 cpu,cpuacct/
dr-xr-xr-x 6 - root 2024-10-31 17:46 cpuacct/
dr-xr-xr-x 6 - root 2024-10-31 17:46 cpuset/
dr-xr-xr-x 14 - root 2024-10-31 17:46 devices/
dr-xr-xr-x 7 - root 2024-10-31 17:46 freezer/
dr-xr-xr-x 6 - root 2024-10-31 17:46 hugetlb/
dr-xr-xr-x 14 - root 2024-10-31 17:46 memory/
dr-xr-xr-x 6 - root 2024-10-31 17:46 misc/
dr-xr-xr-x 6 - root 2024-10-31 17:46 net_cls/
drwxr-xr-x 2 - root 2024-10-31 17:46 net_cls,net_prio/
dr-xr-xr-x 6 - root 2024-10-31 17:46 net_prio/
dr-xr-xr-x 6 - root 2024-10-31 17:46 perf_event/
dr-xr-xr-x 14 - root 2024-10-31 17:46 pids/
dr-xr-xr-x 6 - root 2024-10-31 17:46 rdma/
dr-xr-xr-x 14 - root 2024-10-31 17:46 systemd/
dr-xr-xr-x 16 - root 2024-10-31 17:46 unified/ Note that I don't have configured a processor limit for WSL, something which is supported: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#main-wsl-settings. Out of curiosity I just configured a limit, but the mentioned file still does not appear. But the limit definitly is applied: ❯ getconf _NPROCESSORS_ONLN
4 Without limit: ❯ getconf _NPROCESSORS_ONLN
16 |
I edited my msg a few times, you probably missed the final revision. Can you please also
|
❯ nproc
16
❯ sysctl -n hw.ncpu
sysctl: cannot stat /proc/sys/hw/ncpu: No such file or directory
❯ ls -a /sys/fs/cgroup/
. blkio cpuacct cpuset freezer memory net_cls net_prio pids systemd
.. cpu cpu,cpuacct devices hugetlb misc net_cls,net_prio perf_event rdma unified
❯ ls -a /sys/fs/cgroup/cpu/
. cgroup.procs cpu.cfs_period_us cpu.rt_period_us cpu.stat tasks
.. cgroup.sane_behavior cpu.cfs_quota_us cpu.rt_runtime_us notify_on_release
cgroup.clone_children cpu.cfs_burst_us cpu.idle cpu.shares release_agent |
super, thank you. George fix should works for you, I'll edit a clarification comment, but you already can try it by - repo: https://github.com/antonbabenko/pre-commit-terraform
rev: 040b9771f828d52e14eff80c47b747b92db77579 |
Thanks, I will try later today and report back |
Perfect. Keep us posted. Once you confirm the fix works for you, we'll merge it to default branch. |
Can confirm that it works fine with the mentioned revision: ❯ task format
...
[INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
...
Terraform fmt............................................................Failed
- hook id: terraform_fmt
- files were modified by this hook
route53.tf
route53.tf
... |
This issue has been resolved in version 1.96.2 🎉 |
Describe the bug
The script
_common.sh
fails to detect correct CPU count in WSL distributions.How can we reproduce it?
Export the following two functions from the mentioned script:
common::get_cpu_num
common::colorify
Run
common::get_cpu_num
You will see this output:
This is wrong. This snippet from get_cpu_num shows the correct CPU count:
But the script never reaches this point, because
exists (and it contains -1).
So the problem is that the hook is not running inside K8s pod or inside DinD but inside WSL. It is possible to set CPU limits for WSL. But by default WSL is allowed to use all available CPUs with no limit.
Environment information
Hook version is v4.6.0
Thanks for the hooks.
The text was updated successfully, but these errors were encountered: