-
Notifications
You must be signed in to change notification settings - Fork 311
HPCC-35485 Add jemalloc allocator config option for LD_PRELOAD #20751
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
HPCC-35485 Add jemalloc allocator config option for LD_PRELOAD #20751
Conversation
|
Jira Issue: https://hpccsystems.atlassian.net//browse/HPCC-35485 Jirabot Action Result: |
fa43fc3 to
da78658
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds support for the jemalloc memory allocator as a configurable option via LD_PRELOAD. The feature allows users to enable jemalloc through configuration settings (either in environment.xml or environment.conf), which can provide better memory allocation performance and lower fragmentation compared to the default glibc allocator. The implementation adds the jemalloc library dependency, installation logic, and runtime configuration parsing.
Key changes:
- Adds jemalloc as a vcpkg dependency for Linux platforms
- Implements configuration parsing in hpcc_setenv.in to detect useJemalloc setting and conditionally add libjemalloc.so to LD_PRELOAD
- Installs jemalloc library files during package build for Linux platforms
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| vcpkg.json.in | Adds jemalloc as a dependency for Linux platforms via vcpkg package manager |
| initfiles/sbin/hpcc_setenv.in | Implements logic to parse useJemalloc configuration from XML or conf files and prepend libjemalloc.so to LD_PRELOAD when enabled |
| CMakeLists.txt | Adds installation logic to copy jemalloc library files from vcpkg to the lib directory for Linux platform builds |
da78658 to
a97b1d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
initfiles/sbin/hpcc_setenv.in
Outdated
| HPCC_XMLFILE=${HPCC_XMLFILE:-${CONFIG_DIR}/${ENV_XML_FILE}} | ||
|
|
||
| usejem=$(sed -n '/\<envsettings/I,/\/envsettings/I{//!p;}' ${HPCC_XMLFILE} 2>/dev/null | awk -F '[<>]' 'tolower($0)~/usejemalloc/{print $3}' 2>/dev/null) | ||
| if [[ "$usejem" == "" ]] ; then | ||
| usejem=$(grep -i usejemalloc ${HPCC_CONFIG} 2> /dev/null | awk -F= '{print $2}' 2>/dev/null) |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sed command parsing the XML file uses case-insensitive matching and a broad pattern that could match unintended XML elements. If the XML structure contains nested or malformed tags, this could extract incorrect values. Consider validating the XML structure or using a proper XML parser. At minimum, document the expected XML structure for the useJemalloc setting in environment.xml.
| HPCC_XMLFILE=${HPCC_XMLFILE:-${CONFIG_DIR}/${ENV_XML_FILE}} | |
| usejem=$(sed -n '/\<envsettings/I,/\/envsettings/I{//!p;}' ${HPCC_XMLFILE} 2>/dev/null | awk -F '[<>]' 'tolower($0)~/usejemalloc/{print $3}' 2>/dev/null) | |
| if [[ "$usejem" == "" ]] ; then | |
| usejem=$(grep -i usejemalloc ${HPCC_CONFIG} 2> /dev/null | awk -F= '{print $2}' 2>/dev/null) | |
| # Expected XML structure in ${HPCC_XMLFILE}: | |
| # <EnvSettings> | |
| # <useJemalloc>true</useJemalloc> | |
| # </EnvSettings> | |
| HPCC_XMLFILE=${HPCC_XMLFILE:-${CONFIG_DIR}/${ENV_XML_FILE}} | |
| usejem="" | |
| if command -v xmlstarlet >/dev/null 2>&1 ; then | |
| # Prefer xmlstarlet for robust XML parsing | |
| usejem=$(xmlstarlet sel -t -v "string(//EnvSettings/useJemalloc)" -n "${HPCC_XMLFILE}" 2>/dev/null | tr 'A-Z' 'a-z') | |
| else | |
| # Fallback to legacy sed/awk parsing within the <EnvSettings> section | |
| usejem=$(sed -n '/\<envsettings/I,/\/envsettings/I{//!p;}' "${HPCC_XMLFILE}" 2>/dev/null | awk -F '[<>]' 'tolower($0)~/usejemalloc/{print tolower($3)}' 2>/dev/null) | |
| fi | |
| if [[ "$usejem" == "" ]] ; then | |
| usejem=$(grep -i usejemalloc "${HPCC_CONFIG}" 2> /dev/null | awk -F= '{print $2}' 2>/dev/null | tr 'A-Z' 'a-z') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its ok as is and don't want to add a dependency on an xml parsing utility.
cee98f7 to
b5cb841
Compare
|
Code seems ok to set LD_PRELOAD ... but some jobs are failing when libjemalloc is used, I will have to look at that more in depth. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| mpSoMaxConn=128 | ||
| mpTraceLevel=0 | ||
|
|
||
| useJemalloc=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is enabled now for testing the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented this out now that tests are passing and the correct initial setting for this is false.
|
If we build libjemalloc with option: --disable-cxx then everything works ok - which suggests there is a memory issue somewhere. Notes from jemalloc discuss this - … passing incorrect sizes to the sized deallocation functions is disallowed by the language spec ("undefined behavior", same as passing a wild pointer or a double-free). One partial "fix" (which will fix the allocator crashes, although still disallowed) is to give the base class a custom operator delete which calls the global, unsized, operator delete; another is to compile with option: -fno-sized-deallocation A way to kinda-sorta fake this is to configure jemalloc with --disable-cxx, which (as a quirk of the current libstdc++ implementation that will likely change fairly soon) will also turn off sized deallocation usage barring some fancy sdallocx-detection trickery in the library that I think is unlikely. Crash only with Jemalloc, ASan is clean · Issue #2353 · jemalloc/jemalloc Using valgrind or asan has so far not reported any issues. I will continue to try and find the memory issue(s) |
|
@mckellyln do you have a stack trace for a failure? |
|
K8s Regression Suite test failure is a false positive (and is getting fixed in 9.14.x soon by James McMullan) |
|
We could also build libjemalloc with --disable-cxx option for added safety, if desired. |
|
@jakesmith fyi |
110a22d to
ad5e250
Compare
ghalliday
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mckellyln looks good, please squash.
Also, is 9.14.x the correct target? Could the inclusion of the library in 9.14.x cause problems?
ad5e250 to
28b5c2d
Compare
|
Squashed. |
ab528e7
into
hpcc-systems:candidate-9.14.x
|
Jirabot Action Result: |
Type of change:
Checklist:
Smoketest:
Testing: