Skip to content

Show CPU usage against the current allocation - #34

Merged
feinburger244 merged 2 commits into
mainfrom
fix/12-cgroup-cpu-usage
Nov 2, 2026
Merged

feinburger244 merged 2 commits into
mainfrom
fix/12-cgroup-cpu-usage

Conversation

@llllrui

@llllrui llllrui commented Oct 13, 2026 •

Copy link
Copy Markdown

Description

Resolves #12. quota cpu reports usage against the current allocation, such as Using 1.9 of 3 CPUs, instead of host-wide per-core percentages. It samples for two seconds and reports cumulative and in-sample throttling for finite caps.

Login sessions select the tightest finite cap up to their user-slice boundary. Host Slurm jobs use node-local, job-wide usage and the smaller of their effective cpuset and finite CPU cap. Scope comes from the shared cgroup locator, independently of Slurm environment variables.

Targets main following the merge of #37; #35 remains based on this branch. Fixup 3c0ce59 removes unused indirect dependencies, the outdated operator-facing README paragraph, and redundant comments. It does not change CPU reporting behavior. The task/cgroup and ConstrainCores=yes prerequisite is recorded in 5ebb81a.

Testing

On 3c0ce59, Go 1.24.4 / macOS arm64: uncached full and race tests, go vet, native and Linux amd64 builds, formatting, diff checks, and go mod tidy -diff passed.

The review of 5ebb81a reports correct allocations on both login nodes, in a 2-CPU srun job, and from an salloc shell remaining on a login node. This fixup has not been deployed; multi-node and container behavior remain unverified.

Separate limitation found during self-review: an isolated fixture with a nested, delegated user-9999.slice selects its 4-CPU cap instead of the enclosing user's 1-CPU cap. This comes from the existing shared locator and is unchanged by this fixup; live reproduction and a separate correction remain pending.

Checklist

Comment thread internal/quota/cpu.go Resolved
Comment thread internal/quota/cpu.go Resolved
Comment thread internal/quota/cpu.go Resolved
Comment thread internal/quota/cgroup.go Resolved
Comment thread internal/quota/cpu.go Resolved
Comment thread internal/quota/cpu.go Resolved
Comment thread internal/quota/cpu.go Resolved
Comment thread internal/quota/cgroup.go Resolved
@llllrui
llllrui changed the base branch from main to refactor/shared-cgroup-locator October 22, 2026 19:42
@llllrui
llllrui requested a review from feinburger244 October 22, 2026 19:47
feinburger244 added a commit that referenced this pull request Oct 30, 2026
Quota commands get the job cgroup or the login search list from one call,
and cgroupAncestors reads /proc/self/cgroup itself, so the walk can no
longer receive an unvalidated path.

After the #34 review removed cgroupAncestors' duplicate ".." check, the
walk stopped only if callers validated first. For a path above the root,
such as "/../x", filepath.Dir reaches "/" without ever equaling the root,
and the loop appends until the process runs out of memory.

Ruled out:
- Restoring the parent == current guard. It can't trigger once the walk
  validates its own input.
- Having findSlurmJobCgroup call cgroupAncestors. Login scope selection
  also needs the ancestor list, so callers would read /proc/self/cgroup
  twice.

#34 and #35 call currentCgroupScope from selectCPUContext and
selectMemoryContext.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@feinburger244
feinburger244 force-pushed the refactor/shared-cgroup-locator branch from db15fe2 to 38ab020 Compare October 30, 2026 17:35
quota cpu reports CPUs in use against the Slurm job's or login session's
allocation, e.g. "Using 1.9 of 3 CPUs". It replaces host-wide per-core
percentages, which count every job on the node.

Usage is the cgroup's cpu.stat usage_usec sampled over two seconds.

A job's allocation is its effective cpuset, capped by a finite cpu.max.
SLURM_CPUS_ON_NODE and scontrol are not consulted. This relies on
ConstrainCores=yes (infra-config #5956); jobs started before that keep
their old cpusets, which may cover the whole node.

A login allocation is the tightest finite cpu.max up to user-<uid>.slice.
On equal caps the broader cgroup wins, so usage covers all work sharing the
cap. Throttling is read from the cumulative cpu.stat counters, so earlier
throttling still shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@feinburger244
feinburger244 force-pushed the fix/12-cgroup-cpu-usage branch from b8ac7b8 to 5ebb81a Compare October 30, 2026 18:44
@feinburger244
feinburger244 changed the base branch from refactor/shared-cgroup-locator to main October 30, 2026 18:47
@feinburger244

Copy link
Copy Markdown
Contributor

@llllrui After #37 merged I rebased #34 and #35 onto main and force-pushed them, which replaced your merge commits. Please make sure your local branch is up to date.

Rebase onto master over merge master in is the convention.

@feinburger244 feinburger244 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.

I ran this commit on

  1. both login nodes (idle, and with two busy loops under the 1-CPU cap)
  2. in a 2-CPU srun job with three busy loops
  3. from an salloc shell that stays on the login node.
    All reported the right allocation.

Three small things before I approve:

  • Use go mod tidy to drop four indirect dependencies that only gopsutil's cpu package needed: lufia/plan9stats, shoenig/go-m1cpu, tklauser/go-sysconf and tklauser/numcpus.
  • The description still says this targets refactor/shared-cgroup-locator and points to b8ac7b8, which is gone after the rebase. Could you refresh it?
  • The README paragraph below.

Please push these as --fixup=5ebb81a commits.

Comment thread README.md Resolved
Comment thread internal/quota/cpu_cgroup.go Resolved
Remove the CPU-only indirect modules left behind after quota cpu stopped using gopsutil/cpu. Refresh the user-facing README and trim comments requested during review; quota behavior is unchanged. The task/cgroup and ConstrainCores prerequisites remain recorded in the target commit.
@feinburger244
feinburger244 merged commit 164f1ab into main Nov 2, 2026
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.

[#3] quota cpu: show CPUs in use against the allocation

2 participants