Skip to content

fix(agent): prevent memory/swap uint64 underflow causing unrealistic usage spikes#1978

Open
svenvg93 wants to merge 1 commit intohenrygd:mainfrom
svenvg93:1975-mem-spike-fix
Open

fix(agent): prevent memory/swap uint64 underflow causing unrealistic usage spikes#1978
svenvg93 wants to merge 1 commit intohenrygd:mainfrom
svenvg93:1975-mem-spike-fix

Conversation

@svenvg93
Copy link
Copy Markdown
Collaborator

@svenvg93 svenvg93 commented May 4, 2026

📃 Description

Fix uint64 integer underflow in memory and swap stat collection that could cause anomalous spikes (millions of TB) in reported memory usage. When /proc/meminfo values are transiently inconsistent, gopsutil can return a Used value greater than Total, or Shared can exceed Cached + Buffers, both of which cause unsigned integer wraparound to near-MaxUint64.

fixes #1975

🪵 Changelog

🔧 Fixed

  • Skip memory sample entirely when v.Used > v.Total to prevent transient /proc/meminfo inconsistencies from producing unrealistic memory usage spikes
  • Fix uint64 underflow in cacheBuff calculation (Cached + Buffers - Shared) which could wrap to ~18 exabytes when Shared > Cached + Buffers; also removed the dead <= 0 guard that could never trigger on a uint64
  • Fix uint64 underflow in SwapUsed calculation by guarding the subtraction before performing it

@svenvg93 svenvg93 requested a review from henrygd as a code owner May 4, 2026 16:18
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.

[Bug]: Unexpected Memory Usage Spike Showing Unrealistic Values (Millions of TB)

1 participant