Add delayed startup RSS shrinker#53081
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: b021bea | Docs | Datadog PR Page | Give us feedback! |
387d484 to
e356f85
Compare
Files inventory check summaryFile checks results against ancestor a77444b5: Results for datadog-agent_7.82.0~devel.git.532.4408c0f.pipeline.122421258-1_amd64.deb:No change detected |
Static quality checks✅ Please find below the results from static quality gates Successful checksInfo
|
Regression DetectorRegression Detector ResultsMetrics dashboard Baseline: fc18d0b Optimization Goals: ✅ Improvement(s) detected
|
| perf | experiment | goal | Δ mean % | Δ mean % CI | trials | links |
|---|---|---|---|---|---|---|
| ➖ | quality_gate_logs | % cpu utilization | +1.68 | [+0.69, +2.67] | 1 | Logs bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | memory utilization | -9.29 | [-9.55, -9.03] | 1 | Logs bounds checks dashboard |
| ✅ | quality_gate_security_mean_fs_load | memory utilization | -18.42 | [-18.61, -18.23] | 1 | Logs bounds checks dashboard |
| ✅ | quality_gate_security_idle | memory utilization | -18.74 | [-18.97, -18.51] | 1 | Logs bounds checks dashboard |
| ✅ | quality_gate_security_no_fs_load | memory utilization | -20.08 | [-20.35, -19.81] | 1 | Logs bounds checks dashboard |
| ✅ | quality_gate_idle | memory utilization | -21.35 | [-21.57, -21.14] | 1 | Logs bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | memory utilization | -29.93 | [-30.23, -29.63] | 1 | Logs bounds checks dashboard |
Bounds Checks: ✅ Passed
| perf | experiment | bounds_check_name | replicates_passed | observed_value | links |
|---|---|---|---|---|---|
| ✅ | quality_gate_idle | intake_connections | 10/10 | 3 ≤ 4 | bounds checks dashboard |
| ✅ | quality_gate_idle | memory_usage | 10/10 | 146.98MiB ≤ 154MiB | bounds checks dashboard |
| ✅ | quality_gate_idle | total_bytes_received | 10/10 | 579.86KiB ≤ 819.20KiB | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | intake_connections | 10/10 | 3 ≤ 4 | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | memory_usage | 10/10 | 484.54MiB ≤ 495MiB | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | total_bytes_received | 10/10 | 0.89MiB ≤ 1.25MiB | bounds checks dashboard |
| ✅ | quality_gate_logs | intake_connections | 10/10 | 3 ≤ 6 | bounds checks dashboard |
| ✅ | quality_gate_logs | memory_usage | 10/10 | 180.97MiB ≤ 195MiB | bounds checks dashboard |
| ✅ | quality_gate_logs | missed_bytes | 10/10 | 0B = 0B | bounds checks dashboard |
| ✅ | quality_gate_logs | total_bytes_received | 10/10 | 264.01MiB ≤ 292MiB | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | cpu_usage | 10/10 | 373.74 ≤ 2000 | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | intake_connections | 10/10 | 3 ≤ 6 | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | memory_usage | 10/10 | 394.17MiB ≤ 430MiB | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | missed_bytes | 10/10 | 0B = 0B | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | total_bytes_received | 10/10 | 0.86GiB ≤ 1.04GiB | bounds checks dashboard |
| ✅ | quality_gate_security_idle | cpu_usage | 10/10 | 38.50 ≤ 40 | bounds checks dashboard |
| ✅ | quality_gate_security_idle | memory_usage | 10/10 | 299.60MiB ≤ 330MiB | bounds checks dashboard |
| ✅ | quality_gate_security_mean_fs_load | cpu_usage | 10/10 | 62.13 ≤ 80 | bounds checks dashboard |
| ✅ | quality_gate_security_mean_fs_load | memory_usage | 10/10 | 274.84MiB ≤ 310MiB | bounds checks dashboard |
| ✅ | quality_gate_security_no_fs_load | cpu_usage | 10/10 | 24.29 ≤ 40 | bounds checks dashboard |
| ✅ | quality_gate_security_no_fs_load | memory_usage | 10/10 | 287.37MiB ≤ 320MiB | bounds checks dashboard |
Explanation
Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%
Performance changes are noted in the perf column of each table:
- ✅ = significantly better comparison variant performance
- ❌ = significantly worse comparison variant performance
- ➖ = no significant change in performance
A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".
For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:
-
Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.
-
Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.
-
Its configuration does not mark it "erratic".
Replicate Execution Details
We run multiple replicates for each experiment/variant. However, we allow replicates to be automatically retried if there are any failures, up to 8 times, at which point the replicate is marked dead and we are unable to run analysis for the entire experiment. We call each of these attempts at running replicates a replicate execution. This section lists all replicate executions that failed due to the target crashing or being oom killed.
Note: In the below tables we bucket failures by experiment, variant, and failure type. For each of these buckets we list out the replicate indexes that failed with an annotation signifying how many times said replicate failed with the given failure mode. In the below example the baseline variant of the experiment named experiment_with_failures had two replicates that failed by oom kills. Replicate 0, which failed 8 executions, and replicate 1 which failed 6 executions, all with the same failure mode.
| Experiment | Variant | Replicates | Failure | Logs | Debug Dashboard |
|---|---|---|---|---|---|
| experiment_with_failures | baseline | 0 (x8) 1 (x6) | Oom killed | Debug Dashboard |
The debug dashboard links will take you to a debugging dashboard specifically designed to investigate replicate execution failures.
❌ Retried Profiling Replicate Execution Failures (ddprof)
Note: Profiling replicas may still be executing. See the debug dashboard for up to date status.
| Experiment | Variant | Replicates | Failure | Debug Dashboard |
|---|---|---|---|---|
| quality_gate_idle_all_features | baseline | 10 | Oom killed | Debug Dashboard |
| quality_gate_idle_all_features | comparison | 10 | Oom killed | Debug Dashboard |
| quality_gate_security_mean_fs_load | comparison | 10 | Oom killed | Debug Dashboard |
CI Pass/Fail Decision
✅ Passed. All Quality Gates passed.
- quality_gate_security_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_idle, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
- quality_gate_security_no_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_no_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_mean_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_mean_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
There was a problem hiding this comment.
quasi, I usually delete these opening a PR for review, but I also think there is some value in recording the LLM prompt/task along with the code, so I've debated making a directory for these
| ) | ||
|
|
||
| // DefaultStartupDelay is the delay before the startup RSS shrinker runs. | ||
| const DefaultStartupDelay = 2*time.Minute + 30*time.Second |
There was a problem hiding this comment.
How did you chose this default delay ?
There was a problem hiding this comment.
fairly arbitrary, my goal was to hit a point in the agent startup where all ‘init’-ish things already happened, and still give plenty of good measurements within the 10min SMP run
### What does this PR do? This bumps the memory allotment the container is allowed for `quality_gate_idle`. ### Motivation Folks started seeing some oom kills of the Agent in regression detector reports. Ex: #52988 (comment) Ex: #53081 (comment) ### Describe how you validated your changes Regression Detector is going to run in CI and I expect to see no oom kills of the Agent during the `quality_gate_idle` experiment. ### Additional Notes The memory allotment is not the bounds value and isn't what we assert on. Co-authored-by: paul.reinlein <paul.reinlein@datadoghq.com>
|
after lots of back and forth with gpt-5.5 here's where I ended up What exactly did this latest experiment do?For the latest
unix.Fadvise(fd, offset, length, unix.FADV_WILLNEED)on the same file offset/range for every mapping we paged out. So it is not only executable mappings. It is the exact same read-only mapping set as the original high-memory-win/high-CPU version, but with Headline result
It restored the big memory win, but CPU and page-fault/reclaim behavior look almost identical to the original bad Three-way comparison:
|
| Mode | CPU delta | PSS delta | RSS delta |
|---|---|---|---|
old r-xp+r--p, no prefetch |
+80.1 mCPU / +124% |
-147.4 MiB / -32% |
-145.3 MiB / -30% |
skip executable, r--p only |
+5.2 mCPU / +8% |
-52.7 MiB / -11% |
-52.5 MiB / -11% |
r-xp+r--p + FADV_WILLNEED |
+83.1 mCPU / +125% |
-146.4 MiB / -31% |
-143.9 MiB / -30% |
So prefetch keeps the RSS/PSS win, but the sustained CPU problem remains.
Page fault / reclaim counters
This is the most important part.
workingset_refault_file
| Mode | Comparison - baseline |
|---|---|
| old no-prefetch | +14,140,316 |
| skip executable | +569,652 |
FADV_WILLNEED |
+14,301,898 |
pgmajfault
| Mode | Comparison - baseline |
|---|---|
| old no-prefetch | +1,555 |
| skip executable | +103 |
FADV_WILLNEED |
+1,553 |
pgscan_direct
| Mode | Comparison - baseline |
|---|---|
| old no-prefetch | +20,890,714 |
| skip executable | +994,158 |
FADV_WILLNEED |
+21,429,315 |
pgsteal_direct
| Mode | Comparison - baseline |
|---|---|
| old no-prefetch | +14,142,829 |
| skip executable | +554,354 |
FADV_WILLNEED |
+14,319,642 |
So FADV_WILLNEED did not meaningfully reduce the refault/reclaim storm.
Cgroup memory impact
You asked about cgroup impact. memory.current goes up in all variants, including the “successful” skip-exec one.
| Mode | cgroup.v2.memory.current comparison - baseline |
|---|---|
| old no-prefetch | +31.2 MiB / +6% |
| skip executable | +29.9 MiB / +5% |
FADV_WILLNEED |
+34.6 MiB / +6% |
So the RSS/PSS win does not translate into lower cgroup memory usage. In fact, cgroup current is modestly higher.
File cache-related stats:
| Mode | memory.stat.file comparison - baseline |
|---|---|
| old no-prefetch | +10.7 MiB |
| skip executable | +35.4 MiB |
FADV_WILLNEED |
+12.4 MiB |
The surprising bit: FADV_WILLNEED did not produce a dramatically larger file-cache footprint than old no-prefetch. It also did not fix refaults. That suggests the fadvise either:
- did not eagerly read enough to matter;
- got reclaimed again under cgroup pressure;
- or does not populate the specific page-table / workingset state needed to avoid later refault cost.
Interpretation
This experiment falsifies the optimistic hypothesis:
“If we page out
r-xp+r--pbut prefetch the backing file range, maybe we keep RSS low and avoid sustained CPU.”
Nope. At least with FADV_WILLNEED, we get:
big RSS/PSS win + big refault/reclaim CPU tax
almost exactly like the original.
The only version that actually changed the CPU/refault picture was:
skip executable mappings
Current best conclusion
Executable mappings are the key. Paging out r-xp causes the kernel to thrash on file-backed workingset refault/direct reclaim during normal idle activity. Trying to warm the file cache with FADV_WILLNEED does not prevent it.
So the best-supported implementation remains:
page out r--p only, skip r-xp
That gives:
- ~11–12% PSS/RSS reduction in idle_all_features
- no major CPU regression
- ~18–25x lower refault/reclaim counters than
r-xp+r--p
Recommendation
Revert the FADV_WILLNEED experiment and keep the skip-executable version.
If we want another experiment, the next useful one is not more prefetching. It would be decomposing:
FreeOSMemory()onlyr--ppageout only- both
But for the “can we safely reclaim executable mappings?” question, this latest data says: not with this approach.
e5781c9 to
c4d23c7
Compare
What does this PR do?
Adds a delayed, one-shot startup RSS shrinker for Linux Agent processes.
The shrinker runs 2m30s after process startup and performs a best-effort reclamation pass:
debug.FreeOSMemory()to return reclaimable Go heap pages to the OS.MADV_PAGEOUTover clean/read-only file-backed mappings to let Linux page out cold startup-touched code/data.malloc_trim(0)only whenDD_STARTUP_RSS_SHRINKER_MALLOC_TRIM=trueis set onlinux && cgobuilds.The scheduled shrinker can be disabled with:
This also extracts the existing duplicated trace-loader / installer-daemon memory release implementation into
cmd/internal/rssshrinker.Motivation
This is intentionally framed as an RSS presentation optimization, not a claim that PSS or cgroup memory pressure will necessarily improve.
Many users inspect Agent footprint through RSS-oriented tools like
topandps, even though PSS/cgroup measurements are better indicators of real memory pressure. After startup, the Agent has touched clean file-backed pages that may no longer be part of the active working set. A single delayed, best-effort reclamation pass gives Linux a chance to evict those pages so reported RSS better reflects the active working set.The pass is delayed and one-shot to keep the behavior simple and avoid periodic page-fault churn.
Describe how you validated your changes
Used the repo Go toolchain by putting Homebrew Go first in PATH:
Validated with:
dda inv test --targets=./cmd/internal/rssshrinker dda inv agent.build --build-exclude=systemd git diff --checkPush hooks were attempted without
--no-verify. They passedgo-mod-tidy,go-mod-replace, andgo-test, but the localgo-linterhook was blocked by a local tool version mismatch:After confirming the remaining failure was local tooling, the branch was pushed with
--no-verifyso CI/perf testing can run.Additional Notes
Automated performance testing should be used to compare RSS/PSS/cgroup memory and page-fault/latency behavior before deciding whether to enable, tune, or further expand this behavior.