Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSS Shrinker Attempt 2 #32507

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

RSS Shrinker Attempt 2 #32507

wants to merge 2 commits into from

Conversation

scottopell
Copy link
Contributor

@scottopell scottopell commented Dec 24, 2024

What does this PR do?

At the beginning of each sub-agent's execution, force all reclaimable memory to be returned to the OS.

Motivation

This builds on @L3n41c 's more tongue-in-cheek version ( #32312 )

The underlying idea here is simple, we explicitly ask Linux to reclaim as much memory as we can once. The process will inevitably page back in some amount of the memory, but this is a trade-off that is worth it to page out memory that was used at agent-init and never again.

Describe how you validated your changes

None yet, needs more validation

Possible Drawbacks / Trade-offs

Additional Notes

Ideally I could swap out the current pageOutFileBackedMemory with a version that utilizes some kernel functionality, however I can't figure out how to trigger memory reclamation for a single process, I found a patch proposing it, but it didn't seem to get any attention. echo N > /proc/[PID]/reclaim (see https://lwn.net/Articles/544319/)

Copy link

Go Package Import Differences

Baseline: 407d013
Comparison: 2cbd847

binaryosarchchange
agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
agentdarwinamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
agentdarwinarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
iot-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
iot-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
heroku-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
cluster-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
cluster-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
process-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
process-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
process-agentwindowsamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
process-agentdarwinamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
process-agentdarwinarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
heroku-process-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
security-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
security-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
system-probelinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
system-probelinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
trace-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
trace-agentlinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
trace-agentwindowsamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
trace-agentdarwinamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
trace-agentdarwinarm64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker
heroku-trace-agentlinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/cmd/internal/rssshrinker

@agent-platform-auto-pr
Copy link
Contributor

Uncompressed package size comparison

Comparison with ancestor 407d0133d110d9e8303511ffaabf829ec061aace

Diff per package
package diff status size ancestor threshold
datadog-agent-amd64-deb 0.03MB ⚠️ 1190.80MB 1190.77MB 140.00MB
datadog-agent-x86_64-rpm 0.03MB ⚠️ 1200.09MB 1200.06MB 140.00MB
datadog-agent-x86_64-suse 0.03MB ⚠️ 1200.09MB 1200.06MB 140.00MB
datadog-agent-arm64-deb 0.02MB ⚠️ 935.09MB 935.06MB 140.00MB
datadog-agent-aarch64-rpm 0.02MB ⚠️ 944.35MB 944.33MB 140.00MB
datadog-heroku-agent-amd64-deb 0.02MB ⚠️ 505.19MB 505.17MB 70.00MB
datadog-dogstatsd-amd64-deb 0.00MB 78.57MB 78.57MB 10.00MB
datadog-dogstatsd-x86_64-rpm 0.00MB 78.65MB 78.65MB 10.00MB
datadog-dogstatsd-x86_64-suse 0.00MB 78.65MB 78.65MB 10.00MB
datadog-dogstatsd-arm64-deb 0.00MB 55.77MB 55.77MB 10.00MB
datadog-iot-agent-amd64-deb 0.00MB 113.34MB 113.34MB 10.00MB
datadog-iot-agent-x86_64-rpm 0.00MB 113.41MB 113.41MB 10.00MB
datadog-iot-agent-x86_64-suse 0.00MB 113.41MB 113.41MB 10.00MB
datadog-iot-agent-arm64-deb 0.00MB 108.81MB 108.81MB 10.00MB
datadog-iot-agent-aarch64-rpm 0.00MB 108.88MB 108.88MB 10.00MB

Decision

⚠️ Warning

@agent-platform-auto-pr
Copy link
Contributor

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

inv aws.create-vm --pipeline-id=51778631 --os-family=ubuntu

Note: This applies to commit 2cbd847

Copy link

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 7f00feae-89a1-4986-8c9c-af56379c2588

Baseline: 407d013
Comparison: 2cbd847
Diff

Optimization Goals: ❌ Regression(s) detected

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_logs % cpu utilization +7.89 [+4.54, +11.23] 1 Logs
quality_gate_idle_all_features memory utilization -15.45 [-15.53, -15.36] 1 Logs bounds checks dashboard
file_tree memory utilization -17.11 [-17.23, -16.99] 1 Logs
quality_gate_idle memory utilization -17.57 [-17.60, -17.54] 1 Logs bounds checks dashboard

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_logs % cpu utilization +7.89 [+4.54, +11.23] 1 Logs
file_to_blackhole_0ms_latency_http1 egress throughput +0.10 [-0.82, +1.02] 1 Logs
file_to_blackhole_500ms_latency egress throughput +0.05 [-0.73, +0.83] 1 Logs
file_to_blackhole_300ms_latency egress throughput +0.02 [-0.62, +0.66] 1 Logs
file_to_blackhole_1000ms_latency_linear_load egress throughput +0.02 [-0.45, +0.49] 1 Logs
uds_dogstatsd_to_api ingress throughput +0.01 [-0.11, +0.13] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.01, +0.01] 1 Logs
file_to_blackhole_0ms_latency_http2 egress throughput -0.01 [-0.86, +0.84] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.05 [-0.92, +0.82] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.10 [-0.81, +0.60] 1 Logs
uds_dogstatsd_to_api_cpu % cpu utilization -0.48 [-1.15, +0.19] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.55 [-1.33, +0.23] 1 Logs
tcp_syslog_to_blackhole ingress throughput -1.65 [-1.72, -1.58] 1 Logs
quality_gate_idle_all_features memory utilization -15.45 [-15.53, -15.36] 1 Logs bounds checks dashboard
file_tree memory utilization -17.11 [-17.23, -16.99] 1 Logs
quality_gate_idle memory utilization -17.57 [-17.60, -17.54] 1 Logs bounds checks dashboard

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_0ms_latency_http1 lost_bytes 10/10
file_to_blackhole_0ms_latency_http1 memory_usage 10/10
file_to_blackhole_0ms_latency_http2 lost_bytes 10/10
file_to_blackhole_0ms_latency_http2 memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency_linear_load memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_300ms_latency lost_bytes 10/10
file_to_blackhole_300ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard
quality_gate_logs lost_bytes 10/10
quality_gate_logs memory_usage 10/10

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:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. 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.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_idle, 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_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.

