Fix memusage reporting#8494
Open
rljacob wants to merge 3 commits into
Open
Conversation
Memory usage values from /proc can exceed 2 GB, causing integer overflow with 32-bit int. Switch the C API to long long and Fortran callers to integer(8). Also switch from /proc/<pid>/statm (page counts) to /proc/<pid>/status (labeled KB fields) on Linux, reporting VmHWM as "size" instead of VmSize to avoid inflation from GPU BAR mappings and other non-physical reservations.
The CMake build was missing -DHAVE_SLASHPROC, so the GPTL code was falling through to the getrusage path which sets *size = -1 (an int -1)
Contributor
There was a problem hiding this comment.
Pull request overview
Update GPTL-based memory reporting to avoid 32-bit overflows and to use more
meaningful Linux /proc metrics, then propagate the 64-bit API change through
Fortran callers and build configuration.
Changes:
- Switch
GPTLget_memusageargument types from 32-bitint*to 64-bit
long long*, and update affected Fortran callers tointeger(8). - On Linux, parse
/proc/<pid>/status(VmHWM/VmRSS, etc.) instead of
/proc/<pid>/statm, and print results in MB. - Ensure
HAVE_SLASHPROCis defined in the CMake build when appropriate.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| share/util/shr_mem_mod.F90 | Update local memusage variables to 64-bit to prevent overflow and preserve MB conversions. |
| share/timing/GPTLprint_memusage.c | Update printing path to use long long memusage values and MB conversion. |
| share/timing/GPTLget_memusage.c | Change C API to long long* and switch Linux implementation to /proc/<pid>/status parsing. |
| share/timing/gptl.h | Update public prototype for GPTLget_memusage to long long* arguments. |
| share/timing/f_wrappers.c | Update Fortran-callable wrapper prototype/signature for 64-bit memusage arguments. |
| share/timing/CMakeLists.txt | Define HAVE_SLASHPROC in CMake builds when /proc support is detected. |
| components/homme/src/share/compose_test_mod.F90 | Update Homme memusage locals to 64-bit for the new GPTL signature. |
| components/homme/src/preqx/share/prim_state_mod.F90 | Update Homme memusage locals to 64-bit for the new GPTL signature. |
Set HAVE_SLASHPROC if system is Linux which is more robust then checking the path as that may not work in a container. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
jgfouca
approved these changes
Jun 17, 2026
rljacob
added a commit
that referenced
this pull request
Jul 10, 2026
Switch to 64-bit ints and /proc/status and fix build with HAVE_SLASHPROC Memory usage values from /proc can exceed 2 GB, causing integer overflow with 32-bit int. Switch the C API to long long and Fortran callers to integer(8). Also switch from /proc/<pid>/statm (page counts) to /proc/<pid>/status (labeled KB fields) on Linux, reporting VmHWM as "size" instead of VmSize to avoid inflation from GPU BAR mappings and other non-physical reservations. Make sure HAVE_SLASHPROC is defined if available. The CMake build was missing -DHAVE_SLASHPROC, so the GPTL code was falling through to the getrusage path which sets *size = -1 (an int -1) Fixes #8425 [BFB]
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.
Switch to 64-bit ints and /proc/status and fix build with HAVE_SLASHPROC
Memory usage values from /proc can exceed 2 GB, causing integer overflow with 32-bit int. Switch the C API to long
long and Fortran callers to integer(8).
Also switch from
/proc/<pid>/statm(page counts) to /proc/<pid>/status(labeled KB fields) on Linux, reportingVmHWM as "size" instead of VmSize to avoid inflation from GPU BAR mappings and other non-physical reservations.
Make sure HAVE_SLASHPROC is defined if available. The CMake build was missing -DHAVE_SLASHPROC, so the
GPTL code was falling through to the getrusage path which sets *size = -1 (an int -1)
Fixes #8425
[BFB]