Skip to content

debug: Link in the debug version of tcmalloc for debug builds.#5424

Merged
jmarantz merged 17 commits intoenvoyproxy:masterfrom
jmarantz:debug-malloc
Jan 8, 2019
Merged

debug: Link in the debug version of tcmalloc for debug builds.#5424
jmarantz merged 17 commits intoenvoyproxy:masterfrom
jmarantz:debug-malloc

Conversation

@jmarantz
Copy link
Contributor

@jmarantz jmarantz commented Dec 26, 2018

Description: Use the debug version of tcmalloc when compiling for debug when --define=tcmalloc=debug is passed to bazel.
Risk Level: low: with this when we debug we are using a different allocator
Testing: //test/...
Docs Changes: n/a
Release Notes: n/a
*Fixes #Issue: #5423

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

This seems like a good idea to me if we can get it passing CI

repository + "//bazel:opt_build": [] if test else ["-ggdb3"],
repository + "//bazel:fastbuild_build": [],
repository + "//bazel:dbg_build": ["-ggdb3"],
repository + "//bazel:dbg_build": ["-ggdb3", "-DDEBUG_TCMALLOC"],
Copy link
Member

Choose a reason for hiding this comment

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

why not fastbuild also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fastbuild sgtm.

Passing CI will be the next hurdle; for some reason the tsan build worked locally on my machine so I must not be using the same options as there are in CI. Will investigate.

@mattklein123 mattklein123 self-assigned this Dec 26, 2018
@jmarantz
Copy link
Contributor Author

I ran into trouble solving this due to my lack of understanding of bazel functions. Seeking stackoverflow help: https://stackoverflow.com/questions/53947289/bazel-select-help-configuring-tcmalloc-debug

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@ggreenway
Copy link
Member

I'm strongly in favor of this, if you can work out the bazel incantations.

@jmarantz
Copy link
Contributor Author

jmarantz commented Jan 2, 2019

I haven't gotten any traction on the stackoverflow question I linked above, but I'm hopeful @htuch will be able to offer some suggestions when he's back online.

I'm pretty sure I can get my alternate approach in #5450 working if I can't do this one, but this seems better as it depends directly on code (https://github.com/gperftools/gperftools/blob/master/src/debugallocation.cc) authored by https://en.wikipedia.org/wiki/Urs_H%C3%B6lzle himself :)

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz
Copy link
Contributor Author

jmarantz commented Jan 4, 2019

closing in favor of #5450 which I've been able to get to work.

@jmarantz jmarantz closed this Jan 4, 2019
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz jmarantz reopened this Jan 6, 2019
@jmarantz jmarantz changed the title RFC debug: Link in the debug version of tcmalloc for debug builds. debug: Link in the debug version of tcmalloc for debug builds. Jan 6, 2019
@jmarantz
Copy link
Contributor Author

jmarantz commented Jan 6, 2019

@ggreenway @PiotrSikora let's review this PR instead :)

Given that in #5450 I was forcing the user to explicitly configure memory debugging, we might as well use the memory debugging built into tcmalloc, which seems to work better with protobuf's inconsistent operator new/delete overrides.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
…ete.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@PiotrSikora
Copy link
Contributor

Note: since this is now guarded by --define debug_memory=enabled, there is no coverage for it on CI. Consider adding it to the bazel.compile_time_options target.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@PiotrSikora
Copy link
Contributor

Sigh, sorry... bazel.compile_time_options uses --define tcmalloc=disabled, so we can't add it there... Perhaps add it to bazel.ipv6_tests or bazel.tsan (though I'm not sure if it's going to survive use-after-free test)?

@PiotrSikora
Copy link
Contributor

...or wait, it doesn't (but perhaps it should???).

@jmarantz
Copy link
Contributor Author

jmarantz commented Jan 6, 2019

I think tcmalloc=disabled is well-covered by tsan, asan, & mac, so it's OK?

Signed-off-by: Joshua Marantz <jmarantz@google.com>
htuch
htuch previously requested changes Jan 7, 2019
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Looks good, a few minor comments.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
PiotrSikora
PiotrSikora previously approved these changes Jan 8, 2019
Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

LGTM, but you need to rebase.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
PiotrSikora
PiotrSikora previously approved these changes Jan 8, 2019
Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

This is really cool. Is there a reason we decided not to do this by default on dbg/fastbuild builds? It seems like this would be nice to have?

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

/wait

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz
Copy link
Contributor Author

jmarantz commented Jan 8, 2019

I added doc. I am in favor of using it in fastbuild and dbg compilation modes, but maybe we can just add the capability now and get some community buy-in before switching the default?

@PiotrSikora
Copy link
Contributor

@mattklein123 I've asked to make memory scribbling optional in #5450, since both memory overhead (2-4x) and runtime overhead (educated guess) are quite significant, and would render debug build almost unusable.

bazel/README.md Outdated
* ASSERT() can be configured to log failures and increment a stat counter in a release build with
`--define log_debug_assert_in_release=enabled`. The default behavior is to compile debug assertions out of
release builds so that the condition is not evaluated. This option has no effect in debug builds.
* tcmalloc can be disabled with `--define tcmalloc=disabled`
Copy link
Contributor

Choose a reason for hiding this comment

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

Disabling is in section above (though, I'd argue that we could merge both).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved tcmalloc=disabled to disabling section. Merging can be left for a different PR.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz
Copy link
Contributor Author

jmarantz commented Jan 8, 2019

@PiotrSikora I ran all the tests with 4 different configs (fastbuild vs debug, tcmalloc=debug vs default) on my workstation. By far the greatest overhead for running tests is compiling and I think especially linking them (30-60 minutes for debug builds). After that it takes about 1.5 to 2 minutes to run all 366 tests independent of mode. An example command-line is:

bazel test --cache_test_results=no --compilation_mode=dbg //test/... --define=tcmalloc=debug

The main concern I have with running tests only under tcmalloc=debug is that it is not the same as production. However we have bazel.release in CI so I think we're OK.

Obviously it doesn't make sense to load-test or perf-test with memory debugging.

@jmarantz jmarantz dismissed htuch’s stale review January 8, 2019 18:24

Per comment thread, the test works, shows what the system does, and we can always delete it if it causes trouble with sanitizers.

@jmarantz jmarantz merged commit 8e23032 into envoyproxy:master Jan 8, 2019
@jmarantz jmarantz deleted the debug-malloc branch January 8, 2019 19:10
fredlas pushed a commit to fredlas/envoy that referenced this pull request Mar 5, 2019
…proxy#5424)

* debug: Use the debug version of tcmalloc when compiling for debug when --define=tcmalloc=debug is passed to bazel.

Signed-off-by: Joshua Marantz <jmarantz@google.com>

Signed-off-by: Fred Douglas <fredlas@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants