Repository navigation
Fix Linux VRAM reporting the PCI aperture size instead of the card's memory - #3573
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
📜 Recent review details⏰ Context from checks skipped due to timeout. (4)
📝 WalkthroughWalkthroughLinux graphics-card discovery now reads total VRAM from NVML through FFM or JNA. If NVML returns no positive value, discovery retains the existing VRAM value. The changelog records this change. ChangesNVML VRAM reporting
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant LinuxGraphicsCard
participant NvmlUtil
participant NVML
LinuxGraphicsCard->>NvmlUtil: getVramTotal(PCI bus ID)
NvmlUtil->>NVML: Query memory information
NVML-->>NvmlUtil: Total VRAM or failure
NvmlUtil-->>LinuxGraphicsCard: VRAM value
LinuxGraphicsCard->>LinuxGraphicsCard: Use existing VRAM if value is not positive
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3573 +/- ##
============================================
- Coverage 79.90% 79.83% -0.08%
Complexity 76 76
============================================
Files 709 709
Lines 24198 24200 +2
Branches 4047 4049 +2
============================================
- Hits 19336 19319 -17
- Misses 2689 2705 +16
- Partials 2173 2176 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes Linux GPU VRAM reporting by preferring NVML’s nvmlDeviceGetMemoryInfo().total (for NVIDIA GPUs) instead of summing prefetchable PCI BAR apertures from lspci, which can under-report VRAM (e.g., 256 MiB BAR1 cap without Resizable BAR).
Changes:
- Add
getVramTotal()to both NVML bindings (JNA + FFM) to expose total VRAM in bytes. - Update Linux graphics card implementations (JNA + FFM) to use NVML total VRAM when available, falling back to the existing
lspci-derived value otherwise. - Document the user-visible change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.java | Adds NVML-backed total VRAM query method. |
| oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardJNA.java | Uses NVML total VRAM for NVIDIA devices when available. |
| oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java | Mirrors the JNA Linux VRAM behavior for the FFM implementation. |
| oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java | Adds NVML-backed total VRAM query method (FFM). |
| CHANGELOG.md | Adds an entry describing the Linux VRAM reporting fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
28ea661 to
daaea5d
Compare
|
Hey @Krillsson , thanks for the fix! When I added more GPU information I did my best to try to use existing documentation, but didn't have real hardware to test it on. I really appreciate users like you finding (most importantly) and fixing (bonus!) these bugs. I made two minor changes:
Otherwise this matches your contribution. Merging. I'll probably cut a release this weekend, unless you prefer otherwise. |
The monotonic() clamps added in #3574 are read-modify-writes on volatile long fields, which Sonar flags as S3078. The read-modify-write is one of ~20 unsynchronized volatile writes in updateAttributes(); OSProcess documents that concurrent callers must synchronize externally, and both racing writers only ever raise the value, so a lost clamp still yields a real ps reading. Suppress on the two methods rather than convert the shared protected fields to AtomicLong. Also restore ascending PR-number order in the 7.4.4 changelog, where the #3574 squash-merge landed the entry above #3569 and #3573.
Hi, its me again. I noticed something strange about my GPU: OSHI says it has of 288 MB VRAM. However my Quadro P400 card has 2GB? So I started digging:
LinuxGraphicsCard.queryLspciMemorySizecalculates VRAM by summing the prefetchable PCI BAR sizes fromlspci -v:While working on this I learned what PCI BAR is;
Those are the address windows the CPU uses to reach the card, not a measure of its memory. Without Resizable BAR, BAR1 is capped at 256 MiB no matter how much memory is on the board, so the P400 comes out as 256 MiB + 32 MiB = 288 MiB on my machine.
NVML is already available in the project and it has the actual number.
nvmlDeviceGetMemoryInfofillstotal,freeandused, andreadVramUsedwas readingusedand discarding the rest. This addsgetVramTotalto both NVML bindings and hasLinuxGraphicsCardJNA/LinuxGraphicsCardFFMprefer it, falling back to the lspci sum when NVML has no answer for a card on non-NVIDIA cards.Verified on my server with a Quadro P400
nvidia-smi --query-gpu=memory.totalreports 2048 MB for the same card.I verified both the JNA path and the FFM paths against a local build on that machine: the JNA one through my project, and the FFM one on JDK 25 with a temporary +512 MB bogus addition to
LinuxGraphicsCardFFMso the reported value would tell me which code path had actually run. It read 2.5 GB.Note that this only fixes NVIDIA cards, since that's what I have to test on. It might affect AMD and Intel based cars to?
Summary by CodeRabbit
Bug Fixes
Documentation