Skip to content

Fix Linux VRAM reporting the PCI aperture size instead of the card's memory - #3573

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
Krillsson:fix/more-correct-vramtotal
Aug 3, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
Krillsson:fix/more-correct-vramtotal

Conversation

@Krillsson

@Krillsson Krillsson commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

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.queryLspciMemorySize calculates VRAM by summing the prefetchable PCI BAR sizes from lspci -v:

if (mem.contains(" prefetchable")) {
    vram += ParseUtil.parseLspciMemorySize(mem);
}

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. nvmlDeviceGetMemoryInfo fills total, free and used, and readVramUsed was reading used and discarding the rest. This adds getVramTotal to both NVML bindings and has LinuxGraphicsCardJNA/LinuxGraphicsCardFFM prefer 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.total reports 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 LinuxGraphicsCardFFM so 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

    • Improved Linux graphics card VRAM reporting using the GPU’s reported total memory.
    • Added consistent VRAM detection across supported native access modes.
    • Preserved existing VRAM values when a valid GPU memory reading is unavailable.
  • Documentation

    • Added release notes documenting improved Linux VRAM reporting in version 7.4.4.

Copilot AI review requested due to automatic review settings August 3, 2026 20:34
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b29cf2d2-6e3b-4117-9be6-42deac735d67

📥 Commits

Reviewing files that changed from the base of the PR and between 28ea661 and daaea5d.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • CHANGELOG.md
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)

📝 Walkthrough

Walkthrough

Linux 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.

Changes

NVML VRAM reporting

Layer / File(s) Summary
NVML VRAM query APIs
oshi-core-ffm/.../NvmlUtilFFM.java, oshi-core/.../NvmlUtilJNA.java
Both implementations read total VRAM from NVML and expose getVramTotal, returning -1L on failure.
Linux graphics-card VRAM wiring
oshi-core-ffm/.../LinuxGraphicsCardFFM.java, oshi-core/.../LinuxGraphicsCardJNA.java
Both Linux graphics-card implementations query NVML by PCI bus ID and fall back to the existing VRAM value when the result is not positive.
Release note
CHANGELOG.md
The changelog records Linux VRAM reporting through NVML instead of summing prefetchable PCI BARs.

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
Loading

Possibly related PRs

  • oshi/oshi#3139: Extended the NVML and Linux graphics-card implementations introduced by this change.
  • oshi/oshi#3542: Refactored the shared NVML query infrastructure used by the new APIs.
  • oshi/oshi#3555: Modified PCI-based Linux graphics-card VRAM lookup.

Suggested reviewers: copilot

Poem

A rabbit checked VRAM with care,
FFM and JNA queried there.
NVML gave the size,
Or fallback supplied the prize,
Linux cards now report fair.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: correcting Linux VRAM reporting to use the card's memory instead of the PCI aperture size.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.83%. Comparing base (0f48066) to head (daaea5d).

Files with missing lines Patch % Lines
.../hardware/platform/linux/LinuxGraphicsCardFFM.java 25.00% 3 Missing ⚠️
.../hardware/platform/linux/LinuxGraphicsCardJNA.java 25.00% 3 Missing ⚠️
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     
Flag Coverage Δ
linux 37.20% <25.00%> (-0.02%) ⬇️
macos 38.15% <0.00%> (-0.05%) ⬇️
windows 44.97% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@dbwiddis
dbwiddis force-pushed the fix/more-correct-vramtotal branch from 28ea661 to daaea5d Compare August 3, 2026 21:52
Copilot AI review requested due to automatic review settings August 3, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@dbwiddis

dbwiddis commented Aug 3, 2026

Copy link
Copy Markdown
Member

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:

  • applied spotless formatting
  • reordered used/total for consistency

Otherwise this matches your contribution. Merging. I'll probably cut a release this weekend, unless you prefer otherwise.

@dbwiddis
dbwiddis merged commit 0483b4d into oshi:master Aug 3, 2026
16 checks passed
dbwiddis added a commit that referenced this pull request Aug 4, 2026
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.
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 participants