Add a shared malloc_trim helper to datadog_checks_base #25718
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.43) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 355 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.351
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #25718"
general
weight: 0.35
iliakur
What does this PR do?
malloc_trim()todatadog_checks.base.utils.native_memory, wrapping glibc'smalloc_trim(0)and degrading to a no-op without glibc (macOS, musl, bionic).Motivation
ibm_wasneeds this. In AGENT-17325 a customer saw RSS climb 311 MB -> 3,965 MB over 9 runs parsing a 27.5 MB PerfServlet response into a libxml2 tree. Reproduced in a glibc container, 8 parses each on its own live thread:| Configuration | RSS after 8 runs |
|---|---|
| Today | 416 -> 3,016 MB, linear |
| With
malloc_trim| 45 MB, flat |kafka_consumerhas carried a local copy since #24553. Moved here so other integrations can call it, with one deliberate change —ctypes.CDLL(None)rather thanctypes.util.find_library('c'), which shells out toldconfig, or togccwhere ldconfig is absent, on every import.CDLL(None)resolves from the process-wide namespace, so anLD_PRELOADallocator interposingmalloc_trimwins; intended, and documented in the docstring.Migration plan
The minimum-base-package job installs each integration's declared floor from PyPI, so importing this before a released base contains it fails with
ModuleNotFoundError(reproducible withddev test <target> --compat). Sequence:1. This PR: helper in base, no callers.
2. Release
datadog-checks-base.3. Follow-up: bump the floor in
ibm_wasandkafka_consumer, haveibm_wascallmalloc_trim()in afinallyaround its check, and deletekafka_consumer's copy.Checklist before requesting review
<!--
tests/base/utils/test_native_memory.py: 6 tests covering the no-op contract, the glibc
binding and its pinned c_size_t/c_int signature, both degradation paths (libc absent,
symbol absent), and both branches of the None guard. Verified by mutation: removing the
argtypes/restype pinning, the None guard, or widening the except clause each turn the
suite red. glibc 6 passed; musl 5 passed, 1 skipped.
-->
🤖 Generated with Claude Code