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

add environment variable to avoid RTLD_DEEPBIND when loading modules #6063

Merged
merged 2 commits into from
Jul 2, 2024

Conversation

trws
Copy link
Member

@trws trws commented Jun 28, 2024

Add an environment variable to control whether we actually apply the RTLD_DEEPBIND flag when calling dlopen. More details in the commit message, but this makes it possible to run flux with an alternate allocator using LD_PRELOAD or certain other things that make heap tracing and certain other debugging and tracing tasks much easier.

Copy link
Contributor

@grondo grondo left a comment

Choose a reason for hiding this comment

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

This LGTM. I just wonder about the need for flux_deepbind() in the public API.

Also, I wonder if the result of getenv () could be cached so we don't check multiple times for an environment variable that will almost never be present (or that could just be premature optimization)

src/common/libflux/plugin.h Outdated Show resolved Hide resolved
src/common/libflux/plugin.c Outdated Show resolved Hide resolved
@trws trws force-pushed the dynamic-deepbind branch 3 times, most recently from bbfad5a to 1ae99f8 Compare July 1, 2024 18:48
Copy link
Contributor

@grondo grondo left a comment

Choose a reason for hiding this comment

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

LGTM! One nit inline, but otherwise seems good to me

src/common/libflux/plugin_private.h Outdated Show resolved Hide resolved
Copy link
Member

@garlick garlick left a comment

Choose a reason for hiding this comment

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

Couple of style nits but o/w LGTM too

@@ -34,6 +36,21 @@
#define UUID_STR_LEN 37 // defined in later libuuid headers
#endif

static int use_deepbind = 1;
static pthread_once_t deepbind_once = PTHREAD_ONCE_INIT;
static void init_use_deepbind () {
Copy link
Member

Choose a reason for hiding this comment

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

Style: void parameter, open brace on new line

}

int plugin_deepbind () {
pthread_once(&deepbind_once, init_use_deepbind);
Copy link
Member

Choose a reason for hiding this comment

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

Style: open brace for function on new line, space before open paren in pthread_once

Copy link
Member

@garlick garlick left a comment

Choose a reason for hiding this comment

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

@grondo - all your changes/fixes are great. I'll approve based on that and you can add yours once you feel like this is ready.

@trws
Copy link
Member Author

trws commented Jul 1, 2024

I think that's all addressed.

#ifndef FLUX_CORE_PLUGIN_PRIVATE_H
#define FLUX_CORE_PLUGIN_PRIVATE_H

int plugin_deepbind ();
Copy link
Member

Choose a reason for hiding this comment

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

style: add void param here too

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@grondo grondo changed the title Dynamic deepbind add environment variable to avoid RTLD_DEEPBIND when loading modules Jul 2, 2024
@garlick
Copy link
Member

garlick commented Jul 2, 2024

Restarted the inception builder which had failed. I could not discern why.

trws added 2 commits July 2, 2024 23:24
problem: I recently needed to get a heap trace of flux to track down why
fluxion was using so much memory, that's another sordid tale I'm afraid,
but every tool I tried reported freeing unallocated pointers.  There is
a bad interaction between recent versions of glibc, that removed the
allocator hooks, and the RTLD_DEEPBIND flag.  Essentially it's nearly
impossible to consistely replace the allocator interface in all the
libraries consistently, whether using LD_PRELOAD or anything else.
Thankfully just turning that off works, as long as we don't have symbol
conflicts.

solution: Replace use of FLUX_DEEPBIND with calls to `flux_deepbind ()`
which checks for an environment variable, `FLUX_LOAD_WITH_DEEPBIND`, and
if that variable is both set and contains 0 returns 0, otherwise it
returns FLUX_DEEPBIND.  This allows for easy flipping to load flux using
say jemalloc, tcmalloc or the interposer library for heaptrack without a
rebuild.
problem: spellcheck failed on the explanation of the deepbind
environment variable

solution: add appropriate tokens to dictionary
@mergify mergify bot merged commit 85d7dfc into flux-framework:master Jul 2, 2024
33 checks passed
Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.31%. Comparing base (4b2bc41) to head (8061990).
Report is 508 commits behind head on master.

Files with missing lines Patch % Lines
src/common/libflux/plugin.c 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6063      +/-   ##
==========================================
- Coverage   83.34%   83.31%   -0.03%     
==========================================
  Files         521      521              
  Lines       84389    84396       +7     
==========================================
- Hits        70330    70317      -13     
- Misses      14059    14079      +20     
Files with missing lines Coverage Δ
src/broker/module.c 77.91% <100.00%> (ø)
src/common/libflux/handle.c 85.21% <100.00%> (ø)
src/common/libflux/plugin.c 92.38% <75.00%> (-0.16%) ⬇️

... and 10 files with indirect coverage changes

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.

3 participants