Closed trallnag closed 1 week ago
@trallnag Can you please confirm that /sys/fs/cgroup/cpu/cpu.cfs_quota_us
file exists inside your WSL env?
@MaxymVlasov If confirmed, we can additionally check for absence of /proc/sys/fs/binfmt_misc/WSLInterop
file at https://github.com/antonbabenko/pre-commit-terraform/blob/master/hooks/_common.sh#L202 (ref: https://superuser.com/a/1749811/1241314) — this method looks to be in the "full compliance" with the existing check on that line. WDYT?
@trallnag I assume the /proc/sys/fs/binfmt_misc/WSLInterop
file exists on your WSL installation, right?
@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: https://github.com/antonbabenko/pre-commit-terraform/pull/728 — please let me know what do you think. Thanks.
@trallnag do you have /sys/fs/cgroup/cpu.max
in WSL?
If not, please make sure that nproc
exist and provides number >1
If not, try sysctl -n hw.ncpu
, it should provide number > 1
Please let me know if any of them works in WSL.
And if still nothing works - please send ls -a /sys/fs/cgroup/
and ls -a /sys/fs/cgroup/cpu/
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
If not, please make sure that
nproc
exist and provides number >1 If not, trysysctl -n hw.ncpu
, it should provide number > 1Please let me know if any of them works in WSL.
And if still nothing works - please send
ls -a /sys/fs/cgroup/
andls -a /sys/fs/cgroup/cpu/
❯ 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
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 :tada:
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.