fix(vGPUmonitor): bound v0 spec metric sums to active proc slots - #2282
Conversation
The v0 shared-region accessors (DeviceMemoryContextSize, ModuleSize, BufferSize, Offset, Total and DeviceSmUtil) iterated over the full procs[1024] array instead of only the live slots bounded by procnum. Slots beyond procnum can retain stale, non-zero data from exited processes, which was summed into the reported per-device memory and SM-utilization metrics and inflated the corresponding vGPUmonitor gauges. Bound every loop to procs[:int(procnum)], mirroring the v1 layout which was already fixed in acc8d91 but never backported to v0. Add regression cases asserting a stale slot beyond procnum is excluded. Fixes Project-HAMi#2281 Signed-off-by: imantaba <itn.taba@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughNVIDIA v0 and v1 specifications now clamp ChangesActive process metric aggregation
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
procnum is read from the mmap'd shared-memory region and may be corrupt (negative or larger than the backing procs array). Slicing it directly would panic with 'slice bounds out of range'. Route both v0 and v1 spec accessors through an activeProcs() helper that clamps procnum into [0, len(procs)] before slicing, and add regression tests covering a negative and an oversized procnum. Signed-off-by: imantaba <itn.taba@gmail.com>
515be96 to
925ab88
Compare
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: archlitchi, imantaba The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
What this PR does / why we need it:
In
pkg/monitor/nvidia/v0/spec.go, the six per-device metric accessors (DeviceMemoryContextSize,DeviceMemoryModuleSize,DeviceMemoryBufferSize,DeviceMemoryOffset,DeviceMemoryTotalandDeviceSmUtil) iterate over the entire fixed-sizeprocs [1024]shrregProcSlotTarray instead of only the live slots bounded byprocnum:procnumis the count of active process slots written bylibvgpu.so. Slots at index>= procnumare not cleared and can retain stale, non-zero values from processes that have exited. Summing over all 1024 slots folds that stale data into the reported per-device memory and SM-utilization totals, inflating the corresponding vGPUmonitor gauges (and in the worst case pushing a value far above the real device usage/limit once a slot beyondprocnumholds leftover data).The v0 layout is reachable:
pkg/monitor/nvidia/cudevshr.goselects it when the shared-region file size is1197897.The v1 layout already bounded these loops to
s.sr.procs[:int(s.sr.procnum)](fixed inacc8d91, #1345) but the fix was never backported to v0. This PR backports it to v0.Changes
activeProcs()helper that clampsprocnuminto[0, len(procs)]before slicing.procnumcomes straight from the mmap'd shared-memory region, so a corrupt value (negative or larger than the backing array) would otherwise panic withslice bounds out of range. This also hardens the pre-existing v1 code, which had the same exposure.procnum(they previously relied on all-zero trailing slots, so they would sumprocs[:0]= 0 once the bound is applied).procnumis excluded from the sum, plus a clamp regression test (negative and oversizedprocnum) for both v0 and v1.Which issue(s) this PR fixes:
Fixes #2281
Special notes for your reviewer:
Verified red→green:
600instead of200; after the fix all pass.activeProcs()slicingprocnumdirectly (no clamp), the clamp test panicsslice bounds out of range [:-5]; with the clamp it passes.go test ./pkg/monitor/nvidia/... -raceandgofmt/go vetare clean.The clamp addresses review feedback on this PR (thanks @mesutoezdil) — folding it in here since it hardens the exact lines this PR touches, and applying it to v1 too keeps both layouts consistent.
This change was prepared with AI assistance (per CONTRIBUTING.md); all changes were reviewed and verified by me.
Does this PR introduce a user-facing change?:
Summary by CodeRabbit
Bug Fixes
Tests