Skip to content

Commit

Permalink
Remove tcmalloc from list of globally linked libraries.
Browse files Browse the repository at this point in the history
It will become a library loaded through LD_PRELOAD so we keep the search
for it but move tcmalloc_minimal to be found first if it exists.
Refs #10271
  • Loading branch information
martyngigg committed Sep 23, 2014
1 parent 0e7ad92 commit 076399a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 91 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/Build/CMake/FindTcmalloc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
# TCMALLOC_LIBRARIES libraries to link against
# TCMALLOC_FOUND If false, do not try to use TCMALLOC

find_path ( TCMALLOC_INCLUDE_DIR tcmalloc.h
find_path ( TCMALLOC_INCLUDE_DIR tcmalloc.h
PATHS /usr/include/google
)

find_library ( TCMALLOC_LIB NAMES tcmalloc tcmalloc_minimal )
find_library ( TCMALLOC_LIB NAMES tcmalloc_minimal tcmalloc )
set ( TCMALLOC_LIBRARIES ${TCMALLOC_LIB} )

# handle the QUIETLY and REQUIRED arguments and set TCMALLOC_FOUND to TRUE if
# handle the QUIETLY and REQUIRED arguments and set TCMALLOC_FOUND to TRUE if
# all listed variables are TRUE
include ( FindPackageHandleStandardArgs )
find_package_handle_standard_args( Tcmalloc DEFAULT_MSG TCMALLOC_LIBRARIES TCMALLOC_INCLUDE_DIR )
Expand Down
46 changes: 22 additions & 24 deletions Code/Mantid/Build/CMake/LinuxSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ endif ()
# tcmalloc stuff. Only used on linux for now.
###########################################################################

# Look for tcmalloc. Make it optional, for now at least, but on by default
set ( USE_TCMALLOC ON CACHE BOOL "Flag for replacing regular malloc with tcmalloc" )
# Look for tcmalloc. It will be used via LD_PRELOAD but USE_TCMALLOC=OFF will turn this off
set ( USE_TCMALLOC ON CACHE BOOL "If true, use LD_PRELOAD=libtcmalloc.so in startup scripts" )
# If not wanted, just carry on without it
if ( USE_TCMALLOC )
find_package ( Tcmalloc )
if ( TCMALLOC_FOUND )
set ( TCMALLOC_LIBRARY ${TCMALLOC_LIBRARIES} )
# Make a C++ define to use as flags in, e.g. MemoryManager.cpp
add_definitions ( -DUSE_TCMALLOC )
else ( TCMALLOC_FOUND )
# If not found, print a message telling the user to either get it or disable its use in the cache
message ( SEND_ERROR "TCMalloc not found: either install the google-perftools suite on your system or set the USE_TCMALLOC CMake cache variable to OFF" )
message ( SEND_ERROR "TCMalloc requested but not found: either install google-perftools or set the USE_TCMALLOC=OFF" )
endif ( TCMALLOC_FOUND )
else ( USE_TCMALLOC )
message ( STATUS "Not using TCMalloc" )
Expand All @@ -38,7 +36,7 @@ set ( PLUGINS_DIR plugins )
set ( PVPLUGINS_DIR pvplugins )
set ( PVPLUGINS_SUBDIR pvplugins ) # Need to tidy these things up!

include ( DetermineLinuxDistro )
include ( DetermineLinuxDistro )

if ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
set ( CMAKE_INSTALL_PREFIX /opt/Mantid CACHE PATH "Install path" FORCE )
Expand All @@ -57,8 +55,8 @@ file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/mantid.sh "#!/bin/sh\n"
# "echo $MANTIDPATH\n"
# "PV_PLUGIN_PATH=$scriptpath/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}\n"
"PATH=$PATH:$MANTIDPATH\n"
"PYTHONPATH=$MANTIDPATH:$PYTHONPATH\n"
"LD_PRELOAD=\n"
"PYTHONPATH=$MANTIDPATH:$PYTHONPATH\n"
"LD_PRELOAD=\n"
"export MANTIDPATH PV_PLUGIN_PATH PATH PYTHONPATH LD_PRELOAD\n"
)

Expand All @@ -67,7 +65,7 @@ file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/mantid.csh "#!/bin/csh\n"
"setenv PV_PLUGIN_PATH \"${CMAKE_INSTALL_PREFIX}/${PVPLUGINS_DIR}/${PVPLUGINS_DIR}\"\n"
"setenv PATH \"\${PATH}:\${MANTIDPATH}\"\n"
"setenv LD_PRELOAD \" \"\n"
"if ($?PYTHONPATH) then\n"
"if ($?PYTHONPATH) then\n"
" setenv PYTHONPATH \"\${MANTIDPATH}:\${PYTHONPATH}\"\n"
"else\n"
" setenv PYTHONPATH \"\${MANTIDPATH}\"\n"
Expand All @@ -80,38 +78,38 @@ file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh "#!/bin/sh\n"
" ln -s $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot $RPM_INSTALL_PREFIX0/${BIN_DIR}/mantidplot\n"
"fi\n"
)
if ( ENVVARS_ON_INSTALL )
file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh "\n"
if ( ENVVARS_ON_INSTALL )
file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh "\n"
"ln -s $RPM_INSTALL_PREFIX0/${ETC_DIR}/mantid.sh /etc/profile.d/mantid.sh\n"
"ln -s $RPM_INSTALL_PREFIX0/${ETC_DIR}/mantid.csh /etc/profile.d/mantid.csh\n"
)
)
endif()



# RHEL6 specific stuff (as we need to use software collections)
if ( "${UNIX_DIST}" MATCHES "RedHatEnterprise" )
file ( APPEND ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh "\n"
"if [ -f $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot ]; then\n"
file ( APPEND ${CMAKE_CURRENT_BINARY_DIR}/rpm_post_install.sh "\n"
"if [ -f $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot ]; then\n"
" mv $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot_exe\n"
" ln -s $RPM_INSTALL_PREFIX0/${BIN_DIR}/launch_mantidplot.sh $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot\n"
" ln -s $RPM_INSTALL_PREFIX0/${BIN_DIR}/launch_mantidplot.sh $RPM_INSTALL_PREFIX0/${BIN_DIR}/MantidPlot\n"
"fi\n"
)
)
if ( "${UNIX_CODENAME}" MATCHES "Santiago" ) # el6
file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh "#!/bin/sh\n"
"scl enable mantidlibs \"${CMAKE_INSTALL_PREFIX}/${BIN_DIR}/MantidPlot_exe $*\" \n"
)
"scl enable mantidlibs \"${CMAKE_INSTALL_PREFIX}/${BIN_DIR}/MantidPlot_exe $*\" \n"
)
else ()
file ( WRITE ${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh "#!/bin/sh\n"
"LD_LIBRARY_PATH=/usr/lib64/paraview:${LD_LIBRARY_PATH} ${CMAKE_INSTALL_PREFIX}/${BIN_DIR}/MantidPlot_exe $* \n"
)
endif()
"LD_LIBRARY_PATH=/usr/lib64/paraview:${LD_LIBRARY_PATH} ${CMAKE_INSTALL_PREFIX}/${BIN_DIR}/MantidPlot_exe $* \n"
)
endif()

install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/launch_mantidplot.sh
DESTINATION ${BIN_DIR}
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
WORLD_EXECUTE WORLD_READ
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
WORLD_EXECUTE WORLD_READ
)

endif()
Expand Down
28 changes: 14 additions & 14 deletions Code/Mantid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ include ( ParaViewSetup )
###########################################################################
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")

if ( NOT THIRD_PARTY )
set ( THIRD_PARTY "${PROJECT_SOURCE_DIR}/../Third_Party" )
endif ()
# Print out where we think we are looking for 3rd party stuff
message (STATUS "Setting THIRD_PARTY to be ${THIRD_PARTY}." )

# Check that the 3rd party directory exists.
if (NOT IS_DIRECTORY "${THIRD_PARTY}")
if ( NOT THIRD_PARTY )
set ( THIRD_PARTY "${PROJECT_SOURCE_DIR}/../Third_Party" )
endif ()
# Print out where we think we are looking for 3rd party stuff
message (STATUS "Setting THIRD_PARTY to be ${THIRD_PARTY}." )

# Check that the 3rd party directory exists.
if (NOT IS_DIRECTORY "${THIRD_PARTY}")
message ( WARNING "Specified THIRD_PARTY directory doesn't exist!" )
endif()
endif()

include ( WindowsSetup )
include ( WindowsSetup )

# Settings for generating the windows Nullsoft package via CPack
include ( WindowsNSIS )
# Settings for generating the windows Nullsoft package via CPack
include ( WindowsNSIS )

ENDIF()

Expand Down Expand Up @@ -249,8 +249,8 @@ if ( ENABLE_CPACK )
# parse list to string required for deb package
string ( REPLACE ";" "" CPACK_DEBIAN_PACKAGE_DEPENDS ${DEPENDS_LIST} )
endif()
# soft requirement of tcmalloc - if built with it, then require it
IF ( USE_TCMALLOC AND TCMALLOC_FOUND )
# soft requirement of tcmalloc if selected
IF ( USE_TCMALLOC )
message ( STATUS " Adding gperftools to the package requirements" )
set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES},gperftools-libs >= 2.0" )
set ( CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},${PERFTOOLS_DEB_PACKAGE}" )
Expand Down
36 changes: 2 additions & 34 deletions Code/Mantid/Framework/API/src/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "MantidKernel/Logger.h"
#include "MantidKernel/Memory.h"

#ifdef USE_TCMALLOC
#include "google/malloc_extension.h"
#endif

#include <ostream> //for endl

using std::size_t;
Expand All @@ -32,7 +28,7 @@ MemoryManagerImpl::MemoryManagerImpl() :
}

/** Private destructor
* Prevents client from calling 'delete' on the pointer handed
* Prevents client from calling 'delete' on the pointer handed
* out by Instance
*/
MemoryManagerImpl::~MemoryManagerImpl()
Expand All @@ -55,11 +51,6 @@ MemoryInfo MemoryManagerImpl::getMemoryInfo()
*/
void MemoryManagerImpl::releaseFreeMemory()
{

#ifdef USE_TCMALLOC
// Make TCMALLOC release memory to the system
MallocExtension::instance()->ReleaseFreeMemory();
#endif
}

/** Release any free memory back to the system,
Expand All @@ -77,18 +68,7 @@ void MemoryManagerImpl::releaseFreeMemory()
*/
void MemoryManagerImpl::releaseFreeMemoryIfAbove(double threshold)
{
UNUSED_ARG(threshold);
#ifdef USE_TCMALLOC
Kernel::MemoryStats mem;
mem.update();
double fraction_available = static_cast<double>(mem.availMem())
/ static_cast<double>(mem.totalMem());
if (fraction_available < (1.0 - threshold))
{
// Make TCMALLOC release memory to the system
MallocExtension::instance()->ReleaseFreeMemory();
}
#endif
UNUSED_ARG(threshold);
}


Expand All @@ -104,18 +84,6 @@ void MemoryManagerImpl::releaseFreeMemoryIfAccumulated(size_t adding, size_t thr
{
UNUSED_ARG(adding);
UNUSED_ARG(threshold);
#ifdef USE_TCMALLOC
accumulatorMutex.lock();

memoryCleared += adding;
if (memoryCleared > threshold)
{
releaseFreeMemory();
memoryCleared = 0;
}

accumulatorMutex.unlock();
#endif
}


Expand Down
16 changes: 8 additions & 8 deletions Code/Mantid/Framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ endif ()
if ( ${CMAKE_PROJECT_NAME} MATCHES "MantidFramework" AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set ( MPI_BUILD OFF CACHE BOOL "Enable MPI options" )
if ( MPI_BUILD )
include ( MPISetup )
include ( MPISetup )
endif ( MPI_BUILD )
endif ()

Expand All @@ -55,8 +55,8 @@ endif ()
###########################################################################

# Might just as well link everything to Boost & Poco (found in CommonSetup)
# TCMalloc & MPI_CXX variables will be empty if not using
set ( MANTIDLIBS ${Boost_LIBRARIES} ${POCO_LIBRARIES} ${TCMALLOC_LIBRARY} ${MPI_CXX_LIBRARIES} )
# MPI_CXX variables will be empty if not using
set ( MANTIDLIBS ${Boost_LIBRARIES} ${POCO_LIBRARIES} ${MPI_CXX_LIBRARIES} )

###########################################################################
# Now add the packages one-by-one, building up the dependencies as we go
Expand Down Expand Up @@ -100,7 +100,7 @@ add_subdirectory (CurveFitting)
add_subdirectory (Crystal)
add_subdirectory (ICat)
add_subdirectory (LiveData)
add_subdirectory (SINQ)
add_subdirectory (SINQ)

# If an MPI-enabled build, add in the MPI-specific algorithms package
if ( MPI_BUILD )
Expand All @@ -113,7 +113,7 @@ if ( OPENCL_BUILD )
add_subdirectory ( GPUAlgorithms )
endif ()

# Unit test helper packages
# Unit test helper packages
if ( CXXTEST_FOUND )
add_subdirectory ( UserAlgorithms )
# This needs to be here so that a Framework-only build will work.
Expand All @@ -131,14 +131,14 @@ add_subdirectory (ISISLiveData)
# Add a custom target to build all of the Framework
###########################################################################

set ( FRAMEWORK_LIBS Kernel Geometry API PythonKernelModule
set ( FRAMEWORK_LIBS Kernel Geometry API PythonKernelModule
PythonGeometryModule PythonAPIModule DataObjects
DataHandling Nexus Algorithms CurveFitting ICat
Crystal MDAlgorithms MDEvents WorkflowAlgorithms
LiveData ISISLiveData RemoteAlgorithms SINQ
)

add_custom_target( Framework DEPENDS ${FRAMEWORK_LIBS} )
add_custom_target( Framework DEPENDS ${FRAMEWORK_LIBS} )

###########################################################################
# Installation settings
Expand All @@ -148,7 +148,7 @@ add_custom_target( Framework DEPENDS ${FRAMEWORK_LIBS} )
###########################################################################

# Create instrument directory and make it writable so vtp files can go there
install ( DIRECTORY ../instrument/ DESTINATION ${INBUNDLE}instrument
install ( DIRECTORY ../instrument/ DESTINATION ${INBUNDLE}instrument
DIRECTORY_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
GROUP_READ GROUP_EXECUTE GROUP_WRITE
WORLD_READ WORLD_EXECUTE WORLD_WRITE
Expand Down
12 changes: 4 additions & 8 deletions Code/Mantid/Framework/Kernel/src/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include <iomanip>
#include <sstream>

#ifdef USE_TCMALLOC
#include "google/malloc_extension.h"
#endif

#ifdef __linux__
#include <unistd.h>
#include <fstream>
Expand Down Expand Up @@ -217,7 +213,7 @@ void MemoryStats::process_mem_system(size_t & sys_avail, size_t & sys_total)
if (avPages < 0) totPages = 0;
if (pageSize < 1) pageSize = 1;
//Commented out the next line as the value was being written by the one after
//sys_avail = avPages / 1024 * pageSize;
//sys_avail = avPages / 1024 * pageSize;
sys_avail = totPages / 1024 * pageSize;
}
// Can get the info on the memory that we've already obtained but aren't using right now
Expand Down Expand Up @@ -283,7 +279,7 @@ void MemoryOptions::initAllocatorOptions()
if( initialized ) return;
#ifdef __linux__
/* The line below tells malloc to use a different memory allocation system call (mmap) to the 'usual'
* one (sbrk) for requests above the threshold of the second argument (in bytes). The effect of this
* one (sbrk) for requests above the threshold of the second argument (in bytes). The effect of this
* is that, for the current threshold value of 8*4096, storage for workspaces having 4096 or greater
* bins per spectrum will be allocated using mmap.
* This should have the effect that memory is returned to the kernel as soon as a workspace is deleted,
Expand Down Expand Up @@ -357,7 +353,7 @@ void MemoryStats::update()
* Set the fields to ignore
* @param ignore :: An enumeration giving the fields to ignore
*/
void MemoryStats::ignoreFields(const MemoryStatsIgnore ignore)
void MemoryStats::ignoreFields(const MemoryStatsIgnore ignore)
{
this->ignore = ignore;
}
Expand Down Expand Up @@ -399,7 +395,7 @@ string MemoryStats::availMemStr() const
}

/**
* Returns the total memory of the system
* Returns the total memory of the system
* @returns An unsigned containing the total amount of memory on the system in kiB
*/
size_t MemoryStats::totalMem() const
Expand Down

0 comments on commit 076399a

Please sign in to comment.