Skip to content

Commit cee98f7

Browse files
committed
HPCC-35485 Add jemalloc allocator config option for LD_PRELOAD
Signed-off-by: M Kelly <mark.kelly@lexisnexisrisk.com>
1 parent d56c768 commit cee98f7

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,14 @@ if(PLATFORM OR CLIENTTOOLS OR REMBED)
552552
install(FILES ${HPCC_SOURCE_DIR}/${LICENSE_FILE} DESTINATION "." COMPONENT Runtime)
553553
endif()
554554

555+
# Install jemalloc library from vcpkg
556+
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND PLATFORM)
557+
file(GLOB JEMALLOC_LIBS "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libjemalloc.so*")
558+
if (JEMALLOC_LIBS)
559+
install(FILES ${JEMALLOC_LIBS} DESTINATION "lib")
560+
endif()
561+
endif()
562+
555563
add_subdirectory(devel)
556564

557565
#uninstall target

initfiles/etc/DIR_NAME/environment.conf.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ mpStart=7101
3030
mpEnd=7500
3131
mpSoMaxConn=128
3232
mpTraceLevel=0
33+
34+
useJemalloc=true
35+
3336
# enable SSL for dafilesrv remote file access (SSLNone/false | SSLOnly/true | SSLFirst | UnsecureFirst | UnsecureAndSSL)
3437
# Enabling requires setting the HPCCPassPhrase, HPCCCertFile, and HPCCPrivateKeyFile values
3538
#dfsUseSSL=SSLNone

initfiles/sbin/hpcc_setenv.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,36 @@ if [ -z "$MALLOC_ARENA_MAX" ]; then
130130
export MALLOC_ARENA_MAX=$num_arenas
131131
fi
132132

133+
# search env or conf file for useJemalloc=true/false setting and if true, add libjemalloc to LD_PRELOAD
134+
HPCC_XMLFILE=${HPCC_XMLFILE:-${CONFIG_DIR}/${ENV_XML_FILE}}
135+
136+
usejem=""
137+
jemline=$(sed -n '/\<envsettings/I,/\/envsettings/I{//!p;}' "${HPCC_XMLFILE}" 2>/dev/null | grep -i '<usejemalloc>')
138+
if [[ "$jemline" != "" ]] ; then
139+
usejem=$(echo "$jemline" | awk -F '[<>]' 'tolower($0)~/usejemalloc/{print $3}' 2>/dev/null)
140+
if [[ "$usejem" == "" ]] ; then
141+
jemline=$(grep -i usejemalloc "${HPCC_CONFIG}" 2>/dev/null)
142+
if [[ "$jemline" != "" ]] ; then
143+
item1=$(echo $jemline 2>/dev/null | awk '{print $1}' | cut -c 1)
144+
if [[ "$item1" != '#' ]] ; then
145+
usejem=$(echo $jemline 2>/dev/null | awk -F= '{print $2}' 2>/dev/null)
146+
fi
147+
fi
148+
fi
149+
fi
150+
151+
if [[ "$usejem" != "" ]] ; then
152+
usejem=$(echo "$usejem" | tr -d "[:blank:]" | tr "[:upper:]" "[:lower:]")
153+
fi
154+
155+
if [[ "$usejem" == "true" ]] ; then
156+
if [[ -s ${INSTALL_DIR}/lib/libjemalloc.so ]] ; then
157+
if [[ ! "${LD_PRELOAD}" =~ .*libjemalloc.* ]] ; then
158+
export LD_PRELOAD="${INSTALL_DIR}/lib/libjemalloc.so${LD_PRELOAD:+:${LD_PRELOAD}}"
159+
fi
160+
fi
161+
fi
162+
133163
PATH_PREFIX=`cat ${HPCC_CONFIG} | sed -n "/\[${SECTION}\]/,/\[/p" | grep "^path *= *" | sed -e 's/^path *= *//'`
134164

135165
export PID=`cat ${HPCC_CONFIG} | sed -n "/\[${SECTION}\]/,/\[/p" | grep "^pid *= *" | sed -e 's/^pid *= *//'`

vcpkg.json.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
"name": "libiconv",
105105
"platform": "osx"
106106
},
107+
{
108+
"name": "jemalloc",
109+
"platform": "linux"
110+
},
107111
{
108112
"name": "libmemcached",
109113
"platform": "@VCPKG_MEMCACHED@ & !windows & !osx"

0 commit comments

Comments
 (0)