FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Respect Linux `cgroup` CPU number for `--threads` value by angelapwen · Pull Request #2083 · github/codeql-action · GitHub

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

Merged
angelapwen merged 6 commits into
github:mainfrom
angelapwen:use-cgroup-for-threads
Jan 23, 2024
Merged

Respect Linux cgroup CPU number for --threads value#2083
angelapwen merged 6 commits into
github:mainfrom
angelapwen:use-cgroup-for-threads

Conversation

angelapwen commented Jan 12, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

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.

angelapwen force-pushed the use-cgroup-for-threads branch from 9ce1146 to 744f969 Compare January 12, 2024 23:13
angelapwen force-pushed the use-cgroup-for-threads branch 2 times, most recently from d93d38b to 75788e9 Compare January 22, 2024 12:58
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.
angelapwen force-pushed the use-cgroup-for-threads branch from 75788e9 to b0e35ba Compare January 22, 2024 13:01
angelapwen marked this pull request as ready for review January 22, 2024 13:11
angelapwen requested a review from a team as a code owner January 22, 2024 13:11

henrymercer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice! A couple of comments:

Comment thread src/util.ts Outdated
}

const cpuMaxString = fs.readFileSync(cpuMaxFile, "utf-8");
const cpuLimit = cpuMaxString.split(" ")[0];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Optional: log a warning and return undefined if there are more than two values

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Comment thread src/util.ts Outdated
angelapwen force-pushed the use-cgroup-for-threads branch from bf7632c to 8e735f0 Compare January 23, 2024 12:30
Comment thread src/util.ts Outdated
Comment on lines +458 to +459
const cpuStartIndex = parseInt(token.charAt(0));
const cpuEndIndex = parseInt(token.charAt(2));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would consider splitting by - in case we have a range like 0-15

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

👍 done! Thanks!

Comment thread src/util.ts
maxThreadsCandidates.push(
...["/sys/fs/cgroup/cpuset.cpus.effective", "/sys/fs/cgroup/cpuset.cpus"]
.map((file) => getCgroupCpuCountFromCpus(file, logger))
.filter((count) => count !== undefined && count > 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Just to record my understanding, this will filter out any NaNs we get since NaN is not greater than 0.

henrymercer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good, thanks!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL