GeezerVison is showing github.com — Respect Linux `cgroup` CPU number for `--threads` value by angelapwen · Pull Request #2083 · github/codeql-action
Conversation
angelapwen
commented
Jan 12, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Merge / deployment checklist
- Confirm this change is backwards compatible with existing workflows.
- Confirm the readme has been updated if necessary.
- Confirm the changelog has been updated if necessary.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
We want to respect `cgroup` constraints so that when we run in a container, the default max threads value is appropriately set to the maximum number of cores in this container rather than the host OS's.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! A couple of comments:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
}
|
|
|
|
|
|
const cpuMaxString = fs.readFileSync(cpuMaxFile, "utf-8");
|
|
|
const cpuLimit = cpuMaxString.split(" ")[0];
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: log a warning and return undefined if there are more than two values
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
angelapwen reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I logged as a debug message rather than warning because I don't think the user necessarily needs to be warned in this case.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+458
to
+459
|
|
const cpuStartIndex = parseInt(token.charAt(0));
|
|
|
const cpuEndIndex = parseInt(token.charAt(2));
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider splitting by - in case we have a range like 0-15
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
angelapwen reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
maxThreadsCandidates.push(
|
|
|
...["/sys/fs/cgroup/cpuset.cpus.effective", "/sys/fs/cgroup/cpuset.cpus"]
|
|
|
.map((file) => getCgroupCpuCountFromCpus(file, logger))
|
|
|
.filter((count) => count !== undefined && count > 0)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to record my understanding, this will filter out any NaNs we get since NaN is not greater than 0.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
angelapwen reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jan 26, 2024
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|