"github.com/DataDog/datadog-agent/cmd/internal/runcmd"
"github.com/DataDog/datadog-agent/cmd/system-probe/command"
"github.com/DataDog/datadog-agent/cmd/system-probe/subcommands"
)

func main() {
rssshrinker.Setup()
Copy link
Contributor

@lebauce lebauce Dec 26, 2024

Choose a reason for hiding this comment

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

Do we agree that this is only to make the RSS metric look better than to actually reduce the actual memory used or the number of OOM kills ?

Copy link
Member

Choose a reason for hiding this comment

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

I think everyone agrees with that (although maybe this should be clearer on the PR description and in code comments), we're just releasing what's not used to the OS, but of course (and unfortunately !) it doesn't actually reduce used memory 😄

Comment on lines +27 to +32
//revive:disable:var-naming

// MADV_PAGEOUT Reclaim these pages.
const MADV_PAGEOUT = 21

//revive:enable:var-naming
Copy link
Member

Choose a reason for hiding this comment

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

🥜 nitpick: ‏I believe this should work similarly while being simpler and less error prone

Suggested change
//revive:disable:var-naming
// MADV_PAGEOUT Reclaim these pages.
const MADV_PAGEOUT = 21
//revive:enable:var-naming
// MADV_PAGEOUT Reclaim these pages.
//
//nolint:revive
const MADV_PAGEOUT = 21

Comment on lines +36 to +37
// Release the memory garbage collected by the Go runtime to Linux
debug.FreeOSMemory()
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏This is not Linux specific so we could have a version of rssshrinker just calling it for Windows/Darwin

Copy link
Member

Choose a reason for hiding this comment

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

🔨 warning: ‏this should be controlled by a config so that we can disable it when needed. It means we can't just do it at the beginning but have to wait for the config component though...

Copy link
Member

Choose a reason for hiding this comment

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

I think by default ASC will own this package, I'm wondering if ASC and SMP should co-own it, what do you think ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants