GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Respect Linux `cgroup` CPU number for `--threads` value by angelapwen · Pull Request #2083 · github/codeql-action

Conversation

@angelapwen

@angelapwen angelapwen commented Jan 12, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@angelapwen
angelapwen force-pushed the use-cgroup-for-threads branch from 9ce1146 to 744f969 Compare January 12, 2024 23:13
@angelapwen
angelapwen force-pushed the use-cgroup-for-threads branch 2 times, most recently from d93d38b to 75788e9 Compare January 22, 2024 12:58
@angelapwen
Respect Linux cgroup CPU number for --threads value
b0e35ba
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
angelapwen force-pushed the use-cgroup-for-threads branch from 75788e9 to b0e35ba Compare January 22, 2024 13:01
angelapwen added 2 commits January 22, 2024 14:01
@angelapwen
Merge remote-tracking branch 'upstream' into use-cgroup-for-threads
354aec0
@angelapwen
Add changenote
dd78af3
@angelapwen
angelapwen marked this pull request as ready for review January 22, 2024 13:11
@angelapwen
angelapwen requested a review from a team as a code owner January 22, 2024 13:11
@angelapwen
Also respect limit from cgroup/cpu.max
ef58de3
henrymercer
henrymercer reviewed Jan 23, 2024
View reviewed changes

@henrymercer henrymercer left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread src/util.ts Outdated
}

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

@henrymercer henrymercer Jan 23, 2024

Copy link
Copy Markdown
Contributor

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
All reactions
  • 👍 1 reaction

@angelapwen angelapwen Jan 23, 2024

Copy link
Copy Markdown
Contributor Author

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.

All reactions
Comment thread src/util.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

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

@henrymercer henrymercer Jan 23, 2024

Copy link
Copy Markdown
Contributor

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
All reactions
  • 👍 1 reaction

@angelapwen angelapwen Jan 23, 2024

Copy link
Copy Markdown
Contributor Author

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! Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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)

@henrymercer henrymercer Jan 23, 2024

Copy link
Copy Markdown
Contributor

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
All reactions
  • 👍 1 reaction
@angelapwen
Allow for multi-digit core indices
4acf5be
henrymercer
henrymercer approved these changes Jan 23, 2024
View reviewed changes

@henrymercer henrymercer left a comment

Copy link
Copy Markdown
Contributor

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.

Looks good, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@angelapwen
angelapwen enabled auto-merge (squash) January 23, 2024 14:37
@angelapwen
angelapwen merged commit 65c7496 into github:main Jan 23, 2024
@angelapwen
angelapwen deleted the use-cgroup-for-threads branch January 23, 2024 14:56
This was referenced Jan 26, 2024
Merge main into releases/v3 #2099
Merged
Merge releases/v3 into releases/v2 #2102
Merged
@thomas-koppera-keenfinity thomas-koppera-keenfinity mentioned this pull request Feb 14, 2024
Executing the CodeQL GitHub Action within a Docker container results in the detection of only a single CPU, due to the /sys/fs/cgroup/cpuset.cpus file being empty. #2139
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@henrymercer henrymercer henrymercer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@angelapwen @henrymercer
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.