-
Notifications
You must be signed in to change notification settings - Fork 901
[Merged by Bors] - Switch allocator to jemalloc #3697
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
69ecba7
Add jemalloc support
michaelsproul 41eac5d
Compatibility with macOS
michaelsproul 81441e9
Disable jemalloc on Windows
michaelsproul a082ba5
Remove check-consensus
michaelsproul 5005dc3
Fix lcli
michaelsproul f14b87b
Update docs
michaelsproul 6c42aef
Fixups
michaelsproul 93457d8
Fix cargo-udeps
michaelsproul ac205b7
Merge remote-tracking branch 'origin/unstable' into jemalloc
michaelsproul 974b335
Merge remote-tracking branch 'origin/unstable' into jemalloc
michaelsproul 7d1307f
Remove reference to pinned udeps version
michaelsproul 8feea86
Update module docs
michaelsproul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[env] | ||
# Set the number of arenas to 16 when using jemalloc. | ||
JEMALLOC_SYS_WITH_MALLOC_CONF = "abort_conf:true,narenas:16" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,21 @@ version = "0.1.0" | |
authors = ["Paul Hauner <[email protected]>"] | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
lighthouse_metrics = { path = "../lighthouse_metrics" } | ||
lazy_static = "1.4.0" | ||
libc = "0.2.79" | ||
parking_lot = "0.12.0" | ||
jemalloc-ctl = { version = "0.5.0", optional = true } | ||
|
||
# Jemalloc's background_threads feature requires Linux (pthreads). | ||
[target.'cfg(target_os = "linux")'.dependencies] | ||
jemallocator = { version = "0.5.0", optional = true, features = ["stats", "background_threads"] } | ||
|
||
[target.'cfg(not(target_os = "linux"))'.dependencies] | ||
jemallocator = { version = "0.5.0", optional = true, features = ["stats"] } | ||
|
||
[features] | ||
mallinfo2 = [] | ||
jemalloc = ["jemallocator", "jemalloc-ctl"] | ||
jemalloc-profiling = ["jemallocator/profiling"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//! Set the allocator to `jemalloc`. | ||
//! | ||
//! Due to `jemalloc` requiring configuration at compile time or immediately upon runtime | ||
//! initialisation it is configured via a Cargo config file in `.cargo/config.toml`. | ||
//! | ||
//! The `jemalloc` tuning can be overriden by: | ||
//! | ||
//! A) `JEMALLOC_SYS_WITH_MALLOC_CONF` at compile-time. | ||
//! B) `_RJEM_MALLOC_CONF` at runtime. | ||
use jemalloc_ctl::{arenas, epoch, stats, Error}; | ||
use lazy_static::lazy_static; | ||
use lighthouse_metrics::{set_gauge, try_create_int_gauge, IntGauge}; | ||
|
||
#[global_allocator] | ||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | ||
|
||
// Metrics for jemalloc. | ||
lazy_static! { | ||
pub static ref NUM_ARENAS: lighthouse_metrics::Result<IntGauge> = | ||
try_create_int_gauge("jemalloc_num_arenas", "The number of arenas in use"); | ||
pub static ref BYTES_ALLOCATED: lighthouse_metrics::Result<IntGauge> = | ||
try_create_int_gauge("jemalloc_bytes_allocated", "Equivalent to stats.allocated"); | ||
pub static ref BYTES_ACTIVE: lighthouse_metrics::Result<IntGauge> = | ||
try_create_int_gauge("jemalloc_bytes_active", "Equivalent to stats.active"); | ||
pub static ref BYTES_MAPPED: lighthouse_metrics::Result<IntGauge> = | ||
try_create_int_gauge("jemalloc_bytes_mapped", "Equivalent to stats.mapped"); | ||
pub static ref BYTES_METADATA: lighthouse_metrics::Result<IntGauge> = | ||
try_create_int_gauge("jemalloc_bytes_metadata", "Equivalent to stats.metadata"); | ||
pub static ref BYTES_RESIDENT: lighthouse_metrics::Result<IntGauge> = | ||
try_create_int_gauge("jemalloc_bytes_resident", "Equivalent to stats.resident"); | ||
pub static ref BYTES_RETAINED: lighthouse_metrics::Result<IntGauge> = | ||
try_create_int_gauge("jemalloc_bytes_retained", "Equivalent to stats.retained"); | ||
} | ||
|
||
pub fn scrape_jemalloc_metrics() { | ||
scrape_jemalloc_metrics_fallible().unwrap() | ||
} | ||
|
||
pub fn scrape_jemalloc_metrics_fallible() -> Result<(), Error> { | ||
// Advance the epoch so that the underlying statistics are updated. | ||
epoch::advance()?; | ||
|
||
set_gauge(&NUM_ARENAS, arenas::narenas::read()? as i64); | ||
set_gauge(&BYTES_ALLOCATED, stats::allocated::read()? as i64); | ||
set_gauge(&BYTES_ACTIVE, stats::active::read()? as i64); | ||
set_gauge(&BYTES_MAPPED, stats::mapped::read()? as i64); | ||
set_gauge(&BYTES_METADATA, stats::metadata::read()? as i64); | ||
set_gauge(&BYTES_RESIDENT, stats::resident::read()? as i64); | ||
set_gauge(&BYTES_RETAINED, stats::retained::read()? as i64); | ||
|
||
Ok(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.