Merge pull request #2350 from influxdata/crepererum/valgrind
feat: memory allocator selection and valgrind supportpull/24376/head
commit
95872ba7a6
|
@ -2,7 +2,9 @@
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
.idea/
|
.idea/
|
||||||
.env
|
.env
|
||||||
|
.gdb_history
|
||||||
*.tsm
|
*.tsm
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
**/.vscode
|
**/.vscode
|
||||||
query_tests/cases/**/*.out
|
query_tests/cases/**/*.out
|
||||||
|
valgrind-out.txt
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Valgrind
|
||||||
|
This document explains how to use [Valgrind] to perform certain debug tasks.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
Create a debug build that uses the system memory allocator (i.e. neither [heappy] nor [jemalloc]):
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ cargo build --no-default-features
|
||||||
|
```
|
||||||
|
|
||||||
|
## Memory Leaks
|
||||||
|
There is a script that does most of the config setting. Just start the server with:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ ./scripts/valgrind_leak ./target/debug/influxdb_iox run ...
|
||||||
|
```
|
||||||
|
|
||||||
|
You can kill the server w/ `CTRL-C` when you're ready. The [Valgrind] output will be written to `valgrind-out.txt`.
|
||||||
|
|
||||||
|
## Suppression Rules
|
||||||
|
[Valgrind] allows you to suppress certain outputs. This can be used to ignore known "issues" like that [lazycell] leaks.
|
||||||
|
For IOx we provide a file that is used by the scripts (under `scripts/valgrind.supp`). If you plan to write your own
|
||||||
|
rules, here are some useful links:
|
||||||
|
|
||||||
|
- <https://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles>
|
||||||
|
- <https://www.valgrind.org/docs/manual/manual-core.html#manual-core.suppress>
|
||||||
|
- <https://wiki.wxwidgets.org/Valgrind_Suppression_File_Howto>
|
||||||
|
|
||||||
|
You may also use the `--gen-suppressions=all` to auto-generate supppression rules:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ ./scripts/valgrind_leak --gen-suppressions=all ./target/debug/influxdb_iox run ...
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that Rust symbols like `influxdb_iox::main` are mangled in a way that [Valgrind] cannot parse them (e.g. to
|
||||||
|
`_ZN12influxdb_iox4main17h940b8bf02831a9d8E`). The easiest way is to replace `::` w/ `*` and prepand and append an
|
||||||
|
additional wildcard `*`, so `influxdb_iox::main` gets `*influxdb_iox*main*`.
|
||||||
|
|
||||||
|
[heappy]: https://github.com/mkmik/heappy
|
||||||
|
[jemalloc]: ttps://github.com/jemalloc/jemalloc
|
||||||
|
[lazycell]: https://crates.io/crates/lazycell
|
||||||
|
[Valgrind]: https://valgrind.org/
|
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
dlopen
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
fun:do_dlopen
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
lazystatic
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
fun:__static_ref_initialize
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
oncecell
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
fun:*once_cell*imp*initialize_inner*
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
init_logs_and_tracing
|
||||||
|
Memcheck:Leak
|
||||||
|
...
|
||||||
|
fun:*init_logs_and_tracing*
|
||||||
|
...
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -eu -o pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
|
||||||
|
exec valgrind \
|
||||||
|
--leak-check=full \
|
||||||
|
--log-file=valgrind-out.txt \
|
||||||
|
--num-callers=50 \
|
||||||
|
--show-leak-kinds=all \
|
||||||
|
--suppressions="$SCRIPT_DIR/valgrind.supp" \
|
||||||
|
--track-origins=yes \
|
||||||
|
--verbose \
|
||||||
|
$@
|
|
@ -130,18 +130,41 @@ fn make_server(
|
||||||
app_server
|
app_server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(not(feature = "heappy"), not(feature = "jemalloc_replacing_malloc")))]
|
||||||
|
fn build_malloc_conf() -> String {
|
||||||
|
"system".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "heappy", not(feature = "jemalloc_replacing_malloc")))]
|
||||||
|
fn build_malloc_conf() -> String {
|
||||||
|
"heappy".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(not(feature = "heappy"), feature = "jemalloc_replacing_malloc"))]
|
||||||
|
fn build_malloc_conf() -> String {
|
||||||
|
tikv_jemalloc_ctl::config::malloc_conf::mib()
|
||||||
|
.unwrap()
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "heappy", feature = "jemalloc_replacing_malloc"))]
|
||||||
|
fn build_malloc_conf() -> String {
|
||||||
|
compile_error!("must use exactly one memory allocator")
|
||||||
|
}
|
||||||
|
|
||||||
/// This is the entry point for the IOx server. `config` represents
|
/// This is the entry point for the IOx server. `config` represents
|
||||||
/// command line arguments, if any.
|
/// command line arguments, if any.
|
||||||
pub async fn main(config: Config) -> Result<()> {
|
pub async fn main(config: Config) -> Result<()> {
|
||||||
let git_hash = option_env!("GIT_HASH").unwrap_or("UNKNOWN");
|
let git_hash = option_env!("GIT_HASH").unwrap_or("UNKNOWN");
|
||||||
let num_cpus = num_cpus::get();
|
let num_cpus = num_cpus::get();
|
||||||
let build_malloc_conf = tikv_jemalloc_ctl::config::malloc_conf::mib()
|
let build_malloc_conf = build_malloc_conf();
|
||||||
.unwrap()
|
|
||||||
.read()
|
|
||||||
.unwrap();
|
|
||||||
info!(
|
info!(
|
||||||
git_hash,
|
git_hash,
|
||||||
num_cpus, build_malloc_conf, "InfluxDB IOx server starting"
|
num_cpus,
|
||||||
|
%build_malloc_conf,
|
||||||
|
"InfluxDB IOx server starting",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Install custom panic handler and forget about it.
|
// Install custom panic handler and forget about it.
|
||||||
|
|
|
@ -46,9 +46,6 @@ static VERSION_STRING: Lazy<String> = Lazy::new(|| {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
#[cfg(not(any(feature = "heappy", feature = "jemalloc_replacing_malloc")))]
|
|
||||||
compile_error!("you need to pick either heappy or jemalloc_replacing_malloc feature, cargo can't pick a default out of a mutually exclusive set");
|
|
||||||
|
|
||||||
#[cfg(all(feature = "heappy", feature = "jemalloc_replacing_malloc"))]
|
#[cfg(all(feature = "heappy", feature = "jemalloc_replacing_malloc"))]
|
||||||
compile_error!("heappy and jemalloc_replacing_malloc features are mutually exclusive");
|
compile_error!("heappy and jemalloc_replacing_malloc features are mutually exclusive");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue