Skip to content

Add an advisory paired cost estimator for native allocation accounting - #972

Open
jbachorik wants to merge 8 commits into
a1-memory-gate-retrofitfrom
a2-paired-estimator
Open

jbachorik wants to merge 8 commits into
a1-memory-gate-retrofitfrom
a2-paired-estimator

Conversation

@jbachorik

Copy link
Copy Markdown
Collaborator

Summary

Add an advisory, paired same-window cost estimator for the native allocation-accounting layer (NativeMem::recordAlloc/recordFreeBefore → MallocFootprint::overheadOf). Tracker: PROF-16568. Stacked on #971.

The repo has no cost estimate for the accounting layer at all. The research discipline is strict about what such an estimate may look like: unpaired before/after medians cannot resolve ≤10 ns/op effects (~30 % in-window drift), so the only valid shape is a paired, same-window measurement of an identical replayed trace.

What changed

  • New Linux-only executable in ddprof-lib/benchmarks (nativeMemCostEstimator.cpp, estimatorSupport{.h,_linux.cpp}), built with its own object directory and tasks (compileNativeMemEstimator/link/run) at the release flags (-O3 -DNDEBUG -g -std=c++17) so the assert is stripped as in shipped builds. It compiles and links the real ddprof-lib/src/main/cpp/nativeMem.cpp — the accounting functions are never copied or reimplemented. The unwind benchmark is untouched.
  • Trace: seeded (std::mt19937_64 raw output, no distributions), balanced (every allocation freed), sizes below the 128 KiB mmap threshold, 64-bit hash asserted. Pair order comes from a second recorded seed (AB/BA).
  • Modes: A (malloc/free, no accounting), B (A + the real recordAlloc/recordFreeBefore on NM_MISC with reset() between replays), I (A + a calibrated per-op spin) for the self-test.
  • Report: median paired delta (ns/op) with a seeded deterministic bootstrap 95 % CI and an exact two-sided sign-test p; A–A noise floor median + CI; I–A median + CI with the injected magnitude; pair count, op count, trace hash, both seeds, libc name/version (glibc via gnu_get_libc_version, musl via the loader banner or NA), build flags, per-window markers: records in the A1 format.
  • Integrity: the B-mode accounting call count must equal the op count and NativeMem::max(cat) > 0 per replay, else non-zero exit.
  • Advisory, deliberately: exits non-zero only on hash mismatch, reached-call mismatch, self-test failure (I–A CI includes 0, or A–A CI excludes 0) or invalid usage — never on the size of an estimate. No numeric threshold exists anywhere, and nothing is wired into a blocking CI job. The injected-magnitude containment is a reported calibration field (ia_ci_contains_magnitude=), not a gate: a 95 % CI misses the true magnitude ~5 % of runs by construction.
  • verifyNativeMemEstimator (Gradle, not CI-wired): runs each fault option (--force-bad-hash, --skip-accounting-call, --inject-zero) asserting non-zero exit and the normal --demo run asserting exit 0 and the required report fields.
  • runBenchmarks now covers both run tasks; GradleTasks.md documents the estimator.

Design decisions for reviewer acknowledgment

  • Advisory only, no CI wiring — the research sets no product thresholds (single-VM, aarch64, synthetic); a blocking number would be invented. Wiring the verification into CI would be a scope change.
  • runBenchmarks now runs the estimator at its default op count (2M ops) in addition to the unwind benchmark — the task is slower; that is the documented behavior of "covers both".
  • The --inject-zero fault mode exits deterministically with a forced-failure reason rather than relying on a CI-condition that flake by construction.
  • Per-reviewer disclosure (sphinx, 3 rounds, 0 Critical/High): the 3 MEDIUMs and 16 LOWs are waived as design-consistent or follow-up hardening — marker-read subprocess cost per window, default-length run cost, test-adequacy mutations on the statistics, and robustness nits in the Linux-only support file (popen error handling, procfs short reads). Follow-ups welcome; none affect the estimate's correctness.

