Repository navigation
Report real GPU memory on NVIDIA unified memory platforms - #511
Merged
Merged
Conversation
The unified-memory path summed the running processes' GPU allocations inline and reported total = used + MemAvailable. That duplicated the generic summation already performed in gpuinfo_fix_dynamic_info_from_process_info() (and did it worse: it missed MPS processes and had no guard against NVML_VALUE_NOT_AVAILABLE), while also redefining total_memory as a moving quantity rather than the system capacity. Report total = MemTotal (same as every other backend) and free = MemAvailable, and let the generic pass sum the process allocations into used_memory. The remaining used + free != total residual is host (non-GPU) residency, which the old code wrongly reported as GPU memory. Record the existing unified-memory detection in static_info.memory_shared_with_host so the generic pass can tell such devices apart. For those it initializes used to 0 so an idle device reports 0 rather than unknown, and derives mem_util_rate for the graph from the reconstructed sum. Devices that do not set the flag are unaffected, including those that leave used unset for other reasons (e.g. Apple without per-process accounting). This removes sum_process_gpu_memory() entirely.
Syllo
force-pushed
the
fix/uma-gpu-memory-reporting
branch
from
September 27, 2026 21:51
339b7e6 to
5d164b8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The problem
On UMA platforms such as DGX Spark, NVML returns
NVML_ERROR_NOT_SUPPORTEDfor the framebuffer query, so nvtop falls back to the Linux system memory counters. The current fallback inset_unified_system_memory_info()reports:Those describe the host, not the GPU. Measured on a DGX Spark (GB10, 121.690 GiB unified):
In the first case the GPU has nothing on it at all. In the second, nvtop overstates by more than 9 GiB of unrelated host consumption. The total also never moves off
MemTotal, so the headroom figure ignores everything else on the machine.This is the regression described in #449.
Reproducing without a DGX Spark
This needs no GPU workload. On any machine nvtop treats as unified memory, allocate and touch host memory:
The reported GPU used memory climbs with host consumption while the GPU stays idle.
The fix
NVML does report per-process allocations on these platforms even though it does not report a framebuffer size. Sum the compute and graphics allocations for the device and use that as the used memory, then report total as that sum plus
MemAvailable, which is the memory the GPU can actually reach.MemAvailablealone becomes the free memory.The change is confined to the existing
if (has_unified_memory)branch. The dedicated framebuffer path is untouched.Verification
Same Spark, model resident, reading NVML immediately before and after each nvtop sample:
Also checked:
One note for review
The helper enumerates processes a second time per refresh. nvtop's order is
refresh_dynamic_info, thenget_running_processes, thenfix_dynamic_info_from_process_info, and this code runs in the first phase, before the process list exists.A tighter version would set only
free_memoryhere and letfix_dynamic_info_from_process_infocompute used from the already collected processes. That needs the sharedneedGPUMemorycondition inextract_gpuinfo.cto stop requiring a validtotal_memoryfirst, which affects every vendor, so I kept this patch self contained. Happy to do it that way instead if you prefer.Fixes #449