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

new(cmake,ci): added support for using jemalloc allocator instead of glibc one #3406

Merged
merged 6 commits into from
Dec 10, 2024

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Nov 20, 2024

What type of PR is this?

/kind feature

Any specific area of the project related to this PR?

/area build
/area CI

What this PR does / why we need it:

We never really tried different allocators, but #2495 (comment) seems to suggest that jemalloc can help us prevent memory starving the system.

Also, jemalloc allows us to customize its behavior and profile the application via malloc.conf (https://github.com/jemalloc/jemalloc/wiki/Getting-Started).
For example:

sudo MALLOC_CONF="prof:true,lg_prof_interval:30,prof_accum:false,prof_prefix:jeprof.out,prof_final:true" falco

Also, the PR adds support for jemalloc stats to stats_writer and prometheus metrics, by enabling the new config key:
metrics.jemalloc_stats_enabled: true. Disabled by default.

Example output:

falco.jemalloc.active_mb=18.3 falco.jemalloc.allocated_mb=17.2 falco.jemalloc.mapped_mb=36.9 falco.jemalloc.metadata_mb=5.7 falco.jemalloc.resident_mb=30.5 falco.jemalloc.retained_mb=28.6

Or, for prometheus:

# HELP falcosecurity_falco_jemalloc_active_bytes https://falco.org/docs/metrics/
# TYPE falcosecurity_falco_jemalloc_active_bytes counter
falcosecurity_falco_jemalloc_active_bytes 21729280.000000
# HELP falcosecurity_falco_jemalloc_allocated_bytes https://falco.org/docs/metrics/
# TYPE falcosecurity_falco_jemalloc_allocated_bytes counter
falcosecurity_falco_jemalloc_allocated_bytes 19951680.000000
# HELP falcosecurity_falco_jemalloc_mapped_bytes https://falco.org/docs/metrics/
# TYPE falcosecurity_falco_jemalloc_mapped_bytes counter
falcosecurity_falco_jemalloc_mapped_bytes 52469760.000000
# HELP falcosecurity_falco_jemalloc_metadata_bytes https://falco.org/docs/metrics/
# TYPE falcosecurity_falco_jemalloc_metadata_bytes counter
falcosecurity_falco_jemalloc_metadata_bytes 8636272.000000
# HELP falcosecurity_falco_jemalloc_metadata_thp_bytes https://falco.org/docs/metrics/
# TYPE falcosecurity_falco_jemalloc_metadata_thp_bytes counter
falcosecurity_falco_jemalloc_metadata_thp_bytes 0.000000
# HELP falcosecurity_falco_jemalloc_resident_bytes https://falco.org/docs/metrics/
# TYPE falcosecurity_falco_jemalloc_resident_bytes counter
falcosecurity_falco_jemalloc_resident_bytes 33603584.000000
# HELP falcosecurity_falco_jemalloc_retained_bytes https://falco.org/docs/metrics/
# TYPE falcosecurity_falco_jemalloc_retained_bytes counter
falcosecurity_falco_jemalloc_retained_bytes 39280640.000000
# HELP falcosecurity_falco_jemalloc_zero_reallocs_bytes https://falco.org/docs/metrics/
# TYPE falcosecurity_falco_jemalloc_zero_reallocs_bytes counter
falcosecurity_falco_jemalloc_zero_reallocs_bytes 0.000000

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

The jemalloc allocator is enabled by default for published packages.

Does this PR introduce a user-facing change?:

new(cmake,ci): added support for using jemalloc allocator instead of glibc one and use it by default for release artifacts

@poiana
Copy link
Contributor

poiana commented Nov 20, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 20, 2024

/milestone 0.40.0

@poiana poiana added this to the 0.40.0 milestone Nov 20, 2024
@poiana poiana added the size/M label Nov 20, 2024
@poiana poiana added size/L and removed size/M labels Nov 20, 2024
@@ -37,6 +37,9 @@ limitations under the License.
#include "event_drops.h"
#include "falco_outputs.h"

// Falco only metric
#define METRICS_V2_JEMALLOC_STATS 1 << 31
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All other METRICS_V2_... defines live in libs; give this a big number to avoid conflicts.

…glibc one.

The jemalloc allocator is enabled by default for published packages.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
…theus metircs.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 21, 2024

CI Build / test-dev-packages / test-packages (pull_request) Failing after 2m

There must be some issues with sanitizer + jemalloc i think :/

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
@FedeDP
Copy link
Contributor Author

FedeDP commented Dec 6, 2024

/cc @sgaist

@poiana poiana requested a review from sgaist December 6, 2024 08:35
@@ -141,6 +142,10 @@ set(CMD_MAKE make)

include(ExternalProject)

if(USE_JEMALLOC)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing the comment about jemalloc and ASAN above, shouldn't there be a check done here that fails the configuration if both are enabled ? Otherwise we will likely have users that will get problematic builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, i'll just add a warning!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed!

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>

Co-authored-by: Samuel Gaist <samuel.gaist@idiap.ch>
CMakeLists.txt Outdated Show resolved Hide resolved
Co-authored-by: Samuel Gaist <samuel.gaist@idiap.ch>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
@poiana poiana added the lgtm label Dec 6, 2024
@poiana poiana merged commit fa862b5 into master Dec 10, 2024
35 checks passed
@poiana poiana deleted the new/use_jemalloc branch December 10, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants