Skip to content

Commit ab528e7

Browse files
authored
Merge pull request #20751 from mckellyln/jemalloc_ldpreload
HPCC-35485 Add jemalloc allocator config option for LD_PRELOAD Reviewed-by: Gavin Halliday <gavin.halliday@lexisnexisrisk.com> Merged-by: Gavin Halliday <gavin.halliday@lexisnexisrisk.com>
2 parents 405b9d7 + 28b5c2d commit ab528e7

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ mpStart=7101
3030
mpEnd=7500
3131
mpSoMaxConn=128
3232
mpTraceLevel=0
33+
34+
# enable jemalloc memory allocator in all HPCC components
35+
# which can help reduce process memory usage (and OOM kills) from system allocator fragmentation
36+
#useJemalloc=true
37+
3338
# enable SSL for dafilesrv remote file access (SSLNone/false | SSLOnly/true | SSLFirst | UnsecureFirst | UnsecureAndSSL)
3439
# Enabling requires setting the HPCCPassPhrase, HPCCCertFile, and HPCCPrivateKeyFile values
3540
#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+
fi
141+
if [[ "$usejem" == "" ]] ; then
142+
jemline=$(grep -i usejemalloc "${HPCC_CONFIG}" 2>/dev/null)
143+
if [[ "$jemline" != "" ]] ; then
144+
item1=$(echo $jemline 2>/dev/null | awk '{print $1}' | cut -c 1)
145+
if [[ "$item1" != '#' ]] ; then
146+
usejem=$(echo $jemline 2>/dev/null | awk -F= '{print $2}' 2>/dev/null)
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 *= *//'`

rtl/eclrtl/rtlrecord.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,12 @@ RtlRecord::~RtlRecord()
383383
{
384384
const RtlFieldInfo *thisField = *finger;
385385
if (thisField->flags & RFTMdynamic)
386-
delete thisField;
386+
{
387+
if (thisField->flags & RFTMinifblock)
388+
delete (RtlCondFieldStrInfo *)thisField;
389+
else
390+
delete thisField;
391+
}
387392
}
388393
delete [] fields;
389394
}

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)