-
Notifications
You must be signed in to change notification settings - Fork 160
build: Added build support for jemalloc. #315
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
base: 29.x-knots
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Copyright (c) 2026-present The Bitcoin Knots developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or https://opensource.org/license/mit/. | ||
|
|
||
| #[=======================================================================[ | ||
| FindJemalloc | ||
| ----------- | ||
|
|
||
| Finds the jemalloc headers and library. | ||
|
|
||
| This is a wrapper around find_package()/pkg_check_modules() commands that: | ||
| - facilitates searching in various build environments | ||
| - prints a standard log message | ||
|
|
||
| #]=======================================================================] | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
|
|
||
| find_package(Jemalloc ${Jemalloc_FIND_VERSION} NO_MODULE QUIET) | ||
| if(Jemalloc_FOUND) | ||
| find_package_handle_standard_args(Jemalloc | ||
| REQUIRED_VARS Jemalloc_DIR | ||
| VERSION_VAR Jemalloc_VERSION | ||
| ) | ||
| if(TARGET jemalloc) | ||
| add_library(Jemalloc::Jemalloc ALIAS jemalloc) | ||
| elseif(TARGET jemalloc-static) | ||
| add_library(Jemalloc::Jemalloc ALIAS jemalloc-static) | ||
| endif() | ||
| mark_as_advanced(Jemalloc_DIR) | ||
| else() | ||
| find_package(PkgConfig REQUIRED) | ||
| if(Jemalloc_FIND_VERSION) | ||
| set(_jemalloc_pc_arg "jemalloc>=${Jemalloc_FIND_VERSION}") | ||
| else() | ||
| set(_jemalloc_pc_arg "jemalloc") | ||
| endif() | ||
| pkg_check_modules(PC_Jemalloc QUIET IMPORTED_TARGET ${_jemalloc_pc_arg}) | ||
| find_package_handle_standard_args(Jemalloc | ||
| REQUIRED_VARS PC_Jemalloc_FOUND | ||
| VERSION_VAR PC_Jemalloc_VERSION | ||
| ) | ||
| if(Jemalloc_FOUND) | ||
| add_library(Jemalloc::Jemalloc ALIAS PkgConfig::PC_Jemalloc) | ||
| endif() | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,6 +140,16 @@ For more information on ZMQ, see: [zmq.md](zmq.md) | |
|
|
||
| --- | ||
|
|
||
| #### jemalloc Dependencies | ||
|
|
||
| Support for jemalloc requires the following dependency: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question, not something I have verified: does linking libjemalloc actually override malloc on macOS? @Retropex reported a successful build/test on macOS, which confirms it compiles and links, but not necessarily that jemalloc is serving allocations at runtime. On macOS the two-level namespace + zone allocator generally means a plain link does not interpose malloc without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you are right, macOS still uses malloc: That's said, I don't know why
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know anything about MacOS. If you run this command (setting the MALLOC_CONF environmental variable): MALLOC_CONF="stats_print:true" bitcoind And then CTRL-C, do you get a lot of statistics dumped? No => jemalloc definitely not working There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it dump a lot of statistics! I have compiled again without jemalloc and it did not dump statistics this time. that's said
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, if it is reporting jemalloc statistics ... I would say it is using jemalloc. If you run the benchmark: Do you see a performance increase? If so, it is using jemalloc for sure.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ps. Those statistics it dumped prompted what will be my next pull request to replace the UniValue engine. I have a yyjson version in testing, and it is a lot faster. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look pretty similar, within error margin. With: Without:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Need someone to test on other platforms as well then.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Retropex , could I ask you to re-test this on MacOS? I think I have corrected a build issue. Note that I have also added a section on "Reproducing Benchmark Results". |
||
|
|
||
| ``` bash | ||
| brew install jemalloc | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| #### Test Suite Dependencies | ||
|
|
||
| There is an included test suite that is useful for testing code changes when developing. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.