Testing

  • Smoke builds + fault modes verified locally (macOS clang++, markers NA).
  • Verified in containers on this candidate: glibc run self_test=pass (libc 2.35), full verifyNativeMemEstimator green (3 fault modes rc=1, normal rc=0, 119 report lines), musl run self_test=pass (musl 1.2.5, ia_ci_contains_magnitude=yes). Musl's CI is visibly wider than glibc's, as expected.
  • spotlessCheck + qualityChecks green; no production file touched (ddprof-lib/src/main/** unchanged; the unwind benchmark byte-identical).

@jbachorik jbachorik added the AI label Nov 10, 2026
@dd-octo-sts

dd-octo-sts Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervmccnms
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 21.1.8 (6ubuntu1)
Date:Mon Nov 16 17:00:43 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs2
Logic error
Dereference of null pointer1
Unused code
Dead initialization1

Filter Results by File

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Unused codeDead initializationreferenceChains.cppapplyOomRamp4971
Logic errorDereference of null pointerperfEvents_linux.cppunregisterThread72026

@dd-octo-sts

dd-octo-sts Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #43913408017 | Commit: afa6e07 | Duration: 20m 8s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ ✅ - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-11-16 17:22:39 UTC

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 41a45b7 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 41a45b7b

@dd-octo-sts

dd-octo-sts Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Reliability & Chaos Results

⚠️ 12 memory check row(s) inconclusive — no failures Pipeline: https://gitlab.ddbuild.io/DataDog/java-profiler/-/pipelines/152059350

⚠️ profiler gmalloc aarch64Xmemory
Median host CPU pressure 25.755 is above the provisional bound
⚠️ profiler gmalloc amd64Xmemory
Median host CPU pressure 12.685 is above the provisional bound
⚠️ profiler jemalloc aarch64Xmemory
Median host CPU pressure 38.66 is above the provisional bound
⚠️ profiler jemalloc amd64Xmemory
Median host CPU pressure 13.925 is above the provisional bound
⚠️ profiler tcmalloc aarch64Xmemory
Median host CPU pressure 25.445 is above the provisional bound
⚠️ profiler tcmalloc amd64Xmemory
Median host CPU pressure 17.74 is above the provisional bound
⚠️ profiler tracer gmalloc aarch64Xmemory
Median host CPU pressure 33.39 is above the provisional bound
⚠️ profiler tracer gmalloc amd64Xmemory
Median host CPU pressure 11.885 is above the provisional bound
⚠️ profiler tracer jemalloc aarch64Xmemory
Median host CPU pressure 38.66 is above the provisional bound
⚠️ profiler tracer jemalloc amd64Xmemory
Median host CPU pressure 15.15 is above the provisional bound
⚠️ profiler tracer tcmalloc aarch64Xmemory
Median host CPU pressure 33.495 is above the provisional bound
⚠️ profiler tracer tcmalloc amd64Xmemory
Median host CPU pressure 21.63 is above the provisional bound

@jbachorik

Copy link
Copy Markdown
Collaborator Author

@DataDog review

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

On musl, an executable path containing musl can make libc detection launch the estimator recursively and hang. The Gradle wiring also shares incompatible benchmark arguments and omits the local header from incremental-build inputs.

Open Bits AI session

🤖 Bits Code Review · Commit c185a4a

Comment thread ddprof-lib/benchmarks/build.gradle.kts Resolved
Comment thread ddprof-lib/benchmarks/build.gradle.kts Resolved
@jbachorik
jbachorik marked this pull request as ready for review November 13, 2026 13:59
@jbachorik
jbachorik requested a review from a team as a code owner November 13, 2026 13:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T14:03:22.633896Z 869e44e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Confidence is limited to source inspection: Linux execution, fault modes, and statistical self-tests were not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 869e44e

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 869e44e155

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The estimate remains advisory: neither its magnitude nor injected-magnitude CI containment becomes a failure threshold. Runtime self-tests and Gradle task execution remain unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 8238c26

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The estimator’s runtime measurements and statistical self-tests were not exercised; validation is limited to static analysis and C++ syntax checks.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 46d861c

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

The PR adds an advisory paired estimator for native allocation-accounting cost, outside blocking CI. This update addresses root-cgroup sampling and adds fault injections for both confidence-interval rejection branches. One P2 issue remains: the cgroup verification accepts incorrect zero counters because it lacks a lower bound. There were no earlier open findings. Runtime estimator and Gradle verification remain unexecuted.

Open Bits AI session

🤖 Bits Code Review · Commit 190493d

} else {
val markerThrottled = Regex("cpu_nr_throttled=(\\S+)").find(report)?.groupValues?.get(1)
val markerValue = markerThrottled?.toLongOrNull()
if (markerValue == null || markerValue > ownThrottled.toLong()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Add a lower bound to the cgroup counter cross-check

When the process’s cgroup already has a nonzero throttling counter, an incorrect marker of zero still passes this upper-bound-only comparison. The verification therefore misses the wrong-hierarchy sampling it is intended to detect whenever that hierarchy reports zero. Read the own-cgroup counter before and after the normal run and require marker values to fall within that interval, or verify with deterministic fixtures containing distinct root and child counters.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

A Linux-only benchmark executable replays a seeded alloc/free
trace with and without NativeMem bookkeeping in AB/BA pairs,
reporting the paired median delta with a bootstrap CI, a sign
test and an A-A noise floor; it links the real nativeMem.cpp and
never gates on the size of an estimate.
GradleTasks.md states that runBenchmarks covers the unwind
benchmark and the estimator, and describes the estimator's
advisory output fields and Linux-only gating.
A mapping path merely containing musl (the estimator binary in a musl
directory) ran the wrong binary and recursed into itself; the probe now
skips candidates until the loader's own filename matches
-Pargs stays with runBenchmark: the estimator rejects its options and
vice versa; and the two directly included headers become compile inputs
so a header edit no longer reuses a stale object

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

The estimator uses the production accounting implementation without changing it, and estimate magnitude remains advisory. Runtime calibration and Gradle task execution were not validated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 41a45b7

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant