Respect Linux cgroup CPU number for --threads value (#2083)

We want to respect cgroup constraints so that when we run in a container, we respect the limits set for the container rather than use the host OS's number of cores.

We check both `/sys/fs/cgroup/cpuset.cpus.effective` (`cgroup v2`) and `/sys/fs/cgroup/cpuset.cpus` (`cgroup v1`) to find the number of cores available. We also check `sys/fs/cgroup/cpu.max` (v1, v2) to calculate the number of cores from the limits set in this file.

The max threads value is set to the minimum of these values, and if no values were found in these files, we default to the original value of the host OS.
This commit is contained in:
Angela P Wen 2024-01-23 06:50:06 -08:00 committed by GitHub
parent 2eaf0149ef
commit 65c74964a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 153 additions and 4 deletions

View file

@ -6,7 +6,7 @@ Note that the only difference between `v2` and `v3` of the CodeQL Action is the
## [UNRELEASED]
No user facing changes.
- On Linux, the maximum possible value for the `--threads` option now respects the CPU count as specified in `cgroup` files to more accurately reflect the number of available cores when running in containers.
## 3.23.1 - 17 Jan 2024