Skip to content

Fix memusage reporting#8494

Open
rljacob wants to merge 3 commits into
masterfrom
rljacob/gptl/fix-memusage
Open

Fix memusage reporting#8494
rljacob wants to merge 3 commits into
masterfrom
rljacob/gptl/fix-memusage

Conversation

@rljacob

@rljacob rljacob commented Jun 17, 2026

Copy link
Copy Markdown
Member

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]

rljacob added 2 commits June 17, 2026 15:07
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)
@rljacob rljacob requested review from amametjanov and jgfouca June 17, 2026 20:14
@rljacob rljacob self-assigned this Jun 17, 2026
@rljacob rljacob added Utils gptl (timer library) The GPTL timer library gptl GPTL Timer library labels Jun 17, 2026
@rljacob rljacob requested a review from Copilot June 17, 2026 20:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_memusage argument types from 32-bit int* to 64-bit
    long long*, and update affected Fortran callers to integer(8).
  • On Linux, parse /proc/<pid>/status (VmHWM/VmRSS, etc.) instead of
    /proc/<pid>/statm, and print results in MB.
  • Ensure HAVE_SLASHPROC is 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.

Comment thread share/timing/CMakeLists.txt Outdated
Comment thread share/timing/GPTLprint_memusage.c
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>
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gptl (timer library) The GPTL timer library gptl GPTL Timer library Utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with memory tracking

3 